36 lines
818 B
Go
36 lines
818 B
Go
|
package handlers_auth
|
||
|
|
||
|
import (
|
||
|
"brunel/auth"
|
||
|
"brunel/helpers"
|
||
|
|
||
|
"github.com/gofiber/fiber/v2"
|
||
|
)
|
||
|
|
||
|
func UpdatePassword(c *fiber.Ctx) error {
|
||
|
|
||
|
username := c.FormValue("username")
|
||
|
password := c.FormValue("password")
|
||
|
passwordConfirm := c.FormValue("passwordConfirm")
|
||
|
|
||
|
user, err := helpers.DBInst.GetUser(username)
|
||
|
if err != nil {
|
||
|
return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||
|
}
|
||
|
|
||
|
if password != passwordConfirm {
|
||
|
return c.Status(fiber.StatusBadRequest).SendString("Passwords do not match")
|
||
|
}
|
||
|
|
||
|
pw := auth.NewPasswordHash(password)
|
||
|
|
||
|
user.PasswordHash = pw
|
||
|
|
||
|
err = helpers.DBInst.UpdateUser(user)
|
||
|
if err != nil {
|
||
|
return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||
|
}
|
||
|
|
||
|
return c.Status(fiber.StatusOK).SendString("Password updated")
|
||
|
}
|