diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-06-30 14:25:40 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-06-30 14:25:40 +0300 |
| commit | 82722f374ce6c6e8a44bffa0a25fe4bf2138004d (patch) | |
| tree | fda4a0707db9af0fe82ced137957d78dc5f3ce50 | |
| parent | fix: remove middleware for unneeded routes (diff) | |
| download | lphub-82722f374ce6c6e8a44bffa0a25fe4bf2138004d.tar.gz lphub-82722f374ce6c6e8a44bffa0a25fe4bf2138004d.tar.bz2 lphub-82722f374ce6c6e8a44bffa0a25fe4bf2138004d.zip | |
feat: add moderator status into jwt token
Former-commit-id: 3034de650c9e5898a1915814ea12c4c7f4f627db
| -rw-r--r-- | backend/controllers/loginController.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index cfe086d..b30d26e 100644 --- a/backend/controllers/loginController.go +++ b/backend/controllers/loginController.go | |||
| @@ -59,10 +59,20 @@ func Login(c *gin.Context) { | |||
| 59 | database.DB.Exec(`INSERT INTO users (steam_id, user_name, avatar_link, country_code) | 59 | database.DB.Exec(`INSERT INTO users (steam_id, user_name, avatar_link, country_code) |
| 60 | VALUES ($1, $2, $3, $4)`, steamID, user.PersonaName, user.AvatarFull, user.LocCountryCode) | 60 | VALUES ($1, $2, $3, $4)`, steamID, user.PersonaName, user.AvatarFull, user.LocCountryCode) |
| 61 | } | 61 | } |
| 62 | moderator := false | ||
| 63 | rows, _ := database.DB.Query("SELECT title_name FROM titles WHERE user_id = $1", steamID) | ||
| 64 | for rows.Next() { | ||
| 65 | var title string | ||
| 66 | rows.Scan(&title) | ||
| 67 | if title == "Moderator" { | ||
| 68 | moderator = true | ||
| 69 | } | ||
| 70 | } | ||
| 62 | // Generate JWT token | 71 | // Generate JWT token |
| 63 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ | 72 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ |
| 64 | "sub": steamID, | 73 | "sub": steamID, |
| 65 | "exp": time.Now().Add(time.Hour * 24 * 30).Unix(), | 74 | "exp": time.Now().Add(time.Hour * 24 * 30).Unix(), |
| 75 | "mod": moderator, | ||
| 66 | }) | 76 | }) |
| 67 | // Sign and get the complete encoded token as a string using the secret | 77 | // Sign and get the complete encoded token as a string using the secret |
| 68 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) | 78 | tokenString, err := token.SignedString([]byte(os.Getenv("SECRET_KEY"))) |