only assign auto-admin when sign up by web
This commit is contained in:
parent
928d9fc1d4
commit
47ac579f09
4 changed files with 14 additions and 12 deletions
|
@ -206,7 +206,7 @@ func runWeb(ctx *cli.Context) {
|
||||||
m.Get("/issues", user.Issues)
|
m.Get("/issues", user.Issues)
|
||||||
}, reqSignIn)
|
}, reqSignIn)
|
||||||
|
|
||||||
// API.
|
// ***** START: API *****
|
||||||
// FIXME: custom form error response.
|
// FIXME: custom form error response.
|
||||||
m.Group("/api", func() {
|
m.Group("/api", func() {
|
||||||
m.Group("/v1", func() {
|
m.Group("/v1", func() {
|
||||||
|
@ -248,6 +248,7 @@ func runWeb(ctx *cli.Context) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}, ignSignIn)
|
}, ignSignIn)
|
||||||
|
// ***** END: API *****
|
||||||
|
|
||||||
// ***** START: User *****
|
// ***** START: User *****
|
||||||
m.Group("/user", func() {
|
m.Group("/user", func() {
|
||||||
|
|
|
@ -373,17 +373,9 @@ func CreateUser(u *User) (err error) {
|
||||||
} else if err = os.MkdirAll(UserPath(u.Name), os.ModePerm); err != nil {
|
} else if err = os.MkdirAll(UserPath(u.Name), os.ModePerm); err != nil {
|
||||||
sess.Rollback()
|
sess.Rollback()
|
||||||
return err
|
return err
|
||||||
} else if err = sess.Commit(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-set admin for the first user.
|
return sess.Commit()
|
||||||
if CountUsers() == 1 {
|
|
||||||
u.IsAdmin = true
|
|
||||||
u.IsActive = true
|
|
||||||
_, err = x.Id(u.Id).AllCols().Update(u)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func countUsers(e Engine) int64 {
|
func countUsers(e Engine) int64 {
|
||||||
|
|
|
@ -80,7 +80,7 @@ func Toggle(options *ToggleOptions) macaron.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !options.SignOutRequire && !options.DisableCsrf && ctx.Req.Method == "POST" {
|
if !options.SignOutRequire && !options.DisableCsrf && ctx.Req.Method == "POST" && !auth.IsAPIPath(ctx.Req.URL.Path) {
|
||||||
csrf.Validate(ctx.Context, ctx.csrf)
|
csrf.Validate(ctx.Context, ctx.csrf)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
|
|
@ -220,7 +220,6 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
|
||||||
Passwd: form.Password,
|
Passwd: form.Password,
|
||||||
IsActive: !setting.Service.RegisterEmailConfirm || isOauth,
|
IsActive: !setting.Service.RegisterEmailConfirm || isOauth,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.CreateUser(u); err != nil {
|
if err := models.CreateUser(u); err != nil {
|
||||||
switch {
|
switch {
|
||||||
case models.IsErrUserAlreadyExist(err):
|
case models.IsErrUserAlreadyExist(err):
|
||||||
|
@ -242,6 +241,16 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
|
||||||
}
|
}
|
||||||
log.Trace("Account created: %s", u.Name)
|
log.Trace("Account created: %s", u.Name)
|
||||||
|
|
||||||
|
// Auto-set admin for the only user.
|
||||||
|
if models.CountUsers() == 1 {
|
||||||
|
u.IsAdmin = true
|
||||||
|
u.IsActive = true
|
||||||
|
if err := models.UpdateUser(u); err != nil {
|
||||||
|
ctx.Handle(500, "UpdateUser", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Bind social account.
|
// Bind social account.
|
||||||
if isOauth {
|
if isOauth {
|
||||||
if err := models.BindUserOauth2(u.Id, sid); err != nil {
|
if err := models.BindUserOauth2(u.Id, sid); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue