stato intermedio
This commit is contained in:
@@ -208,3 +208,63 @@ func (ac *AuthController) ResetPassword(c *fiber.Ctx) error {
|
||||
}
|
||||
return c.Redirect("/login")
|
||||
}
|
||||
|
||||
func (ac *AuthController) UpdateLanguage(c *fiber.Ctx) error {
|
||||
currentUser, ok := httpmw.CurrentUserFromContext(c)
|
||||
if !ok {
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
type langRequest struct {
|
||||
Lang string `json:"lang" form:"lang"`
|
||||
}
|
||||
|
||||
var req langRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
req.Lang = c.FormValue("lang")
|
||||
}
|
||||
|
||||
lang := services.NormalizeLanguage(req.Lang)
|
||||
if !services.IsSupportedLanguage(lang) {
|
||||
return c.Status(fiber.StatusBadRequest).SendString("invalid language")
|
||||
}
|
||||
|
||||
if err := ac.authService.UpdateUserLanguage(currentUser.ID, lang); err != nil {
|
||||
if errors.Is(err, services.ErrInvalidLanguage) {
|
||||
return c.Status(fiber.StatusBadRequest).SendString("invalid language")
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("cannot update language")
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
func (ac *AuthController) UpdateTheme(c *fiber.Ctx) error {
|
||||
currentUser, ok := httpmw.CurrentUserFromContext(c)
|
||||
if !ok {
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
type themeRequest struct {
|
||||
Theme string `json:"theme" form:"theme"`
|
||||
}
|
||||
|
||||
var req themeRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
req.Theme = c.FormValue("theme")
|
||||
}
|
||||
|
||||
theme := services.NormalizeTheme(req.Theme)
|
||||
if theme != "dark" && theme != "light" {
|
||||
return c.Status(fiber.StatusBadRequest).SendString("invalid theme")
|
||||
}
|
||||
|
||||
if err := ac.authService.UpdateUserTheme(currentUser.ID, theme); err != nil {
|
||||
if errors.Is(err, services.ErrInvalidTheme) {
|
||||
return c.Status(fiber.StatusBadRequest).SendString("invalid theme")
|
||||
}
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("cannot update theme")
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user