diff options
author | Unknwon <u@gogs.io> | 2015-08-19 04:58:45 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-19 04:58:45 +0800 |
commit | 47ac579f092cef9128fa0c74798ecaffa2c888f9 (patch) | |
tree | f1df7b8742fe72c36aaaf3330a196b090e3dbc54 /routers/user | |
parent | 928d9fc1d42fdc030cbf3847a0370f5088548379 (diff) | |
download | gitea-47ac579f092cef9128fa0c74798ecaffa2c888f9.tar.gz gitea-47ac579f092cef9128fa0c74798ecaffa2c888f9.zip |
only assign auto-admin when sign up by web
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/auth.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/routers/user/auth.go b/routers/user/auth.go index 61e572f9bc..5c6bb26fba 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -220,7 +220,6 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe Passwd: form.Password, IsActive: !setting.Service.RegisterEmailConfirm || isOauth, } - if err := models.CreateUser(u); err != nil { switch { 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) + // 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. if isOauth { if err := models.BindUserOauth2(u.Id, sid); err != nil { |