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/user | |
parent | b3919c577f7082bad3955e039691c83b63c241e9 (diff) | |
download | gitea-f174633b36ef102d8e8324dd708b96335188f5dd.tar.gz gitea-f174633b36ef102d8e8324dd708b96335188f5dd.zip |
Clean code
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/setting.go | 11 | ||||
-rw-r--r-- | routers/user/user.go | 55 |
2 files changed, 33 insertions, 33 deletions
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 } } |