From 57bc2d1ca0bfc3ba90e6d85309dba39415c6db73 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 13 Mar 2014 03:39:18 -0400 Subject: Add update user profile back end, add new gitignore and license, add template data to public profile page --- modules/auth/auth.go | 5 ----- modules/auth/user.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) (limited to 'modules/auth') diff --git a/modules/auth/auth.go b/modules/auth/auth.go index e4748650..b0855275 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -90,11 +90,6 @@ func (f *LogInForm) Validate(errors *binding.Errors, req *http.Request, context validate(errors, data, f) } -type FeedsForm struct { - UserId int64 `form:"userid" binding:"Required"` - Offset int64 `form:"offset"` -} - func getMinMaxSize(field reflect.StructField) string { for _, rule := range strings.Split(field.Tag.Get("binding"), ";") { if strings.HasPrefix(rule, "MinSize(") || strings.HasPrefix(rule, "MaxSize(") { diff --git a/modules/auth/user.go b/modules/auth/user.go index 4059edfd..e868fac2 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -5,10 +5,15 @@ package auth import ( + "net/http" + "reflect" + "github.com/codegangsta/martini" "github.com/martini-contrib/render" "github.com/martini-contrib/sessions" + "github.com/gogits/binding" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" @@ -83,3 +88,43 @@ func SignOutRequire() martini.Handler { } } } + +type FeedsForm struct { + UserId int64 `form:"userid" binding:"Required"` + Offset int64 `form:"offset"` +} + +type UpdateProfileForm struct { + Email string `form:"email" binding:"Required;Email;MaxSize(50)"` + Website string `form:"website" binding:"AlphaDash;MaxSize(50)"` + Location string `form:"location" binding:"MaxSize(50)"` + Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"` +} + +func (f *UpdateProfileForm) Name(field string) string { + names := map[string]string{ + "Email": "Email address", + "Website": "Website", + "Location": "Location", + "Avatar": "Gravatar Email", + } + return names[field] +} + +func (f *UpdateProfileForm) 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("UpdateProfileForm.Validate: %v", err) + } + return + } + + validate(errors, data, f) +} -- cgit v1.2.3 From c01f593daa994dddc208f853c1c116c56d2ea397 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 13 Mar 2014 04:06:35 -0400 Subject: Add updatePasswd --- README.md | 3 ++- modules/auth/user.go | 33 +++++++++++++++++++++++++++++++++ routers/user/setting.go | 33 +++++++++++++++++++++++++++++++++ web.go | 1 + 4 files changed, 69 insertions(+), 1 deletion(-) (limited to 'modules/auth') 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) -- cgit v1.2.3 From 52de63e7bbd500a90a1a8cb62cdb490b0ba623c7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 13 Mar 2014 16:21:16 -0400 Subject: Allow 1 letter usernames --- modules/auth/auth.go | 4 ++-- public/js/app.js | 1 - templates/user/signup.tmpl | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'modules/auth') diff --git a/modules/auth/auth.go b/modules/auth/auth.go index b0855275..0e871688 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -23,7 +23,7 @@ type Form interface { } type RegisterForm struct { - UserName string `form:"username" binding:"Required;AlphaDash;MinSize(5);MaxSize(30)"` + UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"` Email string `form:"email" binding:"Required;Email;MaxSize(50)"` Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"` RetypePasswd string `form:"retypepasswd"` @@ -59,7 +59,7 @@ func (f *RegisterForm) Validate(errors *binding.Errors, req *http.Request, conte } type LogInForm struct { - UserName string `form:"username" binding:"Required;AlphaDash;MinSize(5);MaxSize(30)"` + UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"` Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"` } diff --git a/public/js/app.js b/public/js/app.js index 69d21020..0f0ecc43 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -78,7 +78,6 @@ function initRegister() { rules: { "username": { required: true, - minlength: 5, maxlength: 30 }, "email": { diff --git a/templates/user/signup.tmpl b/templates/user/signup.tmpl index ba41b0c9..2f1e82c7 100644 --- a/templates/user/signup.tmpl +++ b/templates/user/signup.tmpl @@ -7,7 +7,7 @@
- +
-- cgit v1.2.3 From 47edf7f4f9d359765764207cbcb6dd82dba36de8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 14 Mar 2014 01:12:07 -0400 Subject: Finish update password and profile --- gogs.go | 2 +- models/user.go | 2 ++ modules/auth/user.go | 2 +- routers/user/setting.go | 27 +++++++++---------- templates/user/delete.tmpl | 2 +- templates/user/email_password.tmpl | 53 -------------------------------------- templates/user/password.tmpl | 51 ++++++++++++++++++++++++++++++++++++ templates/user/profile.tmpl | 4 +-- templates/user/publickey.tmpl | 2 +- templates/user/setting.tmpl | 43 +++++++++++++++++++++++++++++-- web.go | 3 +-- 11 files changed, 115 insertions(+), 76 deletions(-) delete mode 100644 templates/user/email_password.tmpl create mode 100644 templates/user/password.tmpl (limited to 'modules/auth') diff --git a/gogs.go b/gogs.go index 96c0f84f..b2764902 100644 --- a/gogs.go +++ b/gogs.go @@ -20,7 +20,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.0.7.0313" +const APP_VER = "0.0.7.0314" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/user.go b/models/user.go index 06db7d8b..8f7a37cb 100644 --- a/models/user.go +++ b/models/user.go @@ -49,6 +49,7 @@ type User struct { NumStars int NumRepos int Avatar string `xorm:"varchar(2048) not null"` + AvatarEmail string `xorm:"not null"` Location string Website string Created time.Time `xorm:"created"` @@ -106,6 +107,7 @@ func RegisterUser(user *User) (err error) { user.LowerName = strings.ToLower(user.Name) user.Avatar = base.EncodeMd5(user.Email) + user.AvatarEmail = user.Email if err = user.EncodePasswd(); err != nil { return err } diff --git a/modules/auth/user.go b/modules/auth/user.go index 6bc71306..ef595c60 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -96,7 +96,7 @@ type FeedsForm struct { type UpdateProfileForm struct { Email string `form:"email" binding:"Required;Email;MaxSize(50)"` - Website string `form:"website" binding:"AlphaDash;MaxSize(50)"` + Website string `form:"website" binding:"MaxSize(50)"` Location string `form:"location" binding:"MaxSize(50)"` Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"` } diff --git a/routers/user/setting.go b/routers/user/setting.go index cf11095b..08879ae4 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -22,8 +22,9 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r data["PageIsUserSetting"] = true user := auth.SignedInUser(session) + data["Owner"] = user + if req.Method == "GET" { - data["Owner"] = user r.HTML(200, "user/setting", data) return } @@ -37,6 +38,7 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r user.Website = form.Website user.Location = form.Location user.Avatar = base.EncodeMd5(form.Avatar) + user.AvatarEmail = form.Avatar if err := models.UpdateUser(user); err != nil { data["ErrorMsg"] = err log.Error("setting.Setting: %v", err) @@ -44,23 +46,21 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r return } + data["IsSuccess"] = true r.HTML(200, "user/setting", data) } -func SettingEmailPassword(r render.Render, data base.TmplData, session sessions.Session, req *http.Request) { - data["Title"] = "Email & Password" +func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.TmplData, session sessions.Session, req *http.Request) { + data["Title"] = "Password" data["PageIsUserSetting"] = true - data["IsPwdSuccess"] = (req.FormValue("password") == "true") - r.HTML(200, "user/email_password", data) -} - -func UpdatePasswd(form auth.UpdatePasswdForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { - data["Title"] = "Setting" - data["PageIsUserSetting"] = true + if req.Method == "GET" { + r.HTML(200, "user/password", data) + return + } user := auth.SignedInUser(session) - newUser := &models.User{Passwd: form.OldPasswd} + newUser := &models.User{Passwd: form.NewPasswd} if err := newUser.EncodePasswd(); err != nil { data["ErrorMsg"] = err log.Error("setting.UpdatePasswd: %v", err) @@ -78,14 +78,15 @@ func UpdatePasswd(form auth.UpdatePasswdForm, r render.Render, data base.TmplDat user.Passwd = newUser.Passwd if err := models.UpdateUser(user); err != nil { data["ErrorMsg"] = err - log.Error("setting.Setting: %v", err) + log.Error("setting.UpdatePasswd: %v", err) r.HTML(200, "base/error", data) return } + data["IsSuccess"] = true } data["Owner"] = user - r.HTML(200, "user/setting", data) + r.HTML(200, "user/password", data) } func SettingSSHKeys(form auth.AddSSHKeyForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { diff --git a/templates/user/delete.tmpl b/templates/user/delete.tmpl index 37259f61..90420177 100644 --- a/templates/user/delete.tmpl +++ b/templates/user/delete.tmpl @@ -5,7 +5,7 @@

Account Setting

  • Account Profile
  • -
  • Emails and Password
  • +
  • Password
  • Notifications
  • SSH Keys
  • Security
  • diff --git a/templates/user/email_password.tmpl b/templates/user/email_password.tmpl deleted file mode 100644 index 364bcf39..00000000 --- a/templates/user/email_password.tmpl +++ /dev/null @@ -1,53 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -
    - -
    -
    -

    Email

    -

    Your Primary Email will be used for Account related notifications as well as any web based operations, such as edits and merges made via the web.

    -

    // TODO


    -
    -
    -

    Password

    -
    {{if .IsPwdSuccess}} -

    Password is changed successfully. You can sign in via new password.

    {{end}} -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    - -
    - -
    -
    -
    -
    -    - Forget Password ? -
    -
    -
    -
    -
    -
    -{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/user/password.tmpl b/templates/user/password.tmpl new file mode 100644 index 00000000..a8b1e21e --- /dev/null +++ b/templates/user/password.tmpl @@ -0,0 +1,51 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
    + +
    +
    +

    Password

    +
    {{if .IsSuccess}} +

    Password is changed successfully. You can now sign in via new password.

    {{else if .HasError}}

    {{.ErrorMsg}}

    {{end}} +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    +
    +    + Forgot your password? +
    +
    +
    +
    +
    +
    +{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 94ec33b6..c10bfcb0 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -11,8 +11,8 @@
    diff --git a/templates/user/publickey.tmpl b/templates/user/publickey.tmpl index 195af758..60d2c246 100644 --- a/templates/user/publickey.tmpl +++ b/templates/user/publickey.tmpl @@ -5,7 +5,7 @@

    Account Setting

    • Account Profile
    • -
    • Emails and Password
    • +
    • Password
    • Notifications
    • SSH Keys
    • Security
    • diff --git a/templates/user/setting.tmpl b/templates/user/setting.tmpl index 380ac88a..edbeeb22 100644 --- a/templates/user/setting.tmpl +++ b/templates/user/setting.tmpl @@ -5,7 +5,7 @@

      Account Setting

      - setting container +
      +

      Account Profile

      +
      {{if .IsSuccess}} +

      Your profile has been successfully updated.

      {{else if .HasError}}

      {{.ErrorMsg}}

      {{end}} +

      Your Email will be public and used for Account related notifications and any web based operations made via the web.

      +
      + +
      + +
      +
      + +
      + +
      + +
      +
      + +
      + +
      + +
      +
      + +
      + +
      + +
      +
      + +
      +
      + +
      +
      +
      +
      {{template "base/footer" .}} \ No newline at end of file diff --git a/web.go b/web.go index 47128617..1fa19afc 100644 --- a/web.go +++ b/web.go @@ -64,8 +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.Get("/user/setting/email_password",auth.SignInRequire(true),user.SettingEmailPassword) - m.Post("/user/setting/update_passwd", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdatePasswdForm{}), user.UpdatePasswd) + m.Any("/user/setting/password", auth.SignInRequire(true), binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) m.Any("/user/setting/ssh", auth.SignInRequire(true), binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) m.Get("/user/:username", auth.SignInRequire(false), user.Profile) -- cgit v1.2.3