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