Browse Source

Add updatePasswd

tags/v0.9.99
Unknown 10 years ago
parent
commit
c01f593daa
4 changed files with 69 additions and 1 deletions
  1. 2
    1
      README.md
  2. 33
    0
      modules/auth/user.go
  3. 33
    0
      routers/user/setting.go
  4. 1
    0
      web.go

+ 2
- 1
README.md View File



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. 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 ## Purpose


- SSH protocal support. - SSH protocal support.
- Register/delete account. - Register/delete account.
- Create/delete public repository. - Create/delete public repository.
- User/repository home page.
- Git repository manipulation. - Git repository manipulation.


## Installation ## Installation

+ 33
- 0
modules/auth/user.go View File



validate(errors, data, f) 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)
}

+ 33
- 0
routers/user/setting.go View File

r.HTML(200, "user/setting", data) 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) { func SettingSSHKeys(form auth.AddSSHKeyForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) {
data["Title"] = "SSH Keys" data["Title"] = "SSH Keys"



+ 1
- 0
web.go View File

m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)


m.Any("/user/setting", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) 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.Any("/user/setting/ssh", auth.SignInRequire(true), binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys)


m.Get("/user/:username", auth.SignInRequire(false), user.Profile) m.Get("/user/:username", auth.SignInRequire(false), user.Profile)

Loading…
Cancel
Save