|
|
@@ -39,41 +39,52 @@ func Settings(ctx *middleware.Context) { |
|
|
|
ctx.HTML(200, SETTINGS_PROFILE) |
|
|
|
} |
|
|
|
|
|
|
|
func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("settings") |
|
|
|
ctx.Data["PageIsSettingsProfile"] = true |
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, SETTINGS_PROFILE) |
|
|
|
func handlerUsernameChange(ctx *middleware.Context, newName string) { |
|
|
|
if len(newName) == 0 { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// Check if user name has been changed. |
|
|
|
if ctx.User.LowerName != strings.ToLower(form.Name) { |
|
|
|
if err := models.ChangeUserName(ctx.User, form.Name); err != nil { |
|
|
|
if ctx.User.LowerName != strings.ToLower(newName) { |
|
|
|
if err := models.ChangeUserName(ctx.User, newName); err != nil { |
|
|
|
switch { |
|
|
|
case models.IsErrUserAlreadyExist(err): |
|
|
|
ctx.Flash.Error(ctx.Tr("form.name_been_taken")) |
|
|
|
ctx.Flash.Error(ctx.Tr("newName_been_taken")) |
|
|
|
ctx.Redirect(setting.AppSubUrl + "/user/settings") |
|
|
|
case models.IsErrEmailAlreadyUsed(err): |
|
|
|
ctx.Flash.Error(ctx.Tr("form.email_been_used")) |
|
|
|
ctx.Redirect(setting.AppSubUrl + "/user/settings") |
|
|
|
case models.IsErrNameReserved(err): |
|
|
|
ctx.Flash.Error(ctx.Tr("user.form.name_reserved")) |
|
|
|
ctx.Flash.Error(ctx.Tr("user.newName_reserved")) |
|
|
|
ctx.Redirect(setting.AppSubUrl + "/user/settings") |
|
|
|
case models.IsErrNamePatternNotAllowed(err): |
|
|
|
ctx.Flash.Error(ctx.Tr("user.form.name_pattern_not_allowed")) |
|
|
|
ctx.Flash.Error(ctx.Tr("user.newName_pattern_not_allowed")) |
|
|
|
ctx.Redirect(setting.AppSubUrl + "/user/settings") |
|
|
|
default: |
|
|
|
ctx.Handle(500, "ChangeUserName", err) |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
log.Trace("User name changed: %s -> %s", ctx.User.Name, form.Name) |
|
|
|
log.Trace("User name changed: %s -> %s", ctx.User.Name, newName) |
|
|
|
} |
|
|
|
// In case it's just a case change. |
|
|
|
ctx.User.Name = form.Name |
|
|
|
ctx.User.LowerName = strings.ToLower(form.Name) |
|
|
|
ctx.User.Name = newName |
|
|
|
ctx.User.LowerName = strings.ToLower(newName) |
|
|
|
} |
|
|
|
|
|
|
|
func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("settings") |
|
|
|
ctx.Data["PageIsSettingsProfile"] = true |
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
ctx.HTML(200, SETTINGS_PROFILE) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
handlerUsernameChange(ctx, form.Name) |
|
|
|
if ctx.Written() { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
ctx.User.FullName = form.FullName |
|
|
|
ctx.User.Email = form.Email |
|
|
|