diff options
author | Sandro Santilli <strk@kbt.io> | 2016-08-07 19:27:38 +0200 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2016-08-07 10:27:38 -0700 |
commit | 90dd0657b564210746c9c494c8c5b07dd8eee91f (patch) | |
tree | 228f1f1a684e355ef77c6d6798027dac76ce1d73 /routers/user | |
parent | ec92565f234deb75ea8df0c30a8772c4cd72bc2d (diff) | |
download | gitea-90dd0657b564210746c9c494c8c5b07dd8eee91f.tar.gz gitea-90dd0657b564210746c9c494c8c5b07dd8eee91f.zip |
Add support for federated avatars (#3320)
* Add support for federated avatars
Fixes #3105
Removes avatar fetching duplication code
Adds an "Enable Federated Avatar" checkbox in user settings
(defaults to unchecked)
Moves avatar settings all in the same form, making
local and remote avatars mutually exclusive
Renames UploadAvatarForm to AvatarForm
as it's not anymore only for uploading
* Run gofmt on all modified files
* Move Avatar form in its own page
* Add go-libravatar dependency to vendor/ dir
Hopefully helps with accepting the contribution.
See also #3214
* Revert "Add go-libravatar dependency to vendor/ dir"
This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82.
* Make federated avatar setting a global configuration
Removes the per-user setting
* Move avatar handling back to base tool, disable federated avatar in offline mode
* Format, handle error
* Properly set fallback host
* Use unsupported github.com mirror for importing go-libravatar
* Remove comment showing life exists outside of github.com
... pity, but contribution would not be accepted otherwise
* Use Combo for Get and Post methods over /avatar
* FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR
* Fix persistance of federated avatar lookup checkbox at install time
* Federated Avatars -> Enable Federated Avatars
* Use len(string) == 0 instead of string == ""
* Move import line where it belong
See
https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md
Pity the import url is still the unofficial one, but oh well...
* Save a line (and waste much more expensive time)
* Remove redundant parens
* Remove an empty line
* Remove empty lines
* Reorder lines to make diff smaller
* Remove another newline
Unknwon review got me start a fight against newlines
* Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE
On re-reading the diff I figured what Unknwon meant here:
https://github.com/gogits/gogs/pull/3320/files#r73741106
* Remove newlines that weren't there before my intervention
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/setting.go | 27 |
1 files changed, 17 insertions, 10 deletions
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) { |