Allow admins to change user avatars (#17661)
Adds the avatar change panel to the edit user page (bottom) and allows admins to change it this way Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
bbffcc3aec
commit
3be156f66a
4 changed files with 72 additions and 0 deletions
|
@ -545,6 +545,7 @@ delete_current_avatar = Delete Current Avatar
|
||||||
uploaded_avatar_not_a_image = The uploaded file is not an image.
|
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.
|
uploaded_avatar_is_too_big = The uploaded file has exceeded the maximum size.
|
||||||
update_avatar_success = Your avatar has been updated.
|
update_avatar_success = Your avatar has been updated.
|
||||||
|
update_user_avatar_success = The user's avatar has been updated.
|
||||||
|
|
||||||
change_password = Update Password
|
change_password = Update Password
|
||||||
old_password = Current Password
|
old_password = Current Password
|
||||||
|
|
|
@ -401,3 +401,34 @@ func DeleteUser(ctx *context.Context) {
|
||||||
"redirect": setting.AppSubURL + "/admin/users",
|
"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))
|
||||||
|
}
|
||||||
|
|
|
@ -408,6 +408,8 @@ func RegisterRoutes(m *web.Route) {
|
||||||
m.Combo("/new").Get(admin.NewUser).Post(bindIgnErr(forms.AdminCreateUserForm{}), admin.NewUserPost)
|
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.Combo("/{userid}").Get(admin.EditUser).Post(bindIgnErr(forms.AdminEditUserForm{}), admin.EditUserPost)
|
||||||
m.Post("/{userid}/delete", admin.DeleteUser)
|
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() {
|
m.Group("/emails", func() {
|
||||||
|
|
|
@ -155,6 +155,44 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h4 class="ui top attached header">
|
||||||
|
{{.i18n.Tr "settings.avatar"}}
|
||||||
|
</h4>
|
||||||
|
<div class="ui attached segment">
|
||||||
|
<form class="ui form" action="{{.Link}}/avatar" method="post" enctype="multipart/form-data">
|
||||||
|
{{.CsrfTokenHtml}}
|
||||||
|
{{if not DisableGravatar}}
|
||||||
|
<div class="inline field">
|
||||||
|
<div class="ui radio checkbox">
|
||||||
|
<input name="source" value="lookup" type="radio" {{if not .User.UseCustomAvatar}}checked{{end}}>
|
||||||
|
<label>{{.i18n.Tr "settings.lookup_avatar_by_mail"}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field {{if .Err_Gravatar}}error{{end}}">
|
||||||
|
<label for="gravatar">Avatar {{.i18n.Tr "email"}}</label>
|
||||||
|
<input id="gravatar" name="gravatar" value="{{.User.AvatarEmail}}" />
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
<div class="inline field">
|
||||||
|
<div class="ui radio checkbox">
|
||||||
|
<input name="source" value="local" type="radio" {{if .User.UseCustomAvatar}}checked{{end}}>
|
||||||
|
<label>{{.i18n.Tr "settings.enable_custom_avatar"}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inline field">
|
||||||
|
<label for="avatar">{{.i18n.Tr "settings.choose_new_avatar"}}</label>
|
||||||
|
<input name="avatar" type="file" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<button class="ui green button">{{$.i18n.Tr "settings.update_avatar"}}</button>
|
||||||
|
<a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.i18n.Tr "settings.delete_current_avatar"}}</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue