mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-30 21:26:17 +01:00
Finish update password and profile
This commit is contained in:
parent
495a52d78b
commit
47edf7f4f9
10 changed files with 72 additions and 33 deletions
2
gogs.go
2
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())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)"`
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<h4>Account Setting</h4>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item"><a href="/user/setting">Account Profile</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/email_password">Emails and Password</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/password">Password</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/notification">Notifications</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/ssh/">SSH Keys</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/security">Security</a></li>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<h4>Account Setting</h4>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item"><a href="/user/setting">Account Profile</a></li>
|
||||
<li class="list-group-item list-group-item-success"><a href="/user/setting/email_password">Emails and Password</a></li>
|
||||
<li class="list-group-item list-group-item-success"><a href="/user/setting/password">Password</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/notification">Notifications</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/ssh/">SSH Keys</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/security">Security</a></li>
|
||||
|
@ -13,37 +13,35 @@
|
|||
</ul>
|
||||
</div>
|
||||
<div id="gogs-user-setting-container" class="col-md-9">
|
||||
<div id="gogs-setting-email">
|
||||
<h4>Email</h4>
|
||||
<p><strong>Your Primary Email</strong> will be used for Account related notifications as well as any web based operations, such as edits and merges made via the web.</p>
|
||||
<p>// TODO</p><br/>
|
||||
</div>
|
||||
<div id="gogs-setting-pwd">
|
||||
<h4>Password</h4>
|
||||
<form class="form-horizontal" id="gogs-password-form" method="post" action="/user/setting/update_passwd">{{if .IsPwdSuccess}}
|
||||
<p class="alert alert-success">Password is changed successfully. You can sign in via new password.</p>{{end}}
|
||||
<form class="form-horizontal" id="gogs-password-form" method="post" action="/user/setting/password">{{if .IsSuccess}}
|
||||
<p class="alert alert-success">Password is changed successfully. You can now sign in via new password.</p>{{else if .HasError}}<p class="alert alert-danger form-error">{{.ErrorMsg}}</p>{{end}}
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">Old Password<strong class="text-danger">*</strong></label>
|
||||
<div class="col-md-8">
|
||||
<input type="password" name="oldpasswd" class="form-control" placeholder="Type your current password" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">New Password<strong class="text-danger">*</strong></label>
|
||||
<div class="col-md-8">
|
||||
<input type="password" name="newpasswd" class="form-control" placeholder="Type your new password" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">Re-Type<strong class="text-danger">*</strong></label>
|
||||
<div class="col-md-8">
|
||||
<input type="password" name="re-type" class="form-control" placeholder="Re-type your new password" required="required">
|
||||
<input type="password" name="retypepasswd" class="form-control" placeholder="Re-type your new password" required="required">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-8">
|
||||
<button type="submit" class="btn btn-primary">Change Password</button>
|
||||
<a href="/forget-password/">Forget Password ?</a>
|
||||
<a href="/forget-password/">Forgot your password?</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
|
@ -11,8 +11,8 @@
|
|||
<div class="profile-info">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item"><i class="fa fa-thumb-tack"></i>{{.Owner.Location}}</li>
|
||||
<li class="list-group-item"><i class="fa fa-envelope"></i><a href="#">{{.Owner.Email}}</a></li>
|
||||
<li class="list-group-item"><i class="fa fa-link"></i><a href="#">{{.Owner.Website}}</a></li>
|
||||
<li class="list-group-item"><i class="fa fa-envelope"></i><a href="mailto:{{.Owner.Email}}">{{.Owner.Email}}</a></li>
|
||||
<li class="list-group-item"><i class="fa fa-link"></i><a target="_blank" href="{{.Owner.Website}}">{{.Owner.Website}}</a></li>
|
||||
<li class="list-group-item"><i class="fa fa-clock-o"></i>{{.Owner.Created}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<h4>Account Setting</h4>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item"><a href="/user/setting">Account Profile</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/email_password">Emails and Password</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/Password">Password</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/notification">Notifications</a></li>
|
||||
<li class="list-group-item list-group-item-success"><a href="/user/setting/ssh/">SSH Keys</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/security">Security</a></li>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<h4>Account Setting</h4>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item list-group-item-success"><a href="/user/setting">Account Profile</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/email_password">Emails and Password</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/password">Password</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/notification">Notifications</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/ssh/">SSH Keys</a></li>
|
||||
<li class="list-group-item"><a href="/user/setting/security">Security</a></li>
|
||||
|
@ -13,7 +13,46 @@
|
|||
</ul>
|
||||
</div>
|
||||
<div id="gogs-user-setting-container" class="col-md-9">
|
||||
setting container
|
||||
<div id="gogs-setting-pwd">
|
||||
<h4>Account Profile</h4>
|
||||
<form class="form-horizontal" id="gogs-password-form" method="post" action="/user/setting">{{if .IsSuccess}}
|
||||
<p class="alert alert-success">Your profile has been successfully updated.</p>{{else if .HasError}}<p class="alert alert-danger form-error">{{.ErrorMsg}}</p>{{end}}
|
||||
<p>Your Email will be public and used for Account related notifications and any web based operations made via the web.</p>
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">Email</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" name="email" class="form-control" placeholder="Type your e-mail address" value="{{.Owner.Email}}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">Website</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" name="website" class="form-control" placeholder="Type your website URL" value="{{.Owner.Website}}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">Location</label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" name="location" class="form-control" placeholder="Type your current location" value="{{.Owner.Location}}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">Gravatar Email<strong class="text-danger">*</strong></label>
|
||||
<div class="col-md-8">
|
||||
<input type="text" name="avatar" class="form-control" placeholder="Type your Gravatar e-mail address" required="required" value="{{.Owner.AvatarEmail}}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-8">
|
||||
<button type="submit" class="btn btn-primary">Update Profile</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
3
web.go
3
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)
|
||||
|
|
Loading…
Reference in a new issue