@ -1233,12 +1233,11 @@ func SignUpPost(ctx *context.Context) {
// Activate render activate user page
// Activate render activate user page
func Activate ( ctx * context . Context ) {
func Activate ( ctx * context . Context ) {
code := ctx . Query ( "code" )
code := ctx . Query ( "code" )
password := ctx . Query ( "password" )
if len ( code ) == 0 {
if len ( code ) == 0 {
ctx . Data [ "IsActivatePage" ] = true
ctx . Data [ "IsActivatePage" ] = true
if ctx . User . IsActive {
if ctx . User == nil || ctx . User . IsActive {
ctx . Error( 404 )
ctx . NotFound( "invalid user" , nil )
return
return
}
}
// Resend confirmation email.
// Resend confirmation email.
@ -1270,6 +1269,34 @@ func Activate(ctx *context.Context) {
// if account is local account, verify password
// if account is local account, verify password
if user . LoginSource == 0 {
if user . LoginSource == 0 {
ctx . Data [ "Code" ] = code
ctx . Data [ "NeedsPassword" ] = true
ctx . HTML ( http . StatusOK , TplActivate )
return
}
handleAccountActivation ( ctx , user )
}
// ActivatePost handles account activation with password check
func ActivatePost ( ctx * context . Context ) {
code := ctx . Query ( "code" )
if len ( code ) == 0 {
ctx . Redirect ( setting . AppSubURL + "/user/activate" )
return
}
user := models . VerifyUserActiveCode ( code )
// if code is wrong
if user == nil {
ctx . Data [ "IsActivateFailed" ] = true
ctx . HTML ( http . StatusOK , TplActivate )
return
}
// if account is local account, verify password
if user . LoginSource == 0 {
password := ctx . Query ( "password" )
if len ( password ) == 0 {
if len ( password ) == 0 {
ctx . Data [ "Code" ] = code
ctx . Data [ "Code" ] = code
ctx . Data [ "NeedsPassword" ] = true
ctx . Data [ "NeedsPassword" ] = true
@ -1283,6 +1310,10 @@ func Activate(ctx *context.Context) {
}
}
}
}
handleAccountActivation ( ctx , user )
}
func handleAccountActivation ( ctx * context . Context , user * models . User ) {
user . IsActive = true
user . IsActive = true
var err error
var err error
if user . Rands , err = models . GetUserSalt ( ) ; err != nil {
if user . Rands , err = models . GetUserSalt ( ) ; err != nil {
@ -1291,7 +1322,7 @@ func Activate(ctx *context.Context) {
}
}
if err := models . UpdateUserCols ( user , "is_active" , "rands" ) ; err != nil {
if err := models . UpdateUserCols ( user , "is_active" , "rands" ) ; err != nil {
if models . IsErrUserNotExist ( err ) {
if models . IsErrUserNotExist ( err ) {
ctx . Error( 404 )
ctx . NotFound( "UpdateUserCols" , err )
} else {
} else {
ctx . ServerError ( "UpdateUser" , err )
ctx . ServerError ( "UpdateUser" , err )
}
}