aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-13 04:06:35 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-13 04:06:35 -0400
commitc01f593daa994dddc208f853c1c116c56d2ea397 (patch)
treedf572e8608c00f2448e19c0b868a38f1f1a30a7a
parent76dae5bf680cd701b1ae9876ecc21486a8721f92 (diff)
Add updatePasswd
-rw-r--r--README.md3
-rw-r--r--modules/auth/user.go33
-rw-r--r--routers/user/setting.go33
-rw-r--r--web.go1
4 files changed, 69 insertions, 1 deletions
diff --git a/README.md b/README.md
index 05056e20..0e354a9d 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![wercker status](https://app.wercker.com/status/ad0bdb0b
Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language, it currently supports Linux and Max OS X, but Windows has **NOT** supported yet due to installation problem with [libgit2](http://libgit2.github.com/) in Windows.
-##### Current version: 0.0.6 Alpha
+##### Current version: 0.0.7 Alpha
## Purpose
@@ -18,6 +18,7 @@ Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, devel
- SSH protocal support.
- Register/delete account.
- Create/delete public repository.
+- User/repository home page.
- Git repository manipulation.
## Installation
diff --git a/modules/auth/user.go b/modules/auth/user.go
index e868fac2..6bc71306 100644
--- a/modules/auth/user.go
+++ b/modules/auth/user.go
@@ -128,3 +128,36 @@ func (f *UpdateProfileForm) Validate(errors *binding.Errors, req *http.Request,
validate(errors, data, f)
}
+
+type UpdatePasswdForm struct {
+ OldPasswd string `form:"oldpasswd" binding:"Required;MinSize(6);MaxSize(30)"`
+ NewPasswd string `form:"newpasswd" binding:"Required;MinSize(6);MaxSize(30)"`
+ RetypePasswd string `form:"retypepasswd"`
+}
+
+func (f *UpdatePasswdForm) Name(field string) string {
+ names := map[string]string{
+ "OldPasswd": "Old password",
+ "NewPasswd": "New password",
+ "RetypePasswd": "Re-type password",
+ }
+ return names[field]
+}
+
+func (f *UpdatePasswdForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
+ if req.Method == "GET" || errors.Count() == 0 {
+ return
+ }
+
+ data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
+ data["HasError"] = true
+
+ if len(errors.Overall) > 0 {
+ for _, err := range errors.Overall {
+ log.Error("UpdatePasswdForm.Validate: %v", err)
+ }
+ return
+ }
+
+ validate(errors, data, f)
+}
diff --git a/routers/user/setting.go b/routers/user/setting.go
index 5ec4c455..02a214b2 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -47,6 +47,39 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r
r.HTML(200, "user/setting", data)
}
+func UpdatePasswd(form auth.UpdatePasswdForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) {
+ data["Title"] = "Setting"
+ data["PageIsUserSetting"] = true
+
+ user := auth.SignedInUser(session)
+ newUser := &models.User{Passwd: form.OldPasswd}
+ if err := newUser.EncodePasswd(); err != nil {
+ data["ErrorMsg"] = err
+ log.Error("setting.UpdatePasswd: %v", err)
+ r.HTML(200, "base/error", data)
+ return
+ }
+
+ if user.Passwd != newUser.Passwd {
+ data["HasError"] = true
+ data["ErrorMsg"] = "Old password is not correct"
+ } else if form.NewPasswd != form.RetypePasswd {
+ data["HasError"] = true
+ data["ErrorMsg"] = "New password and re-type password are not same"
+ } else {
+ user.Passwd = newUser.Passwd
+ if err := models.UpdateUser(user); err != nil {
+ data["ErrorMsg"] = err
+ log.Error("setting.Setting: %v", err)
+ r.HTML(200, "base/error", data)
+ return
+ }
+ }
+
+ data["Owner"] = user
+ r.HTML(200, "user/setting", data)
+}
+
func SettingSSHKeys(form auth.AddSSHKeyForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) {
data["Title"] = "SSH Keys"
diff --git a/web.go b/web.go
index 856d0f10..a80c4924 100644
--- a/web.go
+++ b/web.go
@@ -64,6 +64,7 @@ func runWeb(*cli.Context) {
m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)
m.Any("/user/setting", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting)
+ m.Post("/user/setting/update_passwd", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdatePasswdForm{}), user.UpdatePasswd)
m.Any("/user/setting/ssh", auth.SignInRequire(true), binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys)
m.Get("/user/:username", auth.SignInRequire(false), user.Profile)