aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLanre Adelowo <adelowomailbox@gmail.com>2019-01-09 18:22:57 +0100
committertechknowlogick <hello@techknowlogick.com>2019-01-09 12:22:57 -0500
commit8d2c24f7f9b9bce3a806e4748623bd3b2742025b (patch)
tree2010e6ffaf542d0828c496c31afa56f816c069d5 /routers
parentea518681d95c9ef8ae5ed71d6d8cd7cfb6994a50 (diff)
downloadgitea-8d2c24f7f9b9bce3a806e4748623bd3b2742025b.tar.gz
gitea-8d2c24f7f9b9bce3a806e4748623bd3b2742025b.zip
Allow for user specific themes (#5668)
* add migration and basic UI for changing a user's theme * update user themem * use right text on button * load theme based on users' selection * load theme based on users' selection in pwa too * update sample config * delete older theme loading * implement AfterLoad to set users' theme properly * set up default theme when creating a user. This uses the installation wide theme * use flash messages for error * set default theme when creating a user from the cli * fix @lunny review
Diffstat (limited to 'routers')
-rw-r--r--routers/routes/routes.go4
-rw-r--r--routers/user/setting/account.go28
2 files changed, 31 insertions, 1 deletions
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index b776d0c201..6011427321 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -42,7 +42,7 @@ import (
"github.com/go-macaron/toolbox"
"github.com/prometheus/client_golang/prometheus"
"github.com/tstranex/u2f"
- "gopkg.in/macaron.v1"
+ macaron "gopkg.in/macaron.v1"
)
// NewMacaron initializes Macaron instance.
@@ -243,6 +243,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/email", bindIgnErr(auth.AddEmailForm{}), userSetting.EmailPost)
m.Post("/email/delete", userSetting.DeleteEmail)
m.Post("/delete", userSetting.DeleteAccount)
+ m.Post("/theme", bindIgnErr(auth.UpdateThemeForm{}), userSetting.UpdateUIThemePost)
})
m.Group("/security", func() {
m.Get("", userSetting.Security)
@@ -292,6 +293,7 @@ func RegisterRoutes(m *macaron.Macaron) {
})
}, reqSignIn, func(ctx *context.Context) {
ctx.Data["PageIsUserSettings"] = true
+ ctx.Data["AllThemes"] = setting.UI.Themes
})
m.Group("/user", func() {
diff --git a/routers/user/setting/account.go b/routers/user/setting/account.go
index bcf602c5ed..ff8631bf5b 100644
--- a/routers/user/setting/account.go
+++ b/routers/user/setting/account.go
@@ -168,6 +168,34 @@ func DeleteAccount(ctx *context.Context) {
}
}
+// UpdateUIThemePost is used to update users' specific theme
+func UpdateUIThemePost(ctx *context.Context, form auth.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) {
emails, err := models.GetEmailAddresses(ctx.User.ID)
if err != nil {