-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
UX treat register like sign in, even oauth #5033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,6 +533,37 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR | |
return setting.AppSubURL + "/" | ||
} | ||
|
||
func handleRegister(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) { | ||
// Auto-set admin for the only user. | ||
if models.CountUsers() == 1 { | ||
u.IsAdmin = true | ||
u.IsActive = true | ||
u.SetLastLogin() | ||
if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { | ||
ctx.ServerError("UpdateUser", err) | ||
return | ||
} | ||
} | ||
|
||
// Send confirmation email | ||
if setting.Service.RegisterEmailConfirm && u.ID > 1 { | ||
models.SendActivateAccountMail(ctx.Context, u) | ||
ctx.Data["IsSendRegisterMail"] = true | ||
ctx.Data["Email"] = u.Email | ||
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) | ||
ctx.HTML(200, TplActivate) | ||
|
||
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { | ||
log.Error("Set cache(MailResendLimit) fail: %v", err) | ||
} | ||
return | ||
} | ||
|
||
ctx.Flash.Success(ctx.Tr("auth.sign_up_successful")) | ||
// Complete the signin without logging in again | ||
handleSignInFull(ctx, u, remember, true) | ||
} | ||
|
||
// SignInOAuth handles the OAuth2 login buttons | ||
func SignInOAuth(ctx *context.Context) { | ||
provider := ctx.Params(":provider") | ||
|
@@ -885,14 +916,20 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au | |
ctx.ServerError("CreateUser", err) | ||
} | ||
|
||
// TODO LoginName should come from form.UserName... shouldn't it? | ||
u := &models.User{ | ||
Name: form.UserName, | ||
Email: form.Email, | ||
Passwd: form.Password, | ||
IsActive: !setting.Service.RegisterEmailConfirm, | ||
LoginType: models.LoginOAuth2, | ||
LoginSource: loginSource.ID, | ||
LoginName: gothUser.(goth.User).UserID, | ||
Name: form.UserName, | ||
Email: form.Email, | ||
Passwd: form.Password, | ||
IsActive: !setting.Service.RegisterEmailConfirm, | ||
} | ||
|
||
// This will link the account in such a way that it cannot be removed | ||
// TODO why is this different from normal linking? | ||
if setting.Service.AllowOnlyExternalRegistration { | ||
u.LoginType = models.LoginOAuth2 | ||
u.LoginSource = loginSource.ID | ||
u.LoginName = gothUser.(goth.User).UserID | ||
} | ||
|
||
if err := models.CreateUser(u); err != nil { | ||
|
@@ -916,32 +953,16 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au | |
} | ||
log.Trace("Account created: %s", u.Name) | ||
|
||
// Auto-set admin for the only user. | ||
if models.CountUsers() == 1 { | ||
u.IsAdmin = true | ||
u.IsActive = true | ||
u.SetLastLogin() | ||
if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { | ||
ctx.ServerError("UpdateUser", err) | ||
// This will link the account in such a way that it can be removed | ||
if !setting.Service.AllowOnlyExternalRegistration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
err = models.LinkAccountToUser(u, gothUser.(goth.User)) | ||
if err != nil { | ||
ctx.ServerError("UserLinkAccount", err) | ||
return | ||
} | ||
} | ||
|
||
// Send confirmation email | ||
if setting.Service.RegisterEmailConfirm && u.ID > 1 { | ||
models.SendActivateAccountMail(ctx.Context, u) | ||
ctx.Data["IsSendRegisterMail"] = true | ||
ctx.Data["Email"] = u.Email | ||
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) | ||
ctx.HTML(200, TplActivate) | ||
|
||
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { | ||
log.Error("Set cache(MailResendLimit) fail: %v", err) | ||
} | ||
return | ||
} | ||
|
||
ctx.Redirect(setting.AppSubURL + "/user/login") | ||
handleRegister(ctx, u, form.Remember, true) | ||
} | ||
|
||
func handleSignOut(ctx *context.Context) { | ||
|
@@ -1058,33 +1079,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo | |
} | ||
log.Trace("Account created: %s", u.Name) | ||
|
||
// Auto-set admin for the only user. | ||
if models.CountUsers() == 1 { | ||
u.IsAdmin = true | ||
u.IsActive = true | ||
u.SetLastLogin() | ||
if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { | ||
ctx.ServerError("UpdateUser", err) | ||
return | ||
} | ||
} | ||
|
||
// Send confirmation email, no need for social account. | ||
if setting.Service.RegisterEmailConfirm && u.ID > 1 { | ||
models.SendActivateAccountMail(ctx.Context, u) | ||
ctx.Data["IsSendRegisterMail"] = true | ||
ctx.Data["Email"] = u.Email | ||
ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) | ||
ctx.HTML(200, TplActivate) | ||
|
||
if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { | ||
log.Error("Set cache(MailResendLimit) fail: %v", err) | ||
} | ||
return | ||
} | ||
|
||
ctx.Flash.Success(ctx.Tr("auth.sign_up_successful")) | ||
handleSignInFull(ctx, u, false, true) | ||
handleRegister(ctx, u, form.Remember, true) | ||
} | ||
|
||
// Activate render activate user page | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary.
setting.Service.AllowOnlyExternalRegistration
means user must register via external source. Since we have been inLinkAccountPostRegister
. The check is unnecessary.