Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(model): update user method. #3360

Merged
merged 2 commits into from
Jan 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down