forked from forgejo/forgejo
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
This commit is contained in:
parent
ea518681d9
commit
8d2c24f7f9
14 changed files with 157 additions and 11 deletions
|
@ -140,6 +140,7 @@ type User struct {
|
|||
|
||||
// Preferences
|
||||
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
|
||||
Theme string `xorm:"NOT NULL DEFAULT ''"`
|
||||
}
|
||||
|
||||
// BeforeUpdate is invoked from XORM before updating this object.
|
||||
|
@ -165,6 +166,13 @@ func (u *User) BeforeUpdate() {
|
|||
u.Description = base.TruncateString(u.Description, 255)
|
||||
}
|
||||
|
||||
// AfterLoad is invoked from XORM after filling all the fields of this object.
|
||||
func (u *User) AfterLoad() {
|
||||
if u.Theme == "" {
|
||||
u.Theme = setting.UI.DefaultTheme
|
||||
}
|
||||
}
|
||||
|
||||
// SetLastLogin set time to last login
|
||||
func (u *User) SetLastLogin() {
|
||||
u.LastLoginUnix = util.TimeStampNow()
|
||||
|
@ -176,6 +184,12 @@ func (u *User) UpdateDiffViewStyle(style string) error {
|
|||
return UpdateUserCols(u, "diff_view_style")
|
||||
}
|
||||
|
||||
// UpdateTheme updates a users' theme irrespective of the site wide theme
|
||||
func (u *User) UpdateTheme(themeName string) error {
|
||||
u.Theme = themeName
|
||||
return UpdateUserCols(u, "theme")
|
||||
}
|
||||
|
||||
// getEmail returns an noreply email, if the user has set to keep his
|
||||
// email address private, otherwise the primary email address.
|
||||
func (u *User) getEmail() string {
|
||||
|
@ -777,6 +791,7 @@ func CreateUser(u *User) (err error) {
|
|||
u.HashPassword(u.Passwd)
|
||||
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization
|
||||
u.MaxRepoCreation = -1
|
||||
u.Theme = setting.UI.DefaultTheme
|
||||
|
||||
if _, err = sess.Insert(u); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue