From 4cf6cc63b0679aaf5fe8b74a2aaf0bd92b1f12d3 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 20 Mar 2014 08:02:14 -0400 Subject: [PATCH] Work on admin --- conf/app.ini | 4 ---- models/user.go | 8 +++++++- modules/base/conf.go | 2 -- modules/middleware/auth.go | 2 +- modules/middleware/context.go | 6 +----- routers/user/user.go | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index 21090ceba5..658f7c0151 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -27,10 +27,6 @@ PASSWD = ; For "postgres" only, either "disable", "require" or "verify-full" SSL_MODE = disable -[admin] -; Administor's name, which should be same as the user name you want to authorize -NAME = admin - [security] ; !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!! SECRET_KEY = !#@FDEWREWR&*( diff --git a/models/user.go b/models/user.go index 8f74fd53fb..fd89af6b3f 100644 --- a/models/user.go +++ b/models/user.go @@ -137,7 +137,13 @@ func RegisterUser(user *User) (*User, error) { } return nil, err } - return user, nil + + if user.Id == 1 { + user.IsAdmin = true + user.IsActive = true + _, err = orm.Id(user.Id).UseBool().Update(user) + } + return user, err } // get user by erify code diff --git a/modules/base/conf.go b/modules/base/conf.go index c904c5b39c..fdbf3ad385 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -32,7 +32,6 @@ var ( AppUrl string Domain string SecretKey string - AdminName string Cfg *goconfig.ConfigFile MailService *Mailer ) @@ -174,7 +173,6 @@ func init() { AppUrl = Cfg.MustValue("server", "ROOT_URL") Domain = Cfg.MustValue("server", "DOMAIN") SecretKey = Cfg.MustValue("security", "SECRET_KEY") - AdminName = strings.ToLower(Cfg.MustValue("admin", "NAME")) } func NewServices() { diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index b67f766bd7..44033abb8f 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -39,7 +39,7 @@ func SignOutRequire() martini.Handler { // AdminRequire requires user signed in as administor. func AdminRequire() martini.Handler { return func(ctx *Context) { - if ctx.User.LowerName != base.AdminName && !ctx.User.IsAdmin { + if !ctx.User.IsAdmin { ctx.Error(403) return } diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 744cdfc10c..cb3cbabca6 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -14,7 +14,6 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" - "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" ) @@ -112,10 +111,7 @@ func InitContext() martini.Handler { ctx.Data["SignedUser"] = user ctx.Data["SignedUserId"] = user.Id ctx.Data["SignedUserName"] = user.LowerName - - if ctx.User.IsAdmin || ctx.User.LowerName == base.AdminName { - ctx.Data["IsAdmin"] = true - } + ctx.Data["IsAdmin"] = ctx.User.IsAdmin } ctx.Data["PageStartTime"] = time.Now() diff --git a/routers/user/user.go b/routers/user/user.go index 2b759e4192..be2c4d3839 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -153,7 +153,7 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) { log.Trace("%s User created: %s", ctx.Req.RequestURI, strings.ToLower(form.UserName)) // Send confirmation e-mail. - if base.Service.RegisterEmailConfirm { + if base.Service.RegisterEmailConfirm && u.Id > 1 { mailer.SendRegisterMail(ctx.Render, u) ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email