Extending test script
This commit is contained in:
parent
04d7a2cdec
commit
2e44d14370
2 changed files with 50 additions and 19 deletions
|
@ -106,17 +106,20 @@ func (gs *GState) IncrementButtonCount(c *fiber.Ctx) error {
|
|||
|
||||
// Login is a simple login handler that returns a JWT token
|
||||
func (gs *GState) Login(c *fiber.Ctx) error {
|
||||
// To test: curl --data "user=user&pass=pass" http://localhost:8080/api/login
|
||||
user := c.FormValue("user")
|
||||
pass := c.FormValue("pass")
|
||||
// The body type is identical to a NewUser
|
||||
u := new(types.NewUser)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
if !gs.Db.CheckUser(user, pass) {
|
||||
if !gs.Db.CheckUser(u.Username, u.Password) {
|
||||
println("User not found")
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
// Create the Claims
|
||||
claims := jwt.MapClaims{
|
||||
"name": user,
|
||||
"name": u.Username,
|
||||
"admin": false,
|
||||
"exp": time.Now().Add(time.Hour * 72).Unix(),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue