|
|
@ -5,12 +5,8 @@ |
|
|
|
package user |
|
|
|
package user |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
|
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/martini-contrib/render" |
|
|
|
|
|
|
|
"github.com/martini-contrib/sessions" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
|
"github.com/gogits/gogs/modules/base" |
|
|
|
"github.com/gogits/gogs/modules/base" |
|
|
@ -18,20 +14,20 @@ import ( |
|
|
|
"github.com/gogits/gogs/modules/middleware" |
|
|
|
"github.com/gogits/gogs/modules/middleware" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func Setting(form auth.UpdateProfileForm, ctx *middleware.Context, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { |
|
|
|
func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { |
|
|
|
data["Title"] = "Setting" |
|
|
|
ctx.Data["Title"] = "Setting" |
|
|
|
data["PageIsUserSetting"] = true |
|
|
|
ctx.Data["PageIsUserSetting"] = true |
|
|
|
|
|
|
|
|
|
|
|
user := auth.SignedInUser(session) |
|
|
|
user := ctx.User |
|
|
|
data["Owner"] = user |
|
|
|
ctx.Data["Owner"] = user |
|
|
|
|
|
|
|
|
|
|
|
if req.Method == "GET" { |
|
|
|
if ctx.Req.Method == "GET" { |
|
|
|
r.HTML(200, "user/setting", data) |
|
|
|
ctx.Render.HTML(200, "user/setting", ctx.Data) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if hasErr, ok := data["HasError"]; ok && hasErr.(bool) { |
|
|
|
if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { |
|
|
|
r.HTML(200, "user/setting", data) |
|
|
|
ctx.Render.HTML(200, "user/setting", ctx.Data) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -45,20 +41,20 @@ func Setting(form auth.UpdateProfileForm, ctx *middleware.Context, r render.Rend |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data["IsSuccess"] = true |
|
|
|
ctx.Data["IsSuccess"] = true |
|
|
|
r.HTML(200, "user/setting", data) |
|
|
|
ctx.Render.HTML(200, "user/setting", ctx.Data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SettingPassword(form auth.UpdatePasswdForm, ctx *middleware.Context, r render.Render, data base.TmplData, session sessions.Session, req *http.Request) { |
|
|
|
func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { |
|
|
|
data["Title"] = "Password" |
|
|
|
ctx.Data["Title"] = "Password" |
|
|
|
data["PageIsUserSetting"] = true |
|
|
|
ctx.Data["PageIsUserSetting"] = true |
|
|
|
|
|
|
|
|
|
|
|
if req.Method == "GET" { |
|
|
|
if ctx.Req.Method == "GET" { |
|
|
|
r.HTML(200, "user/password", data) |
|
|
|
ctx.Render.HTML(200, "user/password", ctx.Data) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
user := auth.SignedInUser(session) |
|
|
|
user := ctx.User |
|
|
|
newUser := &models.User{Passwd: form.NewPasswd} |
|
|
|
newUser := &models.User{Passwd: form.NewPasswd} |
|
|
|
if err := newUser.EncodePasswd(); err != nil { |
|
|
|
if err := newUser.EncodePasswd(); err != nil { |
|
|
|
ctx.Handle(200, "setting.SettingPassword", err) |
|
|
|
ctx.Handle(200, "setting.SettingPassword", err) |
|
|
@ -66,35 +62,34 @@ func SettingPassword(form auth.UpdatePasswdForm, ctx *middleware.Context, r rend |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if user.Passwd != newUser.Passwd { |
|
|
|
if user.Passwd != newUser.Passwd { |
|
|
|
data["HasError"] = true |
|
|
|
ctx.Data["HasError"] = true |
|
|
|
data["ErrorMsg"] = "Old password is not correct" |
|
|
|
ctx.Data["ErrorMsg"] = "Old password is not correct" |
|
|
|
} else if form.NewPasswd != form.RetypePasswd { |
|
|
|
} else if form.NewPasswd != form.RetypePasswd { |
|
|
|
data["HasError"] = true |
|
|
|
ctx.Data["HasError"] = true |
|
|
|
data["ErrorMsg"] = "New password and re-type password are not same" |
|
|
|
ctx.Data["ErrorMsg"] = "New password and re-type password are not same" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
user.Passwd = newUser.Passwd |
|
|
|
user.Passwd = newUser.Passwd |
|
|
|
if err := models.UpdateUser(user); err != nil { |
|
|
|
if err := models.UpdateUser(user); err != nil { |
|
|
|
ctx.Handle(200, "setting.SettingPassword", err) |
|
|
|
ctx.Handle(200, "setting.SettingPassword", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
data["IsSuccess"] = true |
|
|
|
ctx.Data["IsSuccess"] = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data["Owner"] = user |
|
|
|
ctx.Data["Owner"] = user |
|
|
|
r.HTML(200, "user/password", data) |
|
|
|
ctx.Render.HTML(200, "user/password", ctx.Data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SettingSSHKeys(form auth.AddSSHKeyForm, r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { |
|
|
|
func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { |
|
|
|
data["Title"] = "SSH Keys" |
|
|
|
ctx.Data["Title"] = "SSH Keys" |
|
|
|
|
|
|
|
|
|
|
|
// Delete SSH key.
|
|
|
|
// Delete SSH key.
|
|
|
|
if req.Method == "DELETE" || req.FormValue("_method") == "DELETE" { |
|
|
|
if ctx.Req.Method == "DELETE" || ctx.Query("_method") == "DELETE" { |
|
|
|
println(1) |
|
|
|
id, err := strconv.ParseInt(ctx.Query("id"), 10, 64) |
|
|
|
id, err := strconv.ParseInt(req.FormValue("id"), 10, 64) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
data["ErrorMsg"] = err |
|
|
|
ctx.Data["ErrorMsg"] = err |
|
|
|
log.Error("ssh.DelPublicKey: %v", err) |
|
|
|
log.Error("ssh.DelPublicKey: %v", err) |
|
|
|
r.JSON(200, map[string]interface{}{ |
|
|
|
ctx.Render.JSON(200, map[string]interface{}{ |
|
|
|
"ok": false, |
|
|
|
"ok": false, |
|
|
|
"err": err.Error(), |
|
|
|
"err": err.Error(), |
|
|
|
}) |
|
|
|
}) |
|
|
@ -102,18 +97,18 @@ func SettingSSHKeys(form auth.AddSSHKeyForm, r render.Render, data base.TmplData |
|
|
|
} |
|
|
|
} |
|
|
|
k := &models.PublicKey{ |
|
|
|
k := &models.PublicKey{ |
|
|
|
Id: id, |
|
|
|
Id: id, |
|
|
|
OwnerId: auth.SignedInId(session), |
|
|
|
OwnerId: ctx.User.Id, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = models.DeletePublicKey(k); err != nil { |
|
|
|
if err = models.DeletePublicKey(k); err != nil { |
|
|
|
data["ErrorMsg"] = err |
|
|
|
ctx.Data["ErrorMsg"] = err |
|
|
|
log.Error("ssh.DelPublicKey: %v", err) |
|
|
|
log.Error("ssh.DelPublicKey: %v", err) |
|
|
|
r.JSON(200, map[string]interface{}{ |
|
|
|
ctx.Render.JSON(200, map[string]interface{}{ |
|
|
|
"ok": false, |
|
|
|
"ok": false, |
|
|
|
"err": err.Error(), |
|
|
|
"err": err.Error(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
r.JSON(200, map[string]interface{}{ |
|
|
|
ctx.Render.JSON(200, map[string]interface{}{ |
|
|
|
"ok": true, |
|
|
|
"ok": true, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -121,51 +116,51 @@ func SettingSSHKeys(form auth.AddSSHKeyForm, r render.Render, data base.TmplData |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add new SSH key.
|
|
|
|
// Add new SSH key.
|
|
|
|
if req.Method == "POST" { |
|
|
|
if ctx.Req.Method == "POST" { |
|
|
|
if hasErr, ok := data["HasError"]; ok && hasErr.(bool) { |
|
|
|
if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { |
|
|
|
r.HTML(200, "user/publickey", data) |
|
|
|
ctx.Render.HTML(200, "user/publickey", ctx.Data) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
k := &models.PublicKey{OwnerId: auth.SignedInId(session), |
|
|
|
k := &models.PublicKey{OwnerId: ctx.User.Id, |
|
|
|
Name: form.KeyName, |
|
|
|
Name: form.KeyName, |
|
|
|
Content: form.KeyContent, |
|
|
|
Content: form.KeyContent, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := models.AddPublicKey(k); err != nil { |
|
|
|
if err := models.AddPublicKey(k); err != nil { |
|
|
|
data["ErrorMsg"] = err |
|
|
|
ctx.Data["ErrorMsg"] = err |
|
|
|
log.Error("ssh.AddPublicKey: %v", err) |
|
|
|
log.Error("ssh.AddPublicKey: %v", err) |
|
|
|
r.HTML(200, "base/error", data) |
|
|
|
ctx.Render.HTML(200, "base/error", ctx.Data) |
|
|
|
return |
|
|
|
return |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
data["AddSSHKeySuccess"] = true |
|
|
|
ctx.Data["AddSSHKeySuccess"] = true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// List existed SSH keys.
|
|
|
|
// List existed SSH keys.
|
|
|
|
keys, err := models.ListPublicKey(auth.SignedInId(session)) |
|
|
|
keys, err := models.ListPublicKey(ctx.User.Id) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
data["ErrorMsg"] = err |
|
|
|
ctx.Data["ErrorMsg"] = err |
|
|
|
log.Error("ssh.ListPublicKey: %v", err) |
|
|
|
log.Error("ssh.ListPublicKey: %v", err) |
|
|
|
r.HTML(200, "base/error", data) |
|
|
|
ctx.Render.HTML(200, "base/error", ctx.Data) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data["PageIsUserSetting"] = true |
|
|
|
ctx.Data["PageIsUserSetting"] = true |
|
|
|
data["Keys"] = keys |
|
|
|
ctx.Data["Keys"] = keys |
|
|
|
r.HTML(200, "user/publickey", data) |
|
|
|
ctx.Render.HTML(200, "user/publickey", ctx.Data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SettingNotification(r render.Render, data base.TmplData) { |
|
|
|
func SettingNotification(ctx *middleware.Context) { |
|
|
|
// todo user setting notification
|
|
|
|
// todo user setting notification
|
|
|
|
data["Title"] = "Notification" |
|
|
|
ctx.Data["Title"] = "Notification" |
|
|
|
data["PageIsUserSetting"] = true |
|
|
|
ctx.Data["PageIsUserSetting"] = true |
|
|
|
r.HTML(200, "user/notification", data) |
|
|
|
ctx.Render.HTML(200, "user/notification", ctx.Data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SettingSecurity(r render.Render, data base.TmplData) { |
|
|
|
func SettingSecurity(ctx *middleware.Context) { |
|
|
|
// todo user setting security
|
|
|
|
// todo user setting security
|
|
|
|
data["Title"] = "Security" |
|
|
|
ctx.Data["Title"] = "Security" |
|
|
|
data["PageIsUserSetting"] = true |
|
|
|
ctx.Data["PageIsUserSetting"] = true |
|
|
|
r.HTML(200, "user/security", data) |
|
|
|
ctx.Render.HTML(200, "user/security", ctx.Data) |
|
|
|
} |
|
|
|
} |
|
|
|