Work on admin

This commit is contained in:
Unknown 2014-03-20 08:02:14 -04:00
parent 9f9cd6bfc6
commit 4cf6cc63b0
6 changed files with 10 additions and 14 deletions

View file

@ -27,10 +27,6 @@ PASSWD =
; For "postgres" only, either "disable", "require" or "verify-full" ; For "postgres" only, either "disable", "require" or "verify-full"
SSL_MODE = disable SSL_MODE = disable
[admin]
; Administor's name, which should be same as the user name you want to authorize
NAME = admin
[security] [security]
; !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!! ; !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!!
SECRET_KEY = !#@FDEWREWR&*( SECRET_KEY = !#@FDEWREWR&*(

View file

@ -137,7 +137,13 @@ func RegisterUser(user *User) (*User, error) {
} }
return nil, err 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 // get user by erify code

View file

@ -32,7 +32,6 @@ var (
AppUrl string AppUrl string
Domain string Domain string
SecretKey string SecretKey string
AdminName string
Cfg *goconfig.ConfigFile Cfg *goconfig.ConfigFile
MailService *Mailer MailService *Mailer
) )
@ -174,7 +173,6 @@ func init() {
AppUrl = Cfg.MustValue("server", "ROOT_URL") AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN") Domain = Cfg.MustValue("server", "DOMAIN")
SecretKey = Cfg.MustValue("security", "SECRET_KEY") SecretKey = Cfg.MustValue("security", "SECRET_KEY")
AdminName = strings.ToLower(Cfg.MustValue("admin", "NAME"))
} }
func NewServices() { func NewServices() {

View file

@ -39,7 +39,7 @@ func SignOutRequire() martini.Handler {
// AdminRequire requires user signed in as administor. // AdminRequire requires user signed in as administor.
func AdminRequire() martini.Handler { func AdminRequire() martini.Handler {
return func(ctx *Context) { return func(ctx *Context) {
if ctx.User.LowerName != base.AdminName && !ctx.User.IsAdmin { if !ctx.User.IsAdmin {
ctx.Error(403) ctx.Error(403)
return return
} }

View file

@ -14,7 +14,6 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
) )
@ -112,10 +111,7 @@ func InitContext() martini.Handler {
ctx.Data["SignedUser"] = user ctx.Data["SignedUser"] = user
ctx.Data["SignedUserId"] = user.Id ctx.Data["SignedUserId"] = user.Id
ctx.Data["SignedUserName"] = user.LowerName ctx.Data["SignedUserName"] = user.LowerName
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
if ctx.User.IsAdmin || ctx.User.LowerName == base.AdminName {
ctx.Data["IsAdmin"] = true
}
} }
ctx.Data["PageStartTime"] = time.Now() ctx.Data["PageStartTime"] = time.Now()

View file

@ -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)) log.Trace("%s User created: %s", ctx.Req.RequestURI, strings.ToLower(form.UserName))
// Send confirmation e-mail. // Send confirmation e-mail.
if base.Service.RegisterEmailConfirm { if base.Service.RegisterEmailConfirm && u.Id > 1 {
mailer.SendRegisterMail(ctx.Render, u) mailer.SendRegisterMail(ctx.Render, u)
ctx.Data["IsSendRegisterMail"] = true ctx.Data["IsSendRegisterMail"] = true
ctx.Data["Email"] = u.Email ctx.Data["Email"] = u.Email