aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorqwerty287 <80460567+qwerty287@users.noreply.github.com>2021-10-27 17:40:08 +0200
committerGitHub <noreply@github.com>2021-10-27 23:40:08 +0800
commit01fc24c78c6108540a3267b41ac113fd8bde23e1 (patch)
tree5bd1117f2bba15d2465a75168017b09e1c2ef7b7 /routers
parent89beceeb9ace8b61223d55b389541bba19578b42 (diff)
downloadgitea-01fc24c78c6108540a3267b41ac113fd8bde23e1.tar.gz
gitea-01fc24c78c6108540a3267b41ac113fd8bde23e1.zip
Add appearance section in settings (#17433)
* Add appearance section in settings * Fix lint * Fix lint * Apply suggestions from code review Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/user/setting/account.go28
-rw-r--r--routers/web/user/setting/profile.go74
-rw-r--r--routers/web/web.go4
3 files changed, 70 insertions, 36 deletions
diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go
index 249793578a..47014dc814 100644
--- a/routers/web/user/setting/account.go
+++ b/routers/web/user/setting/account.go
@@ -257,34 +257,6 @@ func DeleteAccount(ctx *context.Context) {
}
}
-// UpdateUIThemePost is used to update users' specific theme
-func UpdateUIThemePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*forms.UpdateThemeForm)
- ctx.Data["Title"] = ctx.Tr("settings")
- ctx.Data["PageIsSettingsAccount"] = true
-
- if ctx.HasError() {
- ctx.Redirect(setting.AppSubURL + "/user/settings/account")
- return
- }
-
- if !form.IsThemeExists() {
- ctx.Flash.Error(ctx.Tr("settings.theme_update_error"))
- ctx.Redirect(setting.AppSubURL + "/user/settings/account")
- return
- }
-
- if err := ctx.User.UpdateTheme(form.Theme); err != nil {
- ctx.Flash.Error(ctx.Tr("settings.theme_update_error"))
- ctx.Redirect(setting.AppSubURL + "/user/settings/account")
- return
- }
-
- log.Trace("Update user theme: %s", ctx.User.Name)
- ctx.Flash.Success(ctx.Tr("settings.theme_update_success"))
- ctx.Redirect(setting.AppSubURL + "/user/settings/account")
-}
-
func loadAccountData(ctx *context.Context) {
emlist, err := models.GetEmailAddresses(ctx.User.ID)
if err != nil {
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go
index d75149b8fc..d181ae1720 100644
--- a/routers/web/user/setting/profile.go
+++ b/routers/web/user/setting/profile.go
@@ -32,6 +32,7 @@ import (
const (
tplSettingsProfile base.TplName = "user/settings/profile"
+ tplSettingsAppearance base.TplName = "user/settings/appearance"
tplSettingsOrganization base.TplName = "user/settings/organization"
tplSettingsRepositories base.TplName = "user/settings/repos"
)
@@ -115,14 +116,6 @@ func ProfilePost(ctx *context.Context) {
ctx.User.KeepEmailPrivate = form.KeepEmailPrivate
ctx.User.Website = form.Website
ctx.User.Location = form.Location
- if len(form.Language) != 0 {
- if !util.IsStringInSlice(form.Language, setting.Langs) {
- ctx.Flash.Error(ctx.Tr("settings.update_language_not_found", form.Language))
- ctx.Redirect(setting.AppSubURL + "/user/settings")
- return
- }
- ctx.User.Language = form.Language
- }
ctx.User.Description = form.Description
ctx.User.KeepActivityPrivate = form.KeepActivityPrivate
ctx.User.Visibility = form.Visibility
@@ -329,3 +322,68 @@ func Repos(ctx *context.Context) {
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplSettingsRepositories)
}
+
+// Appearance render user's appearance settings
+func Appearance(ctx *context.Context) {
+ ctx.Data["Title"] = ctx.Tr("settings")
+ ctx.Data["PageIsSettingsAppearance"] = true
+
+ ctx.HTML(http.StatusOK, tplSettingsAppearance)
+}
+
+// UpdateUIThemePost is used to update users' specific theme
+func UpdateUIThemePost(ctx *context.Context) {
+ form := web.GetForm(ctx).(*forms.UpdateThemeForm)
+ ctx.Data["Title"] = ctx.Tr("settings")
+ ctx.Data["PageIsSettingsAppearance"] = true
+
+ if ctx.HasError() {
+ ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
+ return
+ }
+
+ if !form.IsThemeExists() {
+ ctx.Flash.Error(ctx.Tr("settings.theme_update_error"))
+ ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
+ return
+ }
+
+ if err := ctx.User.UpdateTheme(form.Theme); err != nil {
+ ctx.Flash.Error(ctx.Tr("settings.theme_update_error"))
+ ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
+ return
+ }
+
+ log.Trace("Update user theme: %s", ctx.User.Name)
+ ctx.Flash.Success(ctx.Tr("settings.theme_update_success"))
+ ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
+}
+
+// UpdateUserLang update a user's language
+func UpdateUserLang(ctx *context.Context) {
+ form := web.GetForm(ctx).(*forms.UpdateLanguageForm)
+ ctx.Data["Title"] = ctx.Tr("settings")
+ ctx.Data["PageIsSettingsAppearance"] = true
+
+ if len(form.Language) != 0 {
+ if !util.IsStringInSlice(form.Language, setting.Langs) {
+ ctx.Flash.Error(ctx.Tr("settings.update_language_not_found", form.Language))
+ ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
+ return
+ }
+ ctx.User.Language = form.Language
+ }
+
+ if err := models.UpdateUserSetting(ctx.User); err != nil {
+ ctx.ServerError("UpdateUserSetting", err)
+ return
+ }
+
+ // Update the language to the one we just set
+ middleware.SetLocaleCookie(ctx.Resp, ctx.User.Language, 0)
+
+ log.Trace("User settings updated: %s", ctx.User.Name)
+ ctx.Flash.Success(i18n.Tr(ctx.User.Language, "settings.update_language_success"))
+ ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
+
+}
diff --git a/routers/web/web.go b/routers/web/web.go
index 88565d6d85..c0bb74da2e 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -317,6 +317,10 @@ func RegisterRoutes(m *web.Route) {
m.Post("/email", bindIgnErr(forms.AddEmailForm{}), userSetting.EmailPost)
m.Post("/email/delete", userSetting.DeleteEmail)
m.Post("/delete", userSetting.DeleteAccount)
+ })
+ m.Group("/appearance", func() {
+ m.Get("", userSetting.Appearance)
+ m.Post("/language", bindIgnErr(forms.UpdateLanguageForm{}), userSetting.UpdateUserLang)
m.Post("/theme", bindIgnErr(forms.UpdateThemeForm{}), userSetting.UpdateUIThemePost)
})
m.Group("/security", func() {