diff options
author | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-03-19 22:19:17 +0800 |
---|---|---|
committer | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-03-19 22:19:17 +0800 |
commit | c7660a81c669455e418610225034d6301cb59872 (patch) | |
tree | d114a5d41a3601dd199aabb47507482cc92407b6 /routers | |
parent | a0e73e2b5411499719a7e02281c48ad40dedfa24 (diff) | |
parent | 483cc3136920a70ae1707ec5337d574b288853c3 (diff) | |
download | gitea-c7660a81c669455e418610225034d6301cb59872.tar.gz gitea-c7660a81c669455e418610225034d6301cb59872.zip |
Merge remote-tracking branch 'origin/master'
Conflicts:
routers/user/user.go
Diffstat (limited to 'routers')
-rw-r--r-- | routers/dashboard.go | 4 | ||||
-rw-r--r-- | routers/repo/repo.go | 10 | ||||
-rw-r--r-- | routers/repo/single.go | 32 | ||||
-rw-r--r-- | routers/user/setting.go | 24 | ||||
-rw-r--r-- | routers/user/user.go | 45 |
5 files changed, 58 insertions, 57 deletions
diff --git a/routers/dashboard.go b/routers/dashboard.go index 6c194ad9e5..d5358f0a00 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.Render.HTML(200, "home", ctx.Data) } func Help(ctx *middleware.Context) { ctx.Data["PageIsHelp"] = true - ctx.HTML(200, "help", ctx.Data) + ctx.Render.HTML(200, "help", ctx.Data) } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index fb54d4ef8b..52d0773f87 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["PageIsNewRepo"] = true // For navbar arrow. ctx.Data["LanguageIgns"] = models.LanguageIgns ctx.Data["Licenses"] = models.Licenses - ctx.HTML(200, "repo/create", ctx.Data) + ctx.Render.HTML(200, "repo/create", ctx.Data) return } @@ -26,7 +26,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { form.Language, form.License, form.Visibility == "private", form.InitReadme == "on") if err == nil { log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName) - ctx.Redirect("/"+ctx.User.Name+"/"+form.RepoName, 302) + ctx.Render.Redirect("/"+ctx.User.Name+"/"+form.RepoName, 302) return } else if err == models.ErrRepoAlreadyExist { ctx.RenderWithErr("Repository name has already been used", "repo/create", &form) @@ -37,7 +37,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { func SettingPost(ctx *middleware.Context) { if !ctx.Repo.IsOwner { - ctx.Error(404) + ctx.Render.Error(404) return } @@ -45,7 +45,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.Render.HTML(200, "repo/setting", ctx.Data) return } @@ -56,5 +56,5 @@ func SettingPost(ctx *middleware.Context) { } log.Trace("%s Repository deleted: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.Repo.Repository.LowerName) - ctx.Redirect("/", 302) + ctx.Render.Redirect("/", 302) } diff --git a/routers/repo/single.go b/routers/repo/single.go index 171b095264..d64248d990 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -27,7 +27,7 @@ func Branches(ctx *middleware.Context, params martini.Params) { ctx.Handle(200, "repo.Branches", err) return } else if len(brs) == 0 { - ctx.Error(404) + ctx.Render.Error(404) return } @@ -38,7 +38,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.Render.HTML(200, "repo/branches", ctx.Data) } func Single(ctx *middleware.Context, params martini.Params) { @@ -57,11 +57,11 @@ func Single(ctx *middleware.Context, params martini.Params) { brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { log.Error("repo.Single(GetBranches): %v", err) - ctx.Error(404) + ctx.Render.Error(404) return } else if len(brs) == 0 { ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/single", ctx.Data) + ctx.Render.HTML(200, "repo/single", ctx.Data) return } @@ -72,7 +72,7 @@ func Single(ctx *middleware.Context, params martini.Params) { params["branchname"], params["commitid"], treename) if err != nil { log.Error("repo.Single(GetReposFiles): %v", err) - ctx.Error(404) + ctx.Render.Error(404) return } ctx.Data["Username"] = params["username"] @@ -94,7 +94,7 @@ func Single(ctx *middleware.Context, params martini.Params) { params["branchname"], params["commitid"]) if err != nil { log.Error("repo.Single(GetCommit): %v", err) - ctx.Error(404) + ctx.Render.Error(404) return } ctx.Data["LastCommit"] = commit @@ -130,12 +130,12 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Treenames"] = treenames ctx.Data["IsRepoToolbarSource"] = true ctx.Data["Files"] = files - ctx.HTML(200, "repo/single", ctx.Data) + ctx.Render.HTML(200, "repo/single", ctx.Data) } func Setting(ctx *middleware.Context, params martini.Params) { if !ctx.Repo.IsOwner { - ctx.Error(404) + ctx.Render.Error(404) return } @@ -143,11 +143,11 @@ func Setting(ctx *middleware.Context, params martini.Params) { brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { log.Error("repo.Setting(GetBranches): %v", err) - ctx.Error(404) + ctx.Render.Error(404) return } else if len(brs) == 0 { ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/setting", ctx.Data) + ctx.Render.HTML(200, "repo/setting", ctx.Data) return } @@ -158,7 +158,7 @@ func Setting(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = title + " - settings" ctx.Data["IsRepoToolbarSetting"] = true - ctx.HTML(200, "repo/setting", ctx.Data) + ctx.Render.HTML(200, "repo/setting", ctx.Data) } func Commits(ctx *middleware.Context, params martini.Params) { @@ -167,7 +167,7 @@ func Commits(ctx *middleware.Context, params martini.Params) { ctx.Handle(200, "repo.Commits", err) return } else if len(brs) == 0 { - ctx.Error(404) + ctx.Render.Error(404) return } @@ -175,19 +175,19 @@ func Commits(ctx *middleware.Context, params martini.Params) { commits, err := models.GetCommits(params["username"], params["reponame"], params["branchname"]) if err != nil { - ctx.Error(404) + ctx.Render.Error(404) return } ctx.Data["Commits"] = commits - ctx.HTML(200, "repo/commits", ctx.Data) + ctx.Render.HTML(200, "repo/commits", ctx.Data) } func Issues(ctx *middleware.Context) { ctx.Data["IsRepoToolbarIssues"] = true - ctx.HTML(200, "repo/issues", ctx.Data) + ctx.Render.HTML(200, "repo/issues", ctx.Data) } func Pulls(ctx *middleware.Context) { ctx.Data["IsRepoToolbarPulls"] = true - ctx.HTML(200, "repo/pulls", ctx.Data) + ctx.Render.HTML(200, "repo/pulls", ctx.Data) } diff --git a/routers/user/setting.go b/routers/user/setting.go index 719e0c1919..66289b6e4d 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.Render.HTML(200, "user/setting", ctx.Data) return } // below is for POST requests if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { - ctx.HTML(200, "user/setting", ctx.Data) + ctx.Render.HTML(200, "user/setting", ctx.Data) return } @@ -45,7 +45,7 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { } ctx.Data["IsSuccess"] = true - ctx.HTML(200, "user/setting", ctx.Data) + ctx.Render.HTML(200, "user/setting", ctx.Data) log.Trace("%s User setting updated: %s", ctx.Req.RequestURI, ctx.User.LowerName) } @@ -55,7 +55,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.Render.HTML(200, "user/password", ctx.Data) return } @@ -82,7 +82,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { } ctx.Data["Owner"] = user - ctx.HTML(200, "user/password", ctx.Data) + ctx.Render.HTML(200, "user/password", ctx.Data) log.Trace("%s User password updated: %s", ctx.Req.RequestURI, ctx.User.LowerName) } @@ -95,7 +95,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { if err != nil { ctx.Data["ErrorMsg"] = err log.Error("ssh.DelPublicKey: %v", err) - ctx.JSON(200, map[string]interface{}{ + ctx.Render.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), }) @@ -109,13 +109,13 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { if err = models.DeletePublicKey(k); err != nil { ctx.Data["ErrorMsg"] = err log.Error("ssh.DelPublicKey: %v", err) - ctx.JSON(200, map[string]interface{}{ + ctx.Render.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), }) } else { log.Trace("%s User SSH key deleted: %s", ctx.Req.RequestURI, ctx.User.LowerName) - ctx.JSON(200, map[string]interface{}{ + ctx.Render.JSON(200, map[string]interface{}{ "ok": true, }) } @@ -125,7 +125,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.Render.HTML(200, "user/publickey", ctx.Data) return } @@ -157,7 +157,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.Render.HTML(200, "user/publickey", ctx.Data) } func SettingNotification(ctx *middleware.Context) { @@ -165,7 +165,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.Render.HTML(200, "user/notification", ctx.Data) } func SettingSecurity(ctx *middleware.Context) { @@ -173,5 +173,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.Render.HTML(200, "user/security", ctx.Data) } diff --git a/routers/user/user.go b/routers/user/user.go index 8c96607055..d702f2b956 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -9,6 +9,8 @@ import ( "strings" "github.com/codegangsta/martini" + "github.com/martini-contrib/render" + "github.com/martini-contrib/sessions" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -33,7 +35,7 @@ func Dashboard(ctx *middleware.Context) { return } ctx.Data["Feeds"] = feeds - ctx.HTML(200, "user/dashboard", ctx.Data) + ctx.Render.HTML(200, "user/dashboard", ctx.Data) } func Profile(ctx *middleware.Context, params martini.Params) { @@ -68,21 +70,19 @@ func Profile(ctx *middleware.Context, params martini.Params) { ctx.Data["Repos"] = repos } - ctx.Data["PageIsUserProfile"] = true // For navbar arrow. - - ctx.HTML(200, "user/profile", ctx.Data) + ctx.Render.HTML(200, "user/profile", ctx.Data) } 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.Render.HTML(200, "user/signin", ctx.Data) return } if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { - ctx.HTML(200, "user/signin", ctx.Data) + ctx.Render.HTML(200, "user/signin", ctx.Data) return } @@ -99,13 +99,14 @@ func SignIn(ctx *middleware.Context, form auth.LogInForm) { ctx.Session.Set("userId", user.Id) ctx.Session.Set("userName", user.Name) - ctx.Redirect("/") + + ctx.Render.Redirect("/") } -func SignOut(ctx *middleware.Context) { - ctx.Session.Delete("userId") - ctx.Session.Delete("userName") - ctx.Redirect("/") +func SignOut(r render.Render, session sessions.Session) { + session.Delete("userId") + session.Delete("userName") + r.Redirect("/") } func SignUp(ctx *middleware.Context, form auth.RegisterForm) { @@ -113,7 +114,7 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) { ctx.Data["PageIsSignUp"] = true if ctx.Req.Method == "GET" { - ctx.HTML(200, "user/signup", ctx.Data) + ctx.Render.HTML(200, "user/signup", ctx.Data) return } @@ -126,7 +127,7 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) { } if ctx.HasError() { - ctx.HTML(200, "user/signup", ctx.Data) + ctx.Render.HTML(200, "user/signup", ctx.Data) return } @@ -156,7 +157,7 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) { if base.Service.RegisterEmailConfirm { auth.SendRegisterMail(u) } - ctx.Redirect("/user/login") + ctx.Render.Redirect("/user/login") } func Delete(ctx *middleware.Context) { @@ -165,7 +166,7 @@ func Delete(ctx *middleware.Context) { ctx.Data["IsUserPageSettingDelete"] = true if ctx.Req.Method == "GET" { - ctx.HTML(200, "user/delete", ctx.Data) + ctx.Render.HTML(200, "user/delete", ctx.Data) return } @@ -185,12 +186,12 @@ func Delete(ctx *middleware.Context) { return } } else { - ctx.Redirect("/") + ctx.Render.Redirect("/") return } } - ctx.HTML(200, "user/delete", ctx.Data) + ctx.Render.HTML(200, "user/delete", ctx.Data) } const ( @@ -201,7 +202,7 @@ const ( func Feeds(ctx *middleware.Context, form auth.FeedsForm) { actions, err := models.GetFeeds(form.UserId, form.Page*20, false) if err != nil { - ctx.JSON(500, err) + ctx.Render.JSON(500, err) } feeds := make([]string, len(actions)) @@ -209,19 +210,19 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { feeds[i] = fmt.Sprintf(TPL_FEED, base.ActionIcon(actions[i].OpType), base.TimeSince(actions[i].Created), base.ActionDesc(actions[i], ctx.User.AvatarLink())) } - ctx.JSON(200, &feeds) + ctx.Render.JSON(200, &feeds) } func Issues(ctx *middleware.Context) { - ctx.HTML(200, "user/issues", ctx.Data) + ctx.Render.HTML(200, "user/issues", ctx.Data) } func Pulls(ctx *middleware.Context) { - ctx.HTML(200, "user/pulls", ctx.Data) + ctx.Render.HTML(200, "user/pulls", ctx.Data) } func Stars(ctx *middleware.Context) { - ctx.HTML(200, "user/stars", ctx.Data) + ctx.Render.HTML(200, "user/stars", ctx.Data) } func Activate(ctx *middleware.Context) { |