mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-12 19:01:50 +02:00
Style preference tab for user (#467)
This commit is contained in:
@ -5,13 +5,19 @@ import (
|
||||
"github.com/thomiceli/opengist/internal/web/context"
|
||||
)
|
||||
|
||||
func UserSettings(ctx *context.Context) error {
|
||||
func UserAccount(ctx *context.Context) error {
|
||||
user := ctx.User
|
||||
|
||||
keys, err := db.GetSSHKeysByUserID(user.ID)
|
||||
if err != nil {
|
||||
return ctx.ErrorRes(500, "Cannot get SSH keys", err)
|
||||
}
|
||||
ctx.SetData("email", user.Email)
|
||||
ctx.SetData("hasPassword", user.Password != "")
|
||||
ctx.SetData("disableForm", ctx.GetData("DisableLoginForm"))
|
||||
ctx.SetData("settingsHeaderPage", "account")
|
||||
ctx.SetData("htmlTitle", ctx.TrH("settings"))
|
||||
return ctx.Html("settings_account.html")
|
||||
}
|
||||
|
||||
func UserMFA(ctx *context.Context) error {
|
||||
user := ctx.User
|
||||
|
||||
passkeys, err := db.GetAllCredentialsForUser(user.ID)
|
||||
if err != nil {
|
||||
@ -23,12 +29,48 @@ func UserSettings(ctx *context.Context) error {
|
||||
return ctx.ErrorRes(500, "Cannot get MFA status", err)
|
||||
}
|
||||
|
||||
ctx.SetData("email", user.Email)
|
||||
ctx.SetData("sshKeys", keys)
|
||||
ctx.SetData("passkeys", passkeys)
|
||||
ctx.SetData("hasTotp", hasTotp)
|
||||
ctx.SetData("hasPassword", user.Password != "")
|
||||
ctx.SetData("disableForm", ctx.GetData("DisableLoginForm"))
|
||||
ctx.SetData("settingsHeaderPage", "mfa")
|
||||
ctx.SetData("htmlTitle", ctx.TrH("settings"))
|
||||
return ctx.Html("settings.html")
|
||||
return ctx.Html("settings_mfa.html")
|
||||
}
|
||||
|
||||
func UserSSHKeys(ctx *context.Context) error {
|
||||
user := ctx.User
|
||||
|
||||
keys, err := db.GetSSHKeysByUserID(user.ID)
|
||||
if err != nil {
|
||||
return ctx.ErrorRes(500, "Cannot get SSH keys", err)
|
||||
}
|
||||
|
||||
ctx.SetData("sshKeys", keys)
|
||||
ctx.SetData("settingsHeaderPage", "ssh")
|
||||
ctx.SetData("htmlTitle", ctx.TrH("settings"))
|
||||
return ctx.Html("settings_ssh.html")
|
||||
}
|
||||
|
||||
func UserStyle(ctx *context.Context) error {
|
||||
ctx.SetData("settingsHeaderPage", "style")
|
||||
ctx.SetData("htmlTitle", ctx.TrH("settings"))
|
||||
return ctx.Html("settings_style.html")
|
||||
}
|
||||
|
||||
func ProcessUserStyle(ctx *context.Context) error {
|
||||
styleDto := new(db.UserStyleDTO)
|
||||
if err := ctx.Bind(styleDto); err != nil {
|
||||
return ctx.ErrorRes(400, ctx.Tr("error.cannot-bind-data"), err)
|
||||
}
|
||||
|
||||
if err := ctx.Validate(styleDto); err != nil {
|
||||
return ctx.ErrorRes(400, "Invalid data", err)
|
||||
}
|
||||
user := ctx.User
|
||||
user.StylePreferences = styleDto.ToJson()
|
||||
if err := user.Update(); err != nil {
|
||||
return ctx.ErrorRes(500, "Cannot update user styles", err)
|
||||
}
|
||||
|
||||
ctx.AddFlash("Updated style", "success")
|
||||
return ctx.RedirectTo("/settings/style")
|
||||
}
|
||||
|
Reference in New Issue
Block a user