Change user handlers to set cookies on registration and log in
This commit is contained in:
parent
a7fb54eeb7
commit
b3362d4a66
|
@ -3,6 +3,7 @@ package handlers
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"git.qowevisa.me/Qowevisa/fin-check-api/consts"
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/tokens"
|
"git.qowevisa.me/Qowevisa/fin-check-api/tokens"
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
||||||
|
@ -47,9 +48,11 @@ func UserRegister(c *gin.Context) {
|
||||||
}
|
}
|
||||||
token1 = token
|
token1 = token
|
||||||
}
|
}
|
||||||
|
c.SetCookie(consts.COOKIE_SESSION, token1.Val, 3600, "/", "localhost", false, true)
|
||||||
acc := types.Account{
|
acc := types.Account{
|
||||||
ID: dbUser.ID,
|
ID: dbUser.ID,
|
||||||
Token: token1.Val,
|
Token: token1.Val,
|
||||||
|
Username: dbUser.Username,
|
||||||
}
|
}
|
||||||
c.JSON(200, acc)
|
c.JSON(200, acc)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +85,7 @@ func UserLogin(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if foundUser.ID == 0 {
|
if foundUser.ID == 0 {
|
||||||
c.JSON(500, types.ErrorResponse{Message: "Credentials are incorrect"})
|
c.JSON(400, types.ErrorResponse{Message: "Credentials are incorrect"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var token1 *tokens.Token
|
var token1 *tokens.Token
|
||||||
|
@ -97,9 +100,13 @@ func UserLogin(c *gin.Context) {
|
||||||
}
|
}
|
||||||
token1 = token
|
token1 = token
|
||||||
}
|
}
|
||||||
|
c.SetCookie(consts.COOKIE_SESSION, token1.Val, 3600, "/", "localhost", false, true)
|
||||||
acc := types.Account{
|
acc := types.Account{
|
||||||
ID: foundUser.ID,
|
ID: foundUser.ID,
|
||||||
Token: token1.Val,
|
Token: token1.Val,
|
||||||
|
Username: dbUser.Username,
|
||||||
}
|
}
|
||||||
c.JSON(200, acc)
|
c.JSON(200, acc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isSessionTokenForUserInvalid(userID uint) {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user