summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-05 16:21:43 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-05 16:21:43 -0400
commitbbdfe2576966210cfffc830bfbe3731bcf653b3b (patch)
treebc0fc83c71887270c4f38d53be8383985ffd01c5 /routers
parentc1eb4d894a092aed1b87ddf5f80ee824fd56789d (diff)
downloadgitea-bbdfe2576966210cfffc830bfbe3731bcf653b3b.tar.gz
gitea-bbdfe2576966210cfffc830bfbe3731bcf653b3b.zip
User code clean and ui improve
Diffstat (limited to 'routers')
-rw-r--r--routers/user/setting.go54
-rw-r--r--routers/user/user.go21
2 files changed, 46 insertions, 29 deletions
diff --git a/routers/user/setting.go b/routers/user/setting.go
index f62e931051..8b8895a3b7 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -5,7 +5,7 @@
package user
import (
- "strconv"
+ "strings"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
@@ -22,11 +22,10 @@ func Setting(ctx *middleware.Context) {
ctx.HTML(200, "user/setting")
}
-// Render user setting page (email, website modify)
func SettingPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
ctx.Data["Title"] = "Setting"
- ctx.Data["PageIsUserSetting"] = true // For navbar arrow.
- ctx.Data["IsUserPageSetting"] = true // For setting nav highlight.
+ ctx.Data["PageIsUserSetting"] = true
+ ctx.Data["IsUserPageSetting"] = true
user := ctx.User
ctx.Data["Owner"] = user
@@ -74,9 +73,22 @@ func SettingSocial(ctx *middleware.Context) {
ctx.Data["Title"] = "Social Account"
ctx.Data["PageIsUserSetting"] = true
ctx.Data["IsUserPageSettingSocial"] = true
+
+ // Unbind social account.
+ remove, _ := base.StrTo(ctx.Query("remove")).Int64()
+ if remove > 0 {
+ if err := models.DeleteOauth2ById(remove); err != nil {
+ ctx.Handle(500, "user.SettingSocial(DeleteOauth2ById)", err)
+ return
+ }
+ ctx.Flash.Success("OAuth2 has been unbinded.")
+ ctx.Redirect("/user/settings/social")
+ return
+ }
+
socials, err := models.GetOauthByUserId(ctx.User.Id)
if err != nil {
- ctx.Handle(500, "user.SettingSocial", err)
+ ctx.Handle(500, "user.SettingSocial(GetOauthByUserId)", err)
return
}
@@ -108,9 +120,9 @@ func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) {
}
tmpUser.EncodePasswd()
if user.Passwd != tmpUser.Passwd {
- ctx.Flash.Error("Old password is not correct")
+ ctx.Flash.Error("Old password is not correct.")
} else if form.NewPasswd != form.RetypePasswd {
- ctx.Flash.Error("New password and re-type password are not same")
+ ctx.Flash.Error("New password and re-type password are not same.")
} else {
user.Passwd = form.NewPasswd
user.Salt = models.GetUserSalt()
@@ -128,10 +140,12 @@ func SettingPasswordPost(ctx *middleware.Context, form auth.UpdatePasswdForm) {
func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
ctx.Data["Title"] = "SSH Keys"
+ ctx.Data["PageIsUserSetting"] = true
+ ctx.Data["IsUserPageSettingSSH"] = true
// Delete SSH key.
if ctx.Req.Method == "DELETE" || ctx.Query("_method") == "DELETE" {
- id, err := strconv.ParseInt(ctx.Query("id"), 10, 64)
+ id, err := base.StrTo(ctx.Query("id")).Int64()
if err != nil {
log.Error("ssh.DelPublicKey: %v", err)
ctx.JSON(200, map[string]interface{}{
@@ -160,6 +174,14 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
return
}
+ // List existed SSH keys.
+ keys, err := models.ListPublicKey(ctx.User.Id)
+ if err != nil {
+ ctx.Handle(500, "ssh.ListPublicKey", err)
+ return
+ }
+ ctx.Data["Keys"] = keys
+
// Add new SSH key.
if ctx.Req.Method == "POST" {
if ctx.HasError() {
@@ -167,6 +189,12 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
return
}
+ if len(form.KeyContent) < 100 || !strings.HasPrefix(form.KeyContent, "ssh-rsa") {
+ ctx.Flash.Error("SSH key content is not valid.")
+ ctx.Redirect("/user/settings/ssh")
+ return
+ }
+
k := &models.PublicKey{
OwnerId: ctx.User.Id,
Name: form.KeyName,
@@ -188,16 +216,6 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
}
}
- // List existed SSH keys.
- keys, err := models.ListPublicKey(ctx.User.Id)
- if err != nil {
- ctx.Handle(200, "ssh.ListPublicKey", err)
- return
- }
-
- ctx.Data["PageIsUserSetting"] = true
- ctx.Data["IsUserPageSettingSSH"] = true
- ctx.Data["Keys"] = keys
ctx.HTML(200, "user/publickey")
}
diff --git a/routers/user/user.go b/routers/user/user.go
index 9cce4e719d..7af65fc585 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -49,14 +49,14 @@ func SignIn(ctx *middleware.Context) {
user, err := models.GetUserByName(userName)
if err != nil {
- ctx.HTML(500, "user/signin")
+ ctx.Handle(500, "user.SignIn(GetUserByName)", err)
return
}
secret := base.EncodeMd5(user.Rands + user.Passwd)
value, _ := ctx.GetSecureCookie(secret, base.CookieRememberName)
if value != user.Name {
- ctx.HTML(500, "user/signin")
+ ctx.HTML(200, "user/signin")
return
}
@@ -85,6 +85,7 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) {
}
if ctx.HasError() {
+ println("shit")
ctx.HTML(200, "user/signin")
return
}
@@ -112,7 +113,7 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) {
return
}
- if form.Remember == "on" {
+ if form.Remember {
secret := base.EncodeMd5(user.Rands + user.Passwd)
days := 86400 * base.LogInRememberDays
ctx.SetCookie(base.CookieUserName, user.Name, days)
@@ -208,16 +209,15 @@ func SignUpPost(ctx *middleware.Context, form auth.RegisterForm) {
ctx.Data["IsSocialLogin"] = true
}
+ if ctx.HasError() {
+ ctx.HTML(200, "user/signup")
+ return
+ }
+
if form.Password != form.RetypePasswd {
- ctx.Data["HasError"] = true
ctx.Data["Err_Password"] = true
ctx.Data["Err_RetypePasswd"] = true
- ctx.Data["ErrorMsg"] = "Password and re-type password are not same"
- auth.AssignForm(form, ctx.Data)
- }
-
- if ctx.HasError() {
- ctx.HTML(200, "user/signup")
+ ctx.RenderWithErr("Password and re-type password are not same", "user/signup", &form)
return
}
@@ -415,7 +415,6 @@ func ResetPasswd(ctx *middleware.Context) {
return
}
ctx.Data["Code"] = code
-
ctx.Data["IsResetForm"] = true
ctx.HTML(200, "user/reset_passwd")
}