0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-21 23:51:32 +01:00

Add updatePasswd

This commit is contained in:
Unknown 2014-03-13 04:06:35 -04:00
parent 76dae5bf68
commit c01f593daa
4 changed files with 69 additions and 1 deletions

View file

@ -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

View file

@ -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)
}

View file

@ -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"

1
web.go
View file

@ -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)