mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 09:44:21 +00:00 
			
		
		
		
	refactor(model): update user method. (#3360)
This commit is contained in:
		@@ -138,6 +138,22 @@ func (u *User) BeforeUpdate() {
 | 
				
			|||||||
	if u.MaxRepoCreation < -1 {
 | 
						if u.MaxRepoCreation < -1 {
 | 
				
			||||||
		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
 | 
					// SetLastLogin set time to last login
 | 
				
			||||||
@@ -840,22 +856,6 @@ func checkDupEmail(e Engine, u *User) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func updateUser(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)
 | 
						_, err := e.ID(u.ID).AllCols().Update(u)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -871,22 +871,6 @@ func UpdateUserCols(u *User, cols ...string) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func updateUserCols(e Engine, 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)
 | 
						_, err := e.ID(u.ID).Cols(cols...).Update(u)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user