treat register like sign in, even oauth
This commit is contained in:
parent
e64ff60c13
commit
eda51c2079
|
@ -76,6 +76,7 @@ type RegisterForm struct {
|
||||||
Email string `binding:"Required;Email;MaxSize(254)"`
|
Email string `binding:"Required;Email;MaxSize(254)"`
|
||||||
Password string `binding:"MaxSize(255)"`
|
Password string `binding:"MaxSize(255)"`
|
||||||
Retype string
|
Retype string
|
||||||
|
Remember bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate valideates the fields
|
// Validate valideates the fields
|
||||||
|
|
|
@ -494,6 +494,36 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
|
||||||
return setting.AppSubURL + "/"
|
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(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete the signin without logging in again
|
||||||
|
handleSignInFull(ctx, u, remember, true)
|
||||||
|
}
|
||||||
|
|
||||||
// SignInOAuth handles the OAuth2 login buttons
|
// SignInOAuth handles the OAuth2 login buttons
|
||||||
func SignInOAuth(ctx *context.Context) {
|
func SignInOAuth(ctx *context.Context) {
|
||||||
provider := ctx.Params(":provider")
|
provider := ctx.Params(":provider")
|
||||||
|
@ -823,14 +853,20 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
|
||||||
ctx.ServerError("CreateUser", err)
|
ctx.ServerError("CreateUser", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO LoginName should come from form.UserName... shouldn't it?
|
||||||
u := &models.User{
|
u := &models.User{
|
||||||
Name: form.UserName,
|
Name: form.UserName,
|
||||||
Email: form.Email,
|
Email: form.Email,
|
||||||
Passwd: form.Password,
|
Passwd: form.Password,
|
||||||
IsActive: !setting.Service.RegisterEmailConfirm,
|
IsActive: !setting.Service.RegisterEmailConfirm,
|
||||||
LoginType: models.LoginOAuth2,
|
}
|
||||||
LoginSource: loginSource.ID,
|
|
||||||
LoginName: gothUser.(goth.User).UserID,
|
// 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 {
|
if err := models.CreateUser(u); err != nil {
|
||||||
|
@ -854,32 +890,16 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
|
||||||
}
|
}
|
||||||
log.Trace("Account created: %s", u.Name)
|
log.Trace("Account created: %s", u.Name)
|
||||||
|
|
||||||
// Auto-set admin for the only user.
|
// This will link the account in such a way that it can be removed
|
||||||
if models.CountUsers() == 1 {
|
if !setting.Service.AllowOnlyExternalRegistration {
|
||||||
u.IsAdmin = true
|
err = models.LinkAccountToUser(u, gothUser.(goth.User))
|
||||||
u.IsActive = true
|
if err != nil {
|
||||||
u.SetLastLogin()
|
ctx.ServerError("UserLinkAccount", err)
|
||||||
if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil {
|
|
||||||
ctx.ServerError("UpdateUser", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send confirmation email
|
handleRegister(ctx, u, form.Remember, true)
|
||||||
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(4, "Set cache(MailResendLimit) fail: %v", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Redirect(setting.AppSubURL + "/user/login")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignOut sign out from login status
|
// SignOut sign out from login status
|
||||||
|
@ -976,32 +996,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
|
||||||
}
|
}
|
||||||
log.Trace("Account created: %s", u.Name)
|
log.Trace("Account created: %s", u.Name)
|
||||||
|
|
||||||
// Auto-set admin for the only user.
|
handleRegister(ctx, u, form.Remember, true)
|
||||||
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(4, "Set cache(MailResendLimit) fail: %v", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Redirect(setting.AppSubURL + "/user/login")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate render activate user page
|
// Activate render activate user page
|
||||||
|
|
|
@ -46,6 +46,13 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
<div class="inline field">
|
||||||
|
<label></label>
|
||||||
|
<div class="ui checkbox">
|
||||||
|
<label>{{.i18n.Tr "auth.remember_me"}}</label>
|
||||||
|
<input name="remember" type="checkbox">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="inline field">
|
<div class="inline field">
|
||||||
<label></label>
|
<label></label>
|
||||||
<button class="ui green button">
|
<button class="ui green button">
|
||||||
|
|
Loading…
Reference in New Issue