Allow non-local users to change their username

release/v1.15
Charlotte Som 2021-12-23 23:07:28 +00:00
parent 6eaebda1b5
commit f851b5635c
2 changed files with 2 additions and 8 deletions

View File

@ -45,12 +45,6 @@ func Profile(ctx *context.Context) {
// HandleUsernameChange handle username changes from user settings and admin interface // HandleUsernameChange handle username changes from user settings and admin interface
func HandleUsernameChange(ctx *context.Context, user *models.User, newName string) error { func HandleUsernameChange(ctx *context.Context, user *models.User, newName string) error {
// Non-local users are not allowed to change their username.
if !user.IsLocal() {
ctx.Flash.Error(ctx.Tr("form.username_change_not_local_user"))
return fmt.Errorf(ctx.Tr("form.username_change_not_local_user"))
}
// Check if user name has been changed // Check if user name has been changed
if user.LowerName != strings.ToLower(newName) { if user.LowerName != strings.ToLower(newName) {
if err := models.ChangeUserName(user, newName); err != nil { if err := models.ChangeUserName(user, newName); err != nil {

View File

@ -15,8 +15,8 @@
<span class="text red hide" id="name-change-prompt"> {{.i18n.Tr "settings.change_username_prompt"}}</span> <span class="text red hide" id="name-change-prompt"> {{.i18n.Tr "settings.change_username_prompt"}}</span>
<span class="text red hide" id="name-change-redirect-prompt"> {{.i18n.Tr "settings.change_username_redirect_prompt"}}</span> <span class="text red hide" id="name-change-redirect-prompt"> {{.i18n.Tr "settings.change_username_redirect_prompt"}}</span>
</label> </label>
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}disabled{{end}}> <input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if .IsReverseProxy}}disabled{{end}}>
{{if or (not .SignedUser.IsLocal) .IsReverseProxy}} {{if .IsReverseProxy}}
<p class="help text blue">{{$.i18n.Tr "settings.password_username_disabled"}}</p> <p class="help text blue">{{$.i18n.Tr "settings.password_username_disabled"}}</p>
{{end}} {{end}}
</div> </div>