forked from kevadesu/forgejo
[GITEA] Allow changing the email address before activation
During registration, one may be required to give their email address, to
be verified and activated later. However, if one makes a mistake, a
typo, they may end up with an account that cannot be activated due to
having a wrong email address.
They can still log in, but not change the email address, thus, no way to
activate it without help from an administrator.
To remedy this issue, lets allow changing the email address for logged
in, but not activated users.
This fixes gitea#17785.
Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
(cherry picked from commit aaaece28e4
)
This commit is contained in:
parent
48f38280e8
commit
639dafabec
6 changed files with 187 additions and 26 deletions
|
@ -690,6 +690,36 @@ func Activate(ctx *context.Context) {
|
|||
func ActivatePost(ctx *context.Context) {
|
||||
code := ctx.FormString("code")
|
||||
if len(code) == 0 {
|
||||
email := ctx.FormString("email")
|
||||
if len(email) > 0 {
|
||||
ctx.Data["IsActivatePage"] = true
|
||||
if ctx.Doer == nil || ctx.Doer.IsActive {
|
||||
ctx.NotFound("invalid user", nil)
|
||||
return
|
||||
}
|
||||
// Change the primary email
|
||||
if setting.Service.RegisterEmailConfirm {
|
||||
if setting.CacheService.Enabled && ctx.Cache.IsExist("MailResendLimit_"+ctx.Doer.LowerName) {
|
||||
ctx.Data["ResendLimited"] = true
|
||||
} else {
|
||||
ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale)
|
||||
err := user_model.ReplaceInactivePrimaryEmail(ctx, ctx.Doer.Email, &user_model.EmailAddress{
|
||||
UID: ctx.Doer.ID,
|
||||
Email: email,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Data["IsActivatePage"] = false
|
||||
log.Error("Couldn't replace inactive primary email of user %d: %v", ctx.Doer.ID, err)
|
||||
ctx.RenderWithErr(ctx.Tr("auth.change_unconfirmed_email_error", err), TplActivate, nil)
|
||||
return
|
||||
}
|
||||
// Confirmation mail will be re-sent after the redirect to `/user/activate` below.
|
||||
}
|
||||
} else {
|
||||
ctx.Data["ServiceNotEnabled"] = true
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubURL + "/user/activate")
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue