diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-22 00:50:47 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-22 00:50:47 +0800 |
commit | 17da2fd2e30e85909394bc58069ecab14d8d8577 (patch) | |
tree | d80e786818d20aed12b7a84f6a9961468a7f70ec /routers | |
parent | efdaf6ee1536f043d9e242dc16a096c99ec1bfda (diff) | |
parent | f219ddcf4ef13b9d5de129da4eb2b56dbc899d61 (diff) | |
download | gitea-17da2fd2e30e85909394bc58069ecab14d8d8577.tar.gz gitea-17da2fd2e30e85909394bc58069ecab14d8d8577.zip |
merged
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/admin.go | 77 | ||||
-rw-r--r-- | routers/admin/user.go | 109 | ||||
-rw-r--r-- | routers/dashboard.go | 4 | ||||
-rw-r--r-- | routers/dev/template.go | 2 | ||||
-rw-r--r-- | routers/repo/repo.go | 7 | ||||
-rw-r--r-- | routers/repo/single.go | 40 | ||||
-rw-r--r-- | routers/user/setting.go | 19 | ||||
-rw-r--r-- | routers/user/user.go | 56 |
8 files changed, 268 insertions, 46 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go new file mode 100644 index 0000000000..2e19b99c10 --- /dev/null +++ b/routers/admin/admin.go @@ -0,0 +1,77 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package admin + +import ( + "strings" + + "github.com/codegangsta/martini" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) + +func Dashboard(ctx *middleware.Context) { + ctx.Data["Title"] = "Admin Dashboard" + ctx.Data["PageIsDashboard"] = true + ctx.Data["Stats"] = models.GetStatistic() + ctx.HTML(200, "admin/dashboard") +} + +func Users(ctx *middleware.Context) { + ctx.Data["Title"] = "User Management" + ctx.Data["PageIsUsers"] = true + + var err error + ctx.Data["Users"], err = models.GetUsers(100, 0) + if err != nil { + ctx.Handle(200, "admin.Users", err) + return + } + ctx.HTML(200, "admin/users") +} + +func Repositories(ctx *middleware.Context) { + ctx.Data["Title"] = "Repository Management" + ctx.Data["PageIsRepos"] = true + + var err error + ctx.Data["Repos"], err = models.GetRepos(100, 0) + if err != nil { + ctx.Handle(200, "admin.Repositories", err) + return + } + ctx.HTML(200, "admin/repos") +} + +func Config(ctx *middleware.Context) { + ctx.Data["Title"] = "Server Configuration" + ctx.Data["PageIsConfig"] = true + + ctx.Data["AppUrl"] = base.AppUrl + ctx.Data["Domain"] = base.Domain + ctx.Data["RunUser"] = base.RunUser + ctx.Data["RunMode"] = strings.Title(martini.Env) + ctx.Data["RepoRootPath"] = base.RepoRootPath + + ctx.Data["Service"] = base.Service + + ctx.Data["DbCfg"] = models.DbCfg + + ctx.Data["MailerEnabled"] = false + if base.MailService != nil { + ctx.Data["MailerEnabled"] = true + ctx.Data["Mailer"] = base.MailService + } + + ctx.Data["CacheAdapter"] = base.CacheAdapter + ctx.Data["CacheConfig"] = base.CacheConfig + + ctx.Data["LogMode"] = base.LogMode + ctx.Data["LogConfig"] = base.LogConfig + + ctx.HTML(200, "admin/config") +} diff --git a/routers/admin/user.go b/routers/admin/user.go new file mode 100644 index 0000000000..d6f8523218 --- /dev/null +++ b/routers/admin/user.go @@ -0,0 +1,109 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package admin + +import ( + "strings" + + "github.com/codegangsta/martini" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/auth" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/middleware" +) + +func NewUser(ctx *middleware.Context, form auth.RegisterForm) { + ctx.Data["Title"] = "New Account" + ctx.Data["PageIsUsers"] = true + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "admin/users/new") + return + } + + if form.Password != form.RetypePasswd { + ctx.Data["HasError"] = true + ctx.Data["Err_Password"] = true + ctx.Data["Err_RetypePasswd"] = true + ctx.Data["ErrorMsg"] = "Password and re-type password are not same" + auth.AssignForm(form, ctx.Data) + } + + if ctx.HasError() { + ctx.HTML(200, "admin/users/new") + return + } + + u := &models.User{ + Name: form.UserName, + Email: form.Email, + Passwd: form.Password, + IsActive: true, + } + + var err error + if u, err = models.RegisterUser(u); err != nil { + switch err { + case models.ErrUserAlreadyExist: + ctx.RenderWithErr("Username has been already taken", "admin/users/new", &form) + case models.ErrEmailAlreadyUsed: + ctx.RenderWithErr("E-mail address has been already used", "admin/users/new", &form) + case models.ErrUserNameIllegal: + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form) + default: + ctx.Handle(200, "admin.user.NewUser", err) + } + return + } + + log.Trace("%s User created by admin(%s): %s", ctx.Req.RequestURI, + ctx.User.LowerName, strings.ToLower(form.UserName)) + + ctx.Redirect("/admin/users") +} + +func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) { + ctx.Data["Title"] = "Edit Account" + ctx.Data["PageIsUsers"] = true + + uid, err := base.StrTo(params["userid"]).Int() + if err != nil { + ctx.Handle(200, "admin.user.EditUser", err) + return + } + + u, err := models.GetUserById(int64(uid)) + if err != nil { + ctx.Handle(200, "admin.user.EditUser", err) + return + } + + if ctx.Req.Method == "GET" { + ctx.Data["User"] = u + ctx.HTML(200, "admin/users/edit") + return + } + + u.Email = form.Email + u.Website = form.Website + u.Location = form.Location + u.Avatar = base.EncodeMd5(form.Avatar) + u.AvatarEmail = form.Avatar + u.IsActive = form.Active == "on" + u.IsAdmin = form.Admin == "on" + if err := models.UpdateUser(u); err != nil { + ctx.Handle(200, "admin.user.EditUser", err) + return + } + + ctx.Data["IsSuccess"] = true + ctx.Data["User"] = u + ctx.HTML(200, "admin/users/edit") + + log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI, + ctx.User.LowerName, ctx.User.LowerName) +} diff --git a/routers/dashboard.go b/routers/dashboard.go index 6c194ad9e5..f61d67b7de 100644 --- a/routers/dashboard.go +++ b/routers/dashboard.go @@ -15,10 +15,10 @@ func Home(ctx *middleware.Context) { return } ctx.Data["PageIsHome"] = true - ctx.HTML(200, "home", ctx.Data) + ctx.HTML(200, "home") } func Help(ctx *middleware.Context) { ctx.Data["PageIsHelp"] = true - ctx.HTML(200, "help", ctx.Data) + ctx.HTML(200, "help") } diff --git a/routers/dev/template.go b/routers/dev/template.go index 7d5225ece7..d2f77ac4d5 100644 --- a/routers/dev/template.go +++ b/routers/dev/template.go @@ -21,5 +21,5 @@ func TemplatePreview(ctx *middleware.Context, params martini.Params) { ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374" ctx.Data["ActiveCodeLives"] = base.Service.ActiveCodeLives / 60 ctx.Data["ResetPwdCodeLives"] = base.Service.ResetPwdCodeLives / 60 - ctx.HTML(200, params["_1"], ctx.Data) + ctx.HTML(200, params["_1"]) } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index b38473b18a..c83a6df522 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -18,7 +18,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.Data["Licenses"] = models.Licenses if ctx.Req.Method == "GET" { - ctx.HTML(200, "repo/create", ctx.Data) + ctx.HTML(200, "repo/create") return } @@ -31,6 +31,9 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { } else if err == models.ErrRepoAlreadyExist { ctx.RenderWithErr("Repository name has already been used", "repo/create", &form) return + } else if err == models.ErrRepoNameIllegal { + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/create", &form) + return } ctx.Handle(200, "repo.Create", err) } @@ -45,7 +48,7 @@ func SettingPost(ctx *middleware.Context) { case "delete": if len(ctx.Repo.Repository.Name) == 0 || ctx.Repo.Repository.Name != ctx.Query("repository") { ctx.Data["ErrorMsg"] = "Please make sure you entered repository name is correct." - ctx.HTML(200, "repo/setting", ctx.Data) + ctx.HTML(200, "repo/setting") return } diff --git a/routers/repo/single.go b/routers/repo/single.go index 064150a234..37c0fabd79 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -40,7 +40,7 @@ func Branches(ctx *middleware.Context, params martini.Params) { ctx.Data["Branches"] = brs ctx.Data["IsRepoToolbarBranches"] = true - ctx.HTML(200, "repo/branches", ctx.Data) + ctx.HTML(200, "repo/branches") } func Single(ctx *middleware.Context, params martini.Params) { @@ -61,6 +61,8 @@ func Single(ctx *middleware.Context, params martini.Params) { return } + ctx.Data["IsRepoToolbarSource"] = true + // Branches. brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { @@ -69,7 +71,7 @@ func Single(ctx *middleware.Context, params martini.Params) { return } else if len(brs) == 0 { ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/single", ctx.Data) + ctx.HTML(200, "repo/single") return } @@ -86,6 +88,11 @@ func Single(ctx *middleware.Context, params martini.Params) { branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"] + if len(treename) != 0 && repoFile == nil { + ctx.Error(404) + return + } + if repoFile != nil && repoFile.IsFile() { if repoFile.Size > 1024*1024 || repoFile.Filemode != git.FileModeBlob { ctx.Data["FileIsLarge"] = true @@ -95,6 +102,11 @@ func Single(ctx *middleware.Context, params martini.Params) { } else { ctx.Data["IsFile"] = true ctx.Data["FileName"] = repoFile.Name + ext := path.Ext(repoFile.Name) + if len(ext) > 0 { + ext = ext[1:] + } + ctx.Data["FileExt"] = ext readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name) ctx.Data["ReadmeExist"] = readmeExist @@ -139,10 +151,9 @@ func Single(ctx *middleware.Context, params martini.Params) { return } else { // current repo branch link - urlPrefix := "http://" + base.Domain + branchLink ctx.Data["FileName"] = readmeFile.Name - ctx.Data["FileContent"] = string(base.RenderMarkdown(blob.Contents(), urlPrefix)) + ctx.Data["FileContent"] = string(base.RenderMarkdown(blob.Contents(), branchLink)) } } } @@ -178,9 +189,8 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames - ctx.Data["IsRepoToolbarSource"] = true ctx.Data["BranchLink"] = branchLink - ctx.HTML(200, "repo/single", ctx.Data) + ctx.HTML(200, "repo/single") } func Http(ctx *middleware.Context, params martini.Params) { @@ -212,6 +222,8 @@ func Setting(ctx *middleware.Context, params martini.Params) { return } + ctx.Data["IsRepoToolbarSetting"] = true + // Branches. brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { @@ -220,7 +232,7 @@ func Setting(ctx *middleware.Context, params martini.Params) { return } else if len(brs) == 0 { ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/setting", ctx.Data) + ctx.HTML(200, "repo/setting") return } @@ -229,9 +241,13 @@ func Setting(ctx *middleware.Context, params martini.Params) { title = t } + if len(params["branchname"]) == 0 { + params["branchname"] = "master" + } + + ctx.Data["Branchname"] = params["branchname"] ctx.Data["Title"] = title + " - settings" - ctx.Data["IsRepoToolbarSetting"] = true - ctx.HTML(200, "repo/setting", ctx.Data) + ctx.HTML(200, "repo/setting") } func Commits(ctx *middleware.Context, params martini.Params) { @@ -255,17 +271,17 @@ func Commits(ctx *middleware.Context, params martini.Params) { ctx.Data["Reponame"] = params["reponame"] ctx.Data["CommitCount"] = commits.Len() ctx.Data["Commits"] = commits - ctx.HTML(200, "repo/commits", ctx.Data) + ctx.HTML(200, "repo/commits") } func Issues(ctx *middleware.Context) { ctx.Data["IsRepoToolbarIssues"] = true - ctx.HTML(200, "repo/issues", ctx.Data) + ctx.HTML(200, "repo/issues") } func Pulls(ctx *middleware.Context) { ctx.Data["IsRepoToolbarPulls"] = true - ctx.HTML(200, "repo/pulls", ctx.Data) + ctx.HTML(200, "repo/pulls") } func Action(ctx *middleware.Context, params martini.Params) { diff --git a/routers/user/setting.go b/routers/user/setting.go index 053f327f0f..75adf2b81d 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -24,13 +24,13 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.Data["Owner"] = user if ctx.Req.Method == "GET" { - ctx.HTML(200, "user/setting", ctx.Data) + ctx.HTML(200, "user/setting") return } // below is for POST requests if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { - ctx.HTML(200, "user/setting", ctx.Data) + ctx.HTML(200, "user/setting") return } @@ -45,7 +45,8 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { } ctx.Data["IsSuccess"] = true - ctx.HTML(200, "user/setting", ctx.Data) + ctx.HTML(200, "user/setting") + log.Trace("%s User setting updated: %s", ctx.Req.RequestURI, ctx.User.LowerName) } @@ -55,7 +56,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { ctx.Data["IsUserPageSettingPasswd"] = true if ctx.Req.Method == "GET" { - ctx.HTML(200, "user/password", ctx.Data) + ctx.HTML(200, "user/password") return } @@ -82,7 +83,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { } ctx.Data["Owner"] = user - ctx.HTML(200, "user/password", ctx.Data) + ctx.HTML(200, "user/password") log.Trace("%s User password updated: %s", ctx.Req.RequestURI, ctx.User.LowerName) } @@ -123,7 +124,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { // Add new SSH key. if ctx.Req.Method == "POST" { if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { - ctx.HTML(200, "user/publickey", ctx.Data) + ctx.HTML(200, "user/publickey") return } @@ -155,7 +156,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingSSH"] = true ctx.Data["Keys"] = keys - ctx.HTML(200, "user/publickey", ctx.Data) + ctx.HTML(200, "user/publickey") } func SettingNotification(ctx *middleware.Context) { @@ -163,7 +164,7 @@ func SettingNotification(ctx *middleware.Context) { ctx.Data["Title"] = "Notification" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingNotify"] = true - ctx.HTML(200, "user/notification", ctx.Data) + ctx.HTML(200, "user/notification") } func SettingSecurity(ctx *middleware.Context) { @@ -171,5 +172,5 @@ func SettingSecurity(ctx *middleware.Context) { ctx.Data["Title"] = "Security" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingSecurity"] = true - ctx.HTML(200, "user/security", ctx.Data) + ctx.HTML(200, "user/security") } diff --git a/routers/user/user.go b/routers/user/user.go index f495cb13ab..d38eb1ceb3 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -34,7 +34,7 @@ func Dashboard(ctx *middleware.Context) { return } ctx.Data["Feeds"] = feeds - ctx.HTML(200, "user/dashboard", ctx.Data) + ctx.HTML(200, "user/dashboard") } func Profile(ctx *middleware.Context, params martini.Params) { @@ -70,19 +70,19 @@ func Profile(ctx *middleware.Context, params martini.Params) { } ctx.Data["PageIsUserProfile"] = true - ctx.HTML(200, "user/profile", ctx.Data) + ctx.HTML(200, "user/profile") } func SignIn(ctx *middleware.Context, form auth.LogInForm) { ctx.Data["Title"] = "Log In" if ctx.Req.Method == "GET" { - ctx.HTML(200, "user/signin", ctx.Data) + ctx.HTML(200, "user/signin") return } if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { - ctx.HTML(200, "user/signin", ctx.Data) + ctx.HTML(200, "user/signin") return } @@ -112,8 +112,14 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) { ctx.Data["Title"] = "Sign Up" ctx.Data["PageIsSignUp"] = true + if base.Service.DisenableRegisteration { + ctx.Data["DisenableRegisteration"] = true + ctx.HTML(200, "user/signup") + return + } + if ctx.Req.Method == "GET" { - ctx.HTML(200, "user/signup", ctx.Data) + ctx.HTML(200, "user/signup") return } @@ -126,7 +132,7 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) { } if ctx.HasError() { - ctx.HTML(200, "user/signup", ctx.Data) + ctx.HTML(200, "user/signup") return } @@ -139,11 +145,13 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) { var err error if u, err = models.RegisterUser(u); err != nil { - switch err.Error() { - case models.ErrUserAlreadyExist.Error(): + switch err { + case models.ErrUserAlreadyExist: ctx.RenderWithErr("Username has been already taken", "user/signup", &form) - case models.ErrEmailAlreadyUsed.Error(): + case models.ErrEmailAlreadyUsed: ctx.RenderWithErr("E-mail address has been already used", "user/signup", &form) + case models.ErrUserNameIllegal: + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "user/signup", &form) default: ctx.Handle(200, "user.SignUp", err) } @@ -153,12 +161,16 @@ 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 ctx.Data["Hours"] = base.Service.ActiveCodeLives / 60 - ctx.Render.HTML(200, "user/active", ctx.Data) + ctx.HTML(200, "user/active") + + if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { + log.Error("Set cache(MailResendLimit) fail: %v", err) + } return } ctx.Redirect("/user/login") @@ -170,7 +182,7 @@ func Delete(ctx *middleware.Context) { ctx.Data["IsUserPageSettingDelete"] = true if ctx.Req.Method == "GET" { - ctx.HTML(200, "user/delete", ctx.Data) + ctx.HTML(200, "user/delete") return } @@ -195,7 +207,7 @@ func Delete(ctx *middleware.Context) { } } - ctx.HTML(200, "user/delete", ctx.Data) + ctx.HTML(200, "user/delete") } const ( @@ -218,15 +230,15 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { } func Issues(ctx *middleware.Context) { - ctx.HTML(200, "user/issues", ctx.Data) + ctx.HTML(200, "user/issues") } func Pulls(ctx *middleware.Context) { - ctx.HTML(200, "user/pulls", ctx.Data) + ctx.HTML(200, "user/pulls") } func Stars(ctx *middleware.Context) { - ctx.HTML(200, "user/stars", ctx.Data) + ctx.HTML(200, "user/stars") } func Activate(ctx *middleware.Context) { @@ -239,12 +251,16 @@ func Activate(ctx *middleware.Context) { } // Resend confirmation e-mail. if base.Service.RegisterEmailConfirm { - ctx.Data["Hours"] = base.Service.ActiveCodeLives / 60 - mailer.SendActiveMail(ctx.Render, ctx.User) + if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) { + ctx.Data["ResendLimited"] = true + } else { + ctx.Data["Hours"] = base.Service.ActiveCodeLives / 60 + mailer.SendActiveMail(ctx.Render, ctx.User) + } } else { ctx.Data["ServiceNotEnabled"] = true } - ctx.Render.HTML(200, "user/active", ctx.Data) + ctx.HTML(200, "user/active") return } @@ -263,5 +279,5 @@ func Activate(ctx *middleware.Context) { } ctx.Data["IsActivateFailed"] = true - ctx.Render.HTML(200, "user/active", ctx.Data) + ctx.HTML(200, "user/active") } |