diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-03 16:20:16 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-03 16:20:16 +0300 |
| commit | 3279b30b3de8e4e9aaa6558ceaa9048b5b9314bd (patch) | |
| tree | 413be21f0ec907a49a34c46eb991eff15a58fb02 /backend | |
| parent | feat: working on rankings, overall rank left (#51) (diff) | |
| download | lphub-3279b30b3de8e4e9aaa6558ceaa9048b5b9314bd.tar.gz lphub-3279b30b3de8e4e9aaa6558ceaa9048b5b9314bd.tar.bz2 lphub-3279b30b3de8e4e9aaa6558ceaa9048b5b9314bd.zip | |
feat: added logs for user update (#55)
Former-commit-id: b1cfb15cd595e93494b370dda6572e48a175d46e
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/handlers/login.go | 8 | ||||
| -rw-r--r-- | backend/handlers/logs.go | 15 | ||||
| -rw-r--r-- | backend/handlers/user.go | 7 |
3 files changed, 21 insertions, 9 deletions
diff --git a/backend/handlers/login.go b/backend/handlers/login.go index 5949fdd..85ffd63 100644 --- a/backend/handlers/login.go +++ b/backend/handlers/login.go | |||
| @@ -38,7 +38,7 @@ func Login(c *gin.Context) { | |||
| 38 | default: | 38 | default: |
| 39 | steamID, err := openID.ValidateAndGetId() | 39 | steamID, err := openID.ValidateAndGetId() |
| 40 | if err != nil { | 40 | if err != nil { |
| 41 | CreateLog(steamID, LogTypeLogin, LogDescriptionUserLoginFailValidate) | 41 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailValidate) |
| 42 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 42 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 43 | return | 43 | return |
| 44 | } | 44 | } |
| @@ -49,7 +49,7 @@ func Login(c *gin.Context) { | |||
| 49 | if checkSteamID == 0 { | 49 | if checkSteamID == 0 { |
| 50 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) | 50 | user, err := GetPlayerSummaries(steamID, os.Getenv("API_KEY")) |
| 51 | if err != nil { | 51 | if err != nil { |
| 52 | CreateLog(steamID, LogTypeLogin, LogDescriptionUserLoginFailSummary) | 52 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailSummary) |
| 53 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 53 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 54 | return | 54 | return |
| 55 | } | 55 | } |
| @@ -79,12 +79,12 @@ func Login(c *gin.Context) { | |||
| 79 | // Sign and get the complete encoded token as a string using the secret | 79 | // Sign and get the complete encoded token as a string using the secret |
| 80 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) | 80 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) |
| 81 | if err != nil { | 81 | if err != nil { |
| 82 | CreateLog(steamID, LogTypeLogin, LogDescriptionUserLoginFailToken) | 82 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginFailToken) |
| 83 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Failed to generate token.")) | 83 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Failed to generate token.")) |
| 84 | return | 84 | return |
| 85 | } | 85 | } |
| 86 | c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true) | 86 | c.SetCookie("token", tokenString, 3600*24*30, "/", "", true, true) |
| 87 | CreateLog(steamID, LogTypeLogin, LogDescriptionUserLoginSuccess) | 87 | CreateLog(steamID, LogTypeUser, LogDescriptionUserLoginSuccess) |
| 88 | c.Redirect(http.StatusTemporaryRedirect, "/") | 88 | c.Redirect(http.StatusTemporaryRedirect, "/") |
| 89 | // c.JSON(http.StatusOK, models.Response{ | 89 | // c.JSON(http.StatusOK, models.Response{ |
| 90 | // Success: true, | 90 | // Success: true, |
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index 8880607..2b8223a 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go | |||
| @@ -12,13 +12,18 @@ import ( | |||
| 12 | 12 | ||
| 13 | const ( | 13 | const ( |
| 14 | LogTypeMod string = "Mod" | 14 | LogTypeMod string = "Mod" |
| 15 | LogTypeLogin string = "User" | 15 | LogTypeUser string = "User" |
| 16 | LogTypeRecord string = "Record" | 16 | LogTypeRecord string = "Record" |
| 17 | 17 | ||
| 18 | LogDescriptionUserLoginSuccess string = "LoginSuccess" | 18 | LogDescriptionUserLoginSuccess string = "LoginSuccess" |
| 19 | LogDescriptionUserLoginFailToken string = "LoginTokenFail" | 19 | LogDescriptionUserLoginFailToken string = "LoginTokenFail" |
| 20 | LogDescriptionUserLoginFailValidate string = "LoginValidateFail" | 20 | LogDescriptionUserLoginFailValidate string = "LoginValidateFail" |
| 21 | LogDescriptionUserLoginFailSummary string = "LoginSummaryFail" | 21 | LogDescriptionUserLoginFailSummary string = "LoginSummaryFail" |
| 22 | LogDescriptionUserUpdateSuccess string = "UpdateSuccess" | ||
| 23 | LogDescriptionUserUpdateFail string = "UpdateFail" | ||
| 24 | LogDescriptionUserUpdateSummaryFail string = "UpdateSummaryFail" | ||
| 25 | LogDescriptionUserUpdateCountrySuccess string = "UpdateCountrySuccess" | ||
| 26 | LogDescriptionUserUpdateCountryFail string = "UpdateCountryFail" | ||
| 22 | 27 | ||
| 23 | LogDescriptionMapSummaryCreate string = "MapSummaryCreate" | 28 | LogDescriptionMapSummaryCreate string = "MapSummaryCreate" |
| 24 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" | 29 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" |
diff --git a/backend/handlers/user.go b/backend/handlers/user.go index e0f1dff..742a57c 100644 --- a/backend/handlers/user.go +++ b/backend/handlers/user.go | |||
| @@ -646,6 +646,7 @@ func UpdateUser(c *gin.Context) { | |||
| 646 | } | 646 | } |
| 647 | profile, err := GetPlayerSummaries(user.(models.User).SteamID, os.Getenv("API_KEY")) | 647 | profile, err := GetPlayerSummaries(user.(models.User).SteamID, os.Getenv("API_KEY")) |
| 648 | if err != nil { | 648 | if err != nil { |
| 649 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSummaryFail) | ||
| 649 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 650 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 650 | return | 651 | return |
| 651 | } | 652 | } |
| @@ -653,9 +654,11 @@ func UpdateUser(c *gin.Context) { | |||
| 653 | _, err = database.DB.Exec(`UPDATE users SET username = $1, avatar_link = $2, country_code = $3, updated_at = $4 | 654 | _, err = database.DB.Exec(`UPDATE users SET username = $1, avatar_link = $2, country_code = $3, updated_at = $4 |
| 654 | WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) | 655 | WHERE steam_id = $5`, profile.PersonaName, profile.AvatarFull, profile.LocCountryCode, time.Now().UTC(), user.(models.User).SteamID) |
| 655 | if err != nil { | 656 | if err != nil { |
| 657 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateFail) | ||
| 656 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 658 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 657 | return | 659 | return |
| 658 | } | 660 | } |
| 661 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateSuccess) | ||
| 659 | c.JSON(http.StatusOK, models.Response{ | 662 | c.JSON(http.StatusOK, models.Response{ |
| 660 | Success: true, | 663 | Success: true, |
| 661 | Message: "Successfully updated user.", | 664 | Message: "Successfully updated user.", |
| @@ -690,21 +693,25 @@ func UpdateCountryCode(c *gin.Context) { | |||
| 690 | } | 693 | } |
| 691 | code := c.Query("country_code") | 694 | code := c.Query("country_code") |
| 692 | if code == "" { | 695 | if code == "" { |
| 696 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) | ||
| 693 | c.JSON(http.StatusNotFound, models.ErrorResponse("Enter a valid country code.")) | 697 | c.JSON(http.StatusNotFound, models.ErrorResponse("Enter a valid country code.")) |
| 694 | return | 698 | return |
| 695 | } | 699 | } |
| 696 | var validCode string | 700 | var validCode string |
| 697 | err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1`, code).Scan(&validCode) | 701 | err := database.DB.QueryRow(`SELECT country_code FROM countries WHERE country_code = $1`, code).Scan(&validCode) |
| 698 | if err != nil { | 702 | if err != nil { |
| 703 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) | ||
| 699 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) | 704 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) |
| 700 | return | 705 | return |
| 701 | } | 706 | } |
| 702 | // Valid code, update profile | 707 | // Valid code, update profile |
| 703 | _, err = database.DB.Exec(`UPDATE users SET country_code = $1 WHERE steam_id = $2`, validCode, user.(models.User).SteamID) | 708 | _, err = database.DB.Exec(`UPDATE users SET country_code = $1 WHERE steam_id = $2`, validCode, user.(models.User).SteamID) |
| 704 | if err != nil { | 709 | if err != nil { |
| 710 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountryFail) | ||
| 705 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) | 711 | c.JSON(http.StatusNotFound, models.ErrorResponse(err.Error())) |
| 706 | return | 712 | return |
| 707 | } | 713 | } |
| 714 | CreateLog(user.(models.User).SteamID, LogTypeUser, LogDescriptionUserUpdateCountrySuccess) | ||
| 708 | c.JSON(http.StatusOK, models.Response{ | 715 | c.JSON(http.StatusOK, models.Response{ |
| 709 | Success: true, | 716 | Success: true, |
| 710 | Message: "Successfully updated country code.", | 717 | Message: "Successfully updated country code.", |