diff --git a/README.md b/README.md index 619f9a9dd6..42369868f1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.2.3 Alpha +##### Current version: 0.2.4 Alpha #### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site. diff --git a/README_ZH.md b/README_ZH.md index 35a0b7630d..71db29a6ed 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。 ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.2.3 Alpha +##### 当前版本:0.2.4 Alpha ## 开发目的 diff --git a/routers/admin/user.go b/routers/admin/user.go index 9f043507d1..fee692202e 100644 --- a/routers/admin/user.go +++ b/routers/admin/user.go @@ -16,14 +16,15 @@ import ( "github.com/gogits/gogs/modules/middleware" ) -func NewUser(ctx *middleware.Context, form auth.RegisterForm) { +func NewUser(ctx *middleware.Context) { ctx.Data["Title"] = "New Account" ctx.Data["PageIsUsers"] = true + ctx.HTML(200, "admin/users/new") +} - if ctx.Req.Method == "GET" { - ctx.HTML(200, "admin/users/new") - return - } +func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { + ctx.Data["Title"] = "New Account" + ctx.Data["PageIsUsers"] = true if form.Password != form.RetypePasswd { ctx.Data["HasError"] = true @@ -55,7 +56,7 @@ func NewUser(ctx *middleware.Context, form auth.RegisterForm) { case models.ErrUserNameIllegal: ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form) default: - ctx.Handle(200, "admin.user.NewUser", err) + ctx.Handle(500, "admin.user.NewUser", err) } return } @@ -66,25 +67,39 @@ func NewUser(ctx *middleware.Context, form auth.RegisterForm) { ctx.Redirect("/admin/users") } -func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEditUserForm) { +func EditUser(ctx *middleware.Context, params martini.Params) { 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) + ctx.Handle(404, "admin.user.EditUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { - ctx.Handle(200, "admin.user.EditUser", err) + ctx.Handle(500, "admin.user.EditUser", err) return } - if ctx.Req.Method == "GET" { - ctx.Data["User"] = u - ctx.HTML(200, "admin/users/edit") + ctx.Data["User"] = u + ctx.HTML(200, "admin/users/edit") +} + +func EditUserPost(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(404, "admin.user.EditUser", err) + return + } + + u, err := models.GetUserById(int64(uid)) + if err != nil { + ctx.Handle(500, "admin.user.EditUser", err) return } @@ -96,47 +111,44 @@ func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEdi u.IsActive = form.Active == "on" u.IsAdmin = form.Admin == "on" if err := models.UpdateUser(u); err != nil { - ctx.Handle(200, "admin.user.EditUser", err) + ctx.Handle(500, "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) + + ctx.Data["User"] = u + ctx.Flash.Success("Account profile has been successfully updated.") + ctx.Redirect("/admin/users/" + params["userid"]) } func DeleteUser(ctx *middleware.Context, params martini.Params) { - ctx.Data["Title"] = "Edit Account" + ctx.Data["Title"] = "Delete Account" ctx.Data["PageIsUsers"] = true + log.Info("delete") uid, err := base.StrTo(params["userid"]).Int() if err != nil { - ctx.Handle(200, "admin.user.EditUser", err) + ctx.Handle(404, "admin.user.EditUser", err) return } u, err := models.GetUserById(int64(uid)) if err != nil { - ctx.Handle(200, "admin.user.EditUser", err) + ctx.Handle(500, "admin.user.EditUser", err) return } if err = models.DeleteUser(u); err != nil { - ctx.Data["HasError"] = true switch err { case models.ErrUserOwnRepos: - ctx.Data["ErrorMsg"] = "This account still has ownership of repository, owner has to delete or transfer them first." - ctx.Data["User"] = u - ctx.HTML(200, "admin/users/edit") + ctx.Flash.Error("This account still has ownership of repository, owner has to delete or transfer them first.") + ctx.Redirect("/admin/users/" + params["userid"]) default: - ctx.Handle(200, "admin.user.DeleteUser", err) + ctx.Handle(500, "admin.user.DeleteUser", err) } return } - log.Trace("%s User deleted by admin(%s): %s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.User.LowerName) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 9688fd4d94..9ab07c0d59 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -82,15 +82,17 @@ func Issues(ctx *middleware.Context) { ctx.HTML(200, "issue/list") } -func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { +func CreateIssue(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Create issue" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false + ctx.HTML(200, "issue/create") +} - if ctx.Req.Method == "GET" { - ctx.HTML(200, "issue/create") - return - } +func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { + ctx.Data["Title"] = "Create issue" + ctx.Data["IsRepoToolbarIssues"] = true + ctx.Data["IsRepoToolbarIssuesList"] = false if ctx.HasError() { ctx.HTML(200, "issue/create") @@ -100,7 +102,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat issue, err := models.CreateIssue(ctx.User.Id, ctx.Repo.Repository.Id, form.MilestoneId, form.AssigneeId, ctx.Repo.Repository.NumIssues, form.IssueName, form.Labels, form.Content, false) if err != nil { - ctx.Handle(200, "issue.CreateIssue(CreateIssue)", err) + ctx.Handle(500, "issue.CreateIssue(CreateIssue)", err) return } @@ -108,7 +110,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, ActEmail: ctx.User.Email, OpType: models.OP_CREATE_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name), RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil { - ctx.Handle(200, "issue.CreateIssue(NotifyWatchers)", err) + ctx.Handle(500, "issue.CreateIssue(NotifyWatchers)", err) return } @@ -116,7 +118,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat if base.Service.NotifyMail { tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue) if err != nil { - ctx.Handle(200, "issue.CreateIssue(SendIssueNotifyMail)", err) + ctx.Handle(500, "issue.CreateIssue(SendIssueNotifyMail)", err) return } @@ -132,12 +134,12 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } if err = mailer.SendIssueMentionMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil { - ctx.Handle(200, "issue.CreateIssue(SendIssueMentionMail)", err) + ctx.Handle(500, "issue.CreateIssue(SendIssueMentionMail)", err) return } } - log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index d4d52ba0d7..b2897d0f51 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -21,16 +21,19 @@ import ( "github.com/gogits/gogs/modules/middleware" ) -func Create(ctx *middleware.Context, form auth.CreateRepoForm) { +func Create(ctx *middleware.Context) { ctx.Data["Title"] = "Create repository" - ctx.Data["PageIsNewRepo"] = true // For navbar arrow. + ctx.Data["PageIsNewRepo"] = true ctx.Data["LanguageIgns"] = models.LanguageIgns ctx.Data["Licenses"] = models.Licenses + ctx.HTML(200, "repo/create") +} - if ctx.Req.Method == "GET" { - ctx.HTML(200, "repo/create") - return - } +func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) { + ctx.Data["Title"] = "Create repository" + ctx.Data["PageIsNewRepo"] = true + ctx.Data["LanguageIgns"] = models.LanguageIgns + ctx.Data["Licenses"] = models.Licenses if ctx.HasError() { ctx.HTML(200, "repo/create") @@ -50,17 +53,18 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/create", &form) return } - ctx.Handle(200, "repo.Create", err) + ctx.Handle(500, "repo.Create", err) } -func Mirror(ctx *middleware.Context, form auth.CreateRepoForm) { +func Mirror(ctx *middleware.Context) { ctx.Data["Title"] = "Mirror repository" - ctx.Data["PageIsNewRepo"] = true // For navbar arrow. + ctx.Data["PageIsNewRepo"] = true + ctx.HTML(200, "repo/mirror") +} - if ctx.Req.Method == "GET" { - ctx.HTML(200, "repo/mirror") - return - } +func MirrorPost(ctx *middleware.Context, form auth.CreateRepoForm) { + ctx.Data["Title"] = "Mirror repository" + ctx.Data["PageIsNewRepo"] = true if ctx.HasError() { ctx.HTML(200, "repo/mirror") @@ -80,7 +84,7 @@ func Mirror(ctx *middleware.Context, form auth.CreateRepoForm) { ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/mirror", &form) return } - ctx.Handle(200, "repo.Mirror", err) + ctx.Handle(500, "repo.Mirror", err) } func Single(ctx *middleware.Context, params martini.Params) { diff --git a/routers/user/setting.go b/routers/user/setting.go index 03da04b9e3..7e66ad3599 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -69,38 +69,46 @@ func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.Redirect("/user/setting") } -func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { +func SettingPassword(ctx *middleware.Context) { + ctx.Data["Title"] = "Password" + ctx.Data["PageIsUserSetting"] = true + ctx.Data["IsUserPageSettingPasswd"] = true + ctx.HTML(200, "user/password") +} + +func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) { ctx.Data["Title"] = "Password" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingPasswd"] = true - if ctx.Req.Method == "GET" { + if ctx.HasError() { ctx.HTML(200, "user/password") return } user := ctx.User - newUser := &models.User{Passwd: form.NewPasswd} - newUser.EncodePasswd() - if user.Passwd != newUser.Passwd { - ctx.Data["HasError"] = true - ctx.Data["ErrorMsg"] = "Old password is not correct" + tmpUser := &models.User{ + Passwd: form.OldPasswd, + Salt: user.Salt, + } + tmpUser.EncodePasswd() + if user.Passwd != tmpUser.Passwd { + ctx.Flash.Error("Old password is not correct") } else if form.NewPasswd != form.RetypePasswd { - ctx.Data["HasError"] = true - ctx.Data["ErrorMsg"] = "New password and re-type password are not same" + ctx.Flash.Error("New password and re-type password are not same") } else { - newUser.Salt = models.GetUserSalt() - user.Passwd = newUser.Passwd + user.Passwd = form.NewPasswd + user.Salt = models.GetUserSalt() + user.EncodePasswd() if err := models.UpdateUser(user); err != nil { ctx.Handle(200, "setting.SettingPassword", err) return } - ctx.Data["IsSuccess"] = true + log.Trace("%s User password updated: %s", ctx.Req.RequestURI, ctx.User.LowerName) + ctx.Flash.Success("Password is changed successfully. You can now sign in via new password.") } - ctx.Data["Owner"] = user - ctx.HTML(200, "user/password") - log.Trace("%s User password updated: %s", ctx.Req.RequestURI, ctx.User.LowerName) + ctx.Redirect("/user/setting/password") } func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { diff --git a/templates/admin/users/edit.tmpl b/templates/admin/users/edit.tmpl index 5db2c7a95e..da9a67cfae 100644 --- a/templates/admin/users/edit.tmpl +++ b/templates/admin/users/edit.tmpl @@ -11,8 +11,8 @@