diff options
author | Bo-Yi Wu <appleboy.tw@gmail.com> | 2018-01-13 17:45:16 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-01-13 11:45:16 +0200 |
commit | 7a2a3fbafc5b15bb460787a2fca9db8f1e09e78e (patch) | |
tree | 17343902be75242731d4082dc2aedd5bc4c4854f /models | |
parent | f7088292bbc544fd74e53863ed3660c1df82a398 (diff) | |
download | gitea-7a2a3fbafc5b15bb460787a2fca9db8f1e09e78e.tar.gz gitea-7a2a3fbafc5b15bb460787a2fca9db8f1e09e78e.zip |
refactor(model): update user method. (#3360)
Diffstat (limited to 'models')
-rw-r--r-- | models/user.go | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/models/user.go b/models/user.go index aaf2320b42..da9411dcb6 100644 --- a/models/user.go +++ b/models/user.go @@ -138,6 +138,22 @@ func (u *User) BeforeUpdate() { if u.MaxRepoCreation < -1 { u.MaxRepoCreation = -1 } + + // Organization does not need email + u.Email = strings.ToLower(u.Email) + if !u.IsOrganization() { + if len(u.AvatarEmail) == 0 { + u.AvatarEmail = u.Email + } + if len(u.AvatarEmail) > 0 { + u.Avatar = base.HashEmail(u.AvatarEmail) + } + } + + u.LowerName = strings.ToLower(u.Name) + u.Location = base.TruncateString(u.Location, 255) + u.Website = base.TruncateString(u.Website, 255) + u.Description = base.TruncateString(u.Description, 255) } // SetLastLogin set time to last login @@ -840,22 +856,6 @@ func checkDupEmail(e Engine, u *User) error { } func updateUser(e Engine, u *User) error { - // Organization does not need email - u.Email = strings.ToLower(u.Email) - if !u.IsOrganization() { - if len(u.AvatarEmail) == 0 { - u.AvatarEmail = u.Email - } - if len(u.AvatarEmail) > 0 { - u.Avatar = base.HashEmail(u.AvatarEmail) - } - } - - u.LowerName = strings.ToLower(u.Name) - u.Location = base.TruncateString(u.Location, 255) - u.Website = base.TruncateString(u.Website, 255) - u.Description = base.TruncateString(u.Description, 255) - _, err := e.ID(u.ID).AllCols().Update(u) return err } @@ -871,22 +871,6 @@ func UpdateUserCols(u *User, cols ...string) error { } func updateUserCols(e Engine, u *User, cols ...string) error { - // Organization does not need email - u.Email = strings.ToLower(u.Email) - if !u.IsOrganization() { - if len(u.AvatarEmail) == 0 { - u.AvatarEmail = u.Email - } - if len(u.AvatarEmail) > 0 { - u.Avatar = base.HashEmail(u.AvatarEmail) - } - } - - u.LowerName = strings.ToLower(u.Name) - u.Location = base.TruncateString(u.Location, 255) - u.Website = base.TruncateString(u.Website, 255) - u.Description = base.TruncateString(u.Description, 255) - _, err := e.ID(u.ID).Cols(cols...).Update(u) return err } |