diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c39063e46..062ce0293 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -545,6 +545,7 @@ delete_current_avatar = Delete Current Avatar uploaded_avatar_not_a_image = The uploaded file is not an image. uploaded_avatar_is_too_big = The uploaded file has exceeded the maximum size. update_avatar_success = Your avatar has been updated. +update_user_avatar_success = The user's avatar has been updated. change_password = Update Password old_password = Current Password diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 8bafd1f19..93e59893e 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -401,3 +401,34 @@ func DeleteUser(ctx *context.Context) { "redirect": setting.AppSubURL + "/admin/users", }) } + +// AvatarPost response for change user's avatar request +func AvatarPost(ctx *context.Context) { + u := prepareUserInfo(ctx) + if ctx.Written() { + return + } + + form := web.GetForm(ctx).(*forms.AvatarForm) + if err := router_user_setting.UpdateAvatarSetting(ctx, form, u); err != nil { + ctx.Flash.Error(err.Error()) + } else { + ctx.Flash.Success(ctx.Tr("settings.update_user_avatar_success")) + } + + ctx.Redirect(setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10)) +} + +// DeleteAvatar render delete avatar page +func DeleteAvatar(ctx *context.Context) { + u := prepareUserInfo(ctx) + if ctx.Written() { + return + } + + if err := u.DeleteAvatar(); err != nil { + ctx.Flash.Error(err.Error()) + } + + ctx.Redirect(setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10)) +} diff --git a/routers/web/web.go b/routers/web/web.go index a20bf484b..132e649d4 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -408,6 +408,8 @@ func RegisterRoutes(m *web.Route) { m.Combo("/new").Get(admin.NewUser).Post(bindIgnErr(forms.AdminCreateUserForm{}), admin.NewUserPost) m.Combo("/{userid}").Get(admin.EditUser).Post(bindIgnErr(forms.AdminEditUserForm{}), admin.EditUserPost) m.Post("/{userid}/delete", admin.DeleteUser) + m.Post("/{userid}/avatar", bindIgnErr(forms.AvatarForm{}), admin.AvatarPost) + m.Post("/{userid}/avatar/delete", admin.DeleteAvatar) }) m.Group("/emails", func() { diff --git a/templates/admin/user/edit.tmpl b/templates/admin/user/edit.tmpl index fb0ccd22b..9475a0cce 100644 --- a/templates/admin/user/edit.tmpl +++ b/templates/admin/user/edit.tmpl @@ -155,6 +155,44 @@ + +

+ {{.i18n.Tr "settings.avatar"}} +

+
+
+ {{.CsrfTokenHtml}} + {{if not DisableGravatar}} +
+
+ + +
+
+
+ + +
+ {{end}} + +
+
+ + +
+
+ +
+ + +
+ +
+ + {{$.i18n.Tr "settings.delete_current_avatar"}} +
+
+