Merge branch 'dev' into frontend
This commit is contained in:
commit
c7fe5e8775
1 changed files with 5 additions and 0 deletions
|
@ -57,9 +57,11 @@ func (gs *GState) Login(c *fiber.Ctx) error {
|
|||
// The body type is identical to a NewUser
|
||||
u := new(types.NewUser)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
println("Error parsing body")
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
println("Username:", u.Username)
|
||||
if !gs.Db.CheckUser(u.Username, u.Password) {
|
||||
println("User not found")
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
|
@ -74,13 +76,16 @@ func (gs *GState) Login(c *fiber.Ctx) error {
|
|||
|
||||
// Create token
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
println("Token created for user:", u.Username)
|
||||
|
||||
// Generate encoded token and send it as response.
|
||||
t, err := token.SignedString([]byte("secret"))
|
||||
if err != nil {
|
||||
println("Error signing token")
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
println("Successfully signed token for user:", u.Username)
|
||||
return c.JSON(fiber.Map{"token": t})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue