diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-15 09:17:16 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-15 09:17:16 -0400 |
commit | f174633b36ef102d8e8324dd708b96335188f5dd (patch) | |
tree | d173c5dfa791ff9b107b426b8445d9b552a854b1 /routers | |
parent | b3919c577f7082bad3955e039691c83b63c241e9 (diff) | |
download | gitea-f174633b36ef102d8e8324dd708b96335188f5dd.tar.gz gitea-f174633b36ef102d8e8324dd708b96335188f5dd.zip |
Clean code
Diffstat (limited to 'routers')
-rw-r--r-- | routers/dashboard.go | 5 | ||||
-rw-r--r-- | routers/repo/repo.go | 14 | ||||
-rw-r--r-- | routers/repo/single.go | 6 | ||||
-rw-r--r-- | routers/user/setting.go | 11 | ||||
-rw-r--r-- | routers/user/user.go | 55 |
5 files changed, 46 insertions, 45 deletions
diff --git a/routers/dashboard.go b/routers/dashboard.go index a75445003a..de9378b0fa 100644 --- a/routers/dashboard.go +++ b/routers/dashboard.go @@ -10,12 +10,13 @@ import ( "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers/user" ) -func Home(r render.Render, data base.TmplData, session sessions.Session) { +func Home(ctx *middleware.Context, r render.Render, data base.TmplData, session sessions.Session) { if auth.IsSignedIn(session) { - user.Dashboard(r, data, session) + user.Dashboard(ctx) return } data["PageIsHome"] = true diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 5aee4cdae4..f920a70c19 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -13,10 +13,10 @@ import ( "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 Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { +func Create(form auth.CreateRepoForm, ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { data["Title"] = "Create repository" if req.Method == "GET" { @@ -61,10 +61,10 @@ func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data b return } - log.Handle(200, "repo.Create", data, r, err) + ctx.Handle(200, "repo.Create", err) } -func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { +func Delete(form auth.DeleteRepoForm, ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { data["Title"] = "Delete repository" if req.Method == "GET" { @@ -73,14 +73,14 @@ func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data b } if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil { - log.Handle(200, "repo.Delete", data, r, err) + ctx.Handle(200, "repo.Delete", err) return } r.Redirect("/", 302) } -func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { +func List(ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { u := auth.SignedInUser(session) if u != nil { r.Redirect("/") @@ -90,7 +90,7 @@ func List(req *http.Request, r render.Render, data base.TmplData, session sessio data["Title"] = "Repositories" repos, err := models.GetRepositories(u) if err != nil { - log.Handle(200, "repo.List", data, r, err) + ctx.Handle(200, "repo.List", err) return } diff --git a/routers/repo/single.go b/routers/repo/single.go index fc6661d05c..605eb231f3 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -7,10 +7,10 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/middleware" ) -func Single(params martini.Params, r render.Render, data base.TmplData) { +func Single(params martini.Params, ctx *middleware.Context, r render.Render, data base.TmplData) { if !data["IsRepositoryValid"].(bool) { return } @@ -21,7 +21,7 @@ func Single(params martini.Params, r render.Render, data base.TmplData) { files, err := models.GetReposFiles(params["username"], params["reponame"], params["branchname"], treename) if err != nil { - log.Handle(200, "repo.Single", data, r, err) + ctx.Handle(200, "repo.Single", err) return } data["Username"] = params["username"] diff --git a/routers/user/setting.go b/routers/user/setting.go index 8b5a2d18df..347aec4e03 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -15,9 +15,10 @@ import ( "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 Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { +func Setting(form auth.UpdateProfileForm, ctx *middleware.Context, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { data["Title"] = "Setting" data["PageIsUserSetting"] = true @@ -40,7 +41,7 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r user.Avatar = base.EncodeMd5(form.Avatar) user.AvatarEmail = form.Avatar if err := models.UpdateUser(user); err != nil { - log.Handle(200, "setting.Setting", data, r, err) + ctx.Handle(200, "setting.Setting", err) return } @@ -48,7 +49,7 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r r.HTML(200, "user/setting", data) } -func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.TmplData, session sessions.Session, req *http.Request) { +func SettingPassword(form auth.UpdatePasswdForm, ctx *middleware.Context, r render.Render, data base.TmplData, session sessions.Session, req *http.Request) { data["Title"] = "Password" data["PageIsUserSetting"] = true @@ -60,7 +61,7 @@ func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.Tmpl user := auth.SignedInUser(session) newUser := &models.User{Passwd: form.NewPasswd} if err := newUser.EncodePasswd(); err != nil { - log.Handle(200, "setting.SettingPassword", data, r, err) + ctx.Handle(200, "setting.SettingPassword", err) return } @@ -73,7 +74,7 @@ func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.Tmpl } else { user.Passwd = newUser.Passwd if err := models.UpdateUser(user); err != nil { - log.Handle(200, "setting.SettingPassword", data, r, err) + ctx.Handle(200, "setting.SettingPassword", err) return } data["IsSuccess"] = true diff --git a/routers/user/user.go b/routers/user/user.go index c66904a24f..9dbcb2a190 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -15,27 +15,26 @@ import ( "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 Dashboard(r render.Render, data base.TmplData, session sessions.Session) { - data["Title"] = "Dashboard" - data["PageIsUserDashboard"] = true - repos, err := models.GetRepositories(&models.User{Id: auth.SignedInId(session)}) +func Dashboard(ctx *middleware.Context) { + ctx.Data["Title"] = "Dashboard" + ctx.Data["PageIsUserDashboard"] = true + repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id}) if err != nil { - log.Handle(200, "user.Dashboard", data, r, err) + ctx.Handle(200, "user.Dashboard", err) return } - data["MyRepos"] = repos + ctx.Data["MyRepos"] = repos - feeds, err := models.GetFeeds(auth.SignedInId(session), 0, false) + feeds, err := models.GetFeeds(ctx.User.Id, 0, false) if err != nil { - log.Handle(200, "user.Dashboard", data, r, err) + ctx.Handle(200, "user.Dashboard", err) return } - data["Feeds"] = feeds - r.HTML(200, "user/dashboard", data) + ctx.Data["Feeds"] = feeds + ctx.Render.HTML(200, "user/dashboard", ctx.Data) } func Profile(ctx *middleware.Context, params martini.Params) { @@ -44,7 +43,7 @@ func Profile(ctx *middleware.Context, params martini.Params) { // TODO: Need to check view self or others. user, err := models.GetUserByName(params["username"]) if err != nil { - ctx.Log(200, "user.Profile", err) + ctx.Handle(200, "user.Profile", err) return } @@ -57,7 +56,7 @@ func Profile(ctx *middleware.Context, params martini.Params) { case "activity": feeds, err := models.GetFeeds(user.Id, 0, true) if err != nil { - ctx.Log(200, "user.Profile", err) + ctx.Handle(200, "user.Profile", err) return } ctx.Data["Feeds"] = feeds @@ -68,30 +67,30 @@ func Profile(ctx *middleware.Context, params martini.Params) { ctx.Render.HTML(200, "user/profile", ctx.Data) } -func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render.Render, session sessions.Session) { - data["Title"] = "Log In" +func SignIn(form auth.LogInForm, ctx *middleware.Context, r render.Render, session sessions.Session) { + ctx.Data["Title"] = "Log In" - if req.Method == "GET" { - r.HTML(200, "user/signin", data) + if ctx.Req.Method == "GET" { + ctx.Render.HTML(200, "user/signin", ctx.Data) return } - if hasErr, ok := data["HasError"]; ok && hasErr.(bool) { - r.HTML(200, "user/signin", data) + if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { + ctx.Render.HTML(200, "user/signin", ctx.Data) return } user, err := models.LoginUserPlain(form.UserName, form.Password) if err != nil { if err.Error() == models.ErrUserNotExist.Error() { - data["HasError"] = true - data["ErrorMsg"] = "Username or password is not correct" - auth.AssignForm(form, data) - r.HTML(200, "user/signin", data) + ctx.Data["HasError"] = true + ctx.Data["ErrorMsg"] = "Username or password is not correct" + auth.AssignForm(form, ctx.Data) + ctx.Render.HTML(200, "user/signin", ctx.Data) return } - log.Handle(200, "user.SignIn", data, r, err) + ctx.Handle(200, "user.SignIn", err) return } @@ -106,7 +105,7 @@ func SignOut(r render.Render, session sessions.Session) { r.Redirect("/") } -func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r render.Render) { +func SignUp(form auth.RegisterForm, ctx *middleware.Context, data base.TmplData, req *http.Request, r render.Render) { data["Title"] = "Sign Up" data["PageIsSignUp"] = true @@ -148,7 +147,7 @@ func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r ren data["ErrorMsg"] = "E-mail address has been already used" r.HTML(200, "user/signup", data) default: - log.Handle(200, "user.SignUp", data, r, err) + ctx.Handle(200, "user.SignUp", err) } return } @@ -156,7 +155,7 @@ func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r ren r.Redirect("/user/login") } -func Delete(data base.TmplData, req *http.Request, session sessions.Session, r render.Render) { +func Delete(data base.TmplData, ctx *middleware.Context, req *http.Request, session sessions.Session, r render.Render) { data["Title"] = "Delete Account" if req.Method == "GET" { @@ -172,7 +171,7 @@ func Delete(data base.TmplData, req *http.Request, session sessions.Session, r r case models.ErrUserOwnRepos.Error(): data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first." default: - log.Handle(200, "user.Delete", data, r, err) + ctx.Handle(200, "user.Delete", err) return } } |