diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/admin.go | 1 | ||||
-rw-r--r-- | routers/install.go | 2 | ||||
-rw-r--r-- | routers/org/setting.go | 4 | ||||
-rw-r--r-- | routers/user/setting.go | 27 |
4 files changed, 22 insertions, 12 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index bc850b638e..b8eb6743d7 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -222,6 +222,7 @@ func Config(ctx *context.Context) { ctx.Data["SessionConfig"] = setting.SessionConfig ctx.Data["DisableGravatar"] = setting.DisableGravatar + ctx.Data["EnableFederatedAvatar"] = setting.EnableFederatedAvatar type logger struct { Mode, Config string diff --git a/routers/install.go b/routers/install.go index 0af1f446c0..8b96ff8254 100644 --- a/routers/install.go +++ b/routers/install.go @@ -169,6 +169,7 @@ func Install(ctx *context.Context) { // Server and other services settings form.OfflineMode = setting.OfflineMode form.DisableGravatar = setting.DisableGravatar + form.EnableFederatedAvatar = setting.EnableFederatedAvatar form.DisableRegistration = setting.Service.DisableRegistration form.EnableCaptcha = setting.Service.EnableCaptcha form.RequireSignInView = setting.Service.RequireSignInView @@ -329,6 +330,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { cfg.Section("server").Key("OFFLINE_MODE").SetValue(com.ToStr(form.OfflineMode)) cfg.Section("picture").Key("DISABLE_GRAVATAR").SetValue(com.ToStr(form.DisableGravatar)) + cfg.Section("picture").Key("ENABLE_FEDERATED_AVATAR").SetValue(com.ToStr(form.EnableFederatedAvatar)) cfg.Section("service").Key("DISABLE_REGISTRATION").SetValue(com.ToStr(form.DisableRegistration)) cfg.Section("service").Key("ENABLE_CAPTCHA").SetValue(com.ToStr(form.EnableCaptcha)) cfg.Section("service").Key("REQUIRE_SIGNIN_VIEW").SetValue(com.ToStr(form.RequireSignInView)) diff --git a/routers/org/setting.go b/routers/org/setting.go index 128fba36a8..14681e4c59 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -83,8 +83,8 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) { ctx.Redirect(ctx.Org.OrgLink + "/settings") } -func SettingsAvatar(ctx *context.Context, form auth.UploadAvatarForm) { - form.Enable = true +func SettingsAvatar(ctx *context.Context, form auth.AvatarForm) { + form.Source = auth.AVATAR_LOCAL if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil { ctx.Flash.Error(err.Error()) } else { diff --git a/routers/user/setting.go b/routers/user/setting.go index 7412ce34d1..c5441f3543 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -22,6 +22,7 @@ import ( const ( SETTINGS_PROFILE base.TplName = "user/settings/profile" + SETTINGS_AVATAR base.TplName = "user/settings/avatar" SETTINGS_PASSWORD base.TplName = "user/settings/password" SETTINGS_EMAILS base.TplName = "user/settings/email" SETTINGS_SSH_KEYS base.TplName = "user/settings/sshkeys" @@ -91,10 +92,6 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) { ctx.User.Email = form.Email ctx.User.Website = form.Website ctx.User.Location = form.Location - if len(form.Gravatar) > 0 { - ctx.User.Avatar = base.EncodeMD5(form.Gravatar) - ctx.User.AvatarEmail = form.Gravatar - } if err := models.UpdateUser(ctx.User); err != nil { ctx.Handle(500, "UpdateUser", err) return @@ -106,8 +103,12 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) { } // FIXME: limit size. -func UpdateAvatarSetting(ctx *context.Context, form auth.UploadAvatarForm, ctxUser *models.User) error { - ctxUser.UseCustomAvatar = form.Enable +func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *models.User) error { + ctxUser.UseCustomAvatar = form.Source == auth.AVATAR_LOCAL + if len(form.Gravatar) > 0 { + ctxUser.Avatar = base.EncodeMD5(form.Gravatar) + ctxUser.AvatarEmail = form.Gravatar + } if form.Avatar != nil { fr, err := form.Avatar.Open() @@ -129,7 +130,7 @@ func UpdateAvatarSetting(ctx *context.Context, form auth.UploadAvatarForm, ctxUs } else { // No avatar is uploaded but setting has been changed to enable, // generate a random one when needed. - if form.Enable && !com.IsFile(ctxUser.CustomAvatarPath()) { + if ctxUser.UseCustomAvatar && !com.IsFile(ctxUser.CustomAvatarPath()) { if err := ctxUser.GenerateRandomAvatar(); err != nil { log.Error(4, "GenerateRandomAvatar[%d]: %v", ctxUser.ID, err) } @@ -143,14 +144,20 @@ func UpdateAvatarSetting(ctx *context.Context, form auth.UploadAvatarForm, ctxUs return nil } -func SettingsAvatar(ctx *context.Context, form auth.UploadAvatarForm) { +func SettingsAvatar(ctx *context.Context) { + ctx.Data["Title"] = ctx.Tr("settings") + ctx.Data["PageIsSettingsAvatar"] = true + ctx.HTML(200, SETTINGS_AVATAR) +} + +func SettingsAvatarPost(ctx *context.Context, form auth.AvatarForm) { if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.update_avatar_success")) } - ctx.Redirect(setting.AppSubUrl + "/user/settings") + ctx.Redirect(setting.AppSubUrl + "/user/settings/avatar") } func SettingsDeleteAvatar(ctx *context.Context) { @@ -158,7 +165,7 @@ func SettingsDeleteAvatar(ctx *context.Context) { ctx.Flash.Error(err.Error()) } - ctx.Redirect(setting.AppSubUrl + "/user/settings") + ctx.Redirect(setting.AppSubUrl + "/user/settings/avatar") } func SettingsPassword(ctx *context.Context) { |