|
|
@ -1203,6 +1203,8 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo |
|
|
|
// 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.IsActive { |
|
|
@ -1228,42 +1230,58 @@ func Activate(ctx *context.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Verify code.
|
|
|
|
user := models.VerifyUserActiveCode(code) |
|
|
|
if user := models.VerifyUserActiveCode(code); user != nil { |
|
|
|
// if code is wrong
|
|
|
|
user.IsActive = true |
|
|
|
if user == nil { |
|
|
|
var err error |
|
|
|
ctx.Data["IsActivateFailed"] = true |
|
|
|
if user.Rands, err = models.GetUserSalt(); err != nil { |
|
|
|
ctx.HTML(200, TplActivate) |
|
|
|
ctx.ServerError("UpdateUser", err) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if account is local account, verify password
|
|
|
|
|
|
|
|
if user.LoginSource == 0 { |
|
|
|
|
|
|
|
if len(password) == 0 { |
|
|
|
|
|
|
|
ctx.Data["Code"] = code |
|
|
|
|
|
|
|
ctx.Data["NeedsPassword"] = true |
|
|
|
|
|
|
|
ctx.HTML(200, TplActivate) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil { |
|
|
|
if !user.ValidatePassword(password) { |
|
|
|
if models.IsErrUserNotExist(err) { |
|
|
|
ctx.Data["IsActivateFailed"] = true |
|
|
|
ctx.Error(404) |
|
|
|
ctx.HTML(200, TplActivate) |
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateUser", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.Trace("User activated: %s", user.Name) |
|
|
|
user.IsActive = true |
|
|
|
|
|
|
|
var err error |
|
|
|
if err := ctx.Session.Set("uid", user.ID); err != nil { |
|
|
|
if user.Rands, err = models.GetUserSalt(); err != nil { |
|
|
|
log.Error(fmt.Sprintf("Error setting uid in session: %v", err)) |
|
|
|
ctx.ServerError("UpdateUser", err) |
|
|
|
} |
|
|
|
return |
|
|
|
if err := ctx.Session.Set("uname", user.Name); err != nil { |
|
|
|
} |
|
|
|
log.Error(fmt.Sprintf("Error setting uname in session: %v", err)) |
|
|
|
if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil { |
|
|
|
} |
|
|
|
if models.IsErrUserNotExist(err) { |
|
|
|
if err := ctx.Session.Release(); err != nil { |
|
|
|
ctx.Error(404) |
|
|
|
log.Error("Error storing session: %v", err) |
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.ServerError("UpdateUser", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("auth.account_activated")) |
|
|
|
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/") |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["IsActivateFailed"] = true |
|
|
|
log.Trace("User activated: %s", user.Name) |
|
|
|
ctx.HTML(200, TplActivate) |
|
|
|
|
|
|
|
|
|
|
|
if err := ctx.Session.Set("uid", user.ID); err != nil { |
|
|
|
|
|
|
|
log.Error(fmt.Sprintf("Error setting uid in session: %v", err)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := ctx.Session.Set("uname", user.Name); err != nil { |
|
|
|
|
|
|
|
log.Error(fmt.Sprintf("Error setting uname in session: %v", err)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := ctx.Session.Release(); err != nil { |
|
|
|
|
|
|
|
log.Error("Error storing session: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("auth.account_activated")) |
|
|
|
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ActivateEmail render the activate email page
|
|
|
|
// ActivateEmail render the activate email page
|
|
|
|