diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-08-12 22:18:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-12 22:18:44 +0800 |
commit | f960e19c590d27fe62a3a6241f1ea8b7fadde13a (patch) | |
tree | cb5045491959550fad930e82434a7f6e27d33cf3 /routers | |
parent | 921d90fd8b929533e30c896923cb3a6f3d33f45a (diff) | |
download | gitea-f960e19c590d27fe62a3a6241f1ea8b7fadde13a.tar.gz gitea-f960e19c590d27fe62a3a6241f1ea8b7fadde13a.zip |
Only update needed columns when update user (#2296)
* only update needed columns when update user
* fix missing update_unix column
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/org/org.go | 2 | ||||
-rw-r--r-- | routers/user/auth.go | 18 | ||||
-rw-r--r-- | routers/user/auth_openid.go | 3 | ||||
-rw-r--r-- | routers/user/setting.go | 4 |
4 files changed, 15 insertions, 12 deletions
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index e4a36b95c0..ec55b9ebe4 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -56,7 +56,7 @@ func Edit(ctx *context.APIContext, form api.EditOrgOption) { org.Description = form.Description org.Website = form.Website org.Location = form.Location - if err := models.UpdateUser(org); err != nil { + if err := models.UpdateUserCols(org, "full_name", "description", "website", "location"); err != nil { ctx.Error(500, "UpdateUser", err) return } diff --git a/routers/user/auth.go b/routers/user/auth.go index f1aa9d26a8..b2caba0bb1 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -340,8 +340,8 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR // Register last login u.SetLastLogin() - if err := models.UpdateUser(u); err != nil { - ctx.Handle(500, "UpdateUser", err) + if err := models.UpdateUserCols(u, "last_login_unix"); err != nil { + ctx.Handle(500, "UpdateUserCols", err) return } @@ -430,8 +430,8 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context // Register last login u.SetLastLogin() - if err := models.UpdateUser(u); err != nil { - ctx.Handle(500, "UpdateUser", err) + if err := models.UpdateUserCols(u, "last_login_unix"); err != nil { + ctx.Handle(500, "UpdateUserCols", err) return } @@ -666,7 +666,8 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au if models.CountUsers() == 1 { u.IsAdmin = true u.IsActive = true - if err := models.UpdateUser(u); err != nil { + u.SetLastLogin() + if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { ctx.Handle(500, "UpdateUser", err) return } @@ -781,7 +782,8 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo if models.CountUsers() == 1 { u.IsAdmin = true u.IsActive = true - if err := models.UpdateUser(u); err != nil { + u.SetLastLogin() + if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { ctx.Handle(500, "UpdateUser", err) return } @@ -840,7 +842,7 @@ func Activate(ctx *context.Context) { ctx.Handle(500, "UpdateUser", err) return } - if err := models.UpdateUser(user); err != nil { + if err := models.UpdateUserCols(user, "is_active", "rands"); err != nil { if models.IsErrUserNotExist(err) { ctx.Error(404) } else { @@ -991,7 +993,7 @@ func ResetPasswdPost(ctx *context.Context) { return } u.EncodePasswd() - if err := models.UpdateUser(u); err != nil { + if err := models.UpdateUserCols(u, "passwd", "rands", "salt"); err != nil { ctx.Handle(500, "UpdateUser", err) return } diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go index ff03e538f8..dcc3fcf0fc 100644 --- a/routers/user/auth_openid.go +++ b/routers/user/auth_openid.go @@ -404,7 +404,8 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si if models.CountUsers() == 1 { u.IsAdmin = true u.IsActive = true - if err := models.UpdateUser(u); err != nil { + u.SetLastLogin() + if err := models.UpdateUserCols(u, "is_admin", "is_active", "last_login_unix"); err != nil { ctx.Handle(500, "UpdateUser", err) return } diff --git a/routers/user/setting.go b/routers/user/setting.go index b6bd4ed5c2..93376043e0 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -156,7 +156,7 @@ func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *mo } } - if err := models.UpdateUser(ctxUser); err != nil { + if err := models.UpdateUserCols(ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil { return fmt.Errorf("UpdateUser: %v", err) } @@ -221,7 +221,7 @@ func SettingsPasswordPost(ctx *context.Context, form auth.ChangePasswordForm) { return } ctx.User.EncodePasswd() - if err := models.UpdateUser(ctx.User); err != nil { + if err := models.UpdateUserCols(ctx.User, "salt", "passwd"); err != nil { ctx.Handle(500, "UpdateUser", err) return } |