"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "models/user.go" between
gitea-1.13.1.tar.gz and gitea-1.13.2.tar.gz

About: Gitea allows to set up a self-hosted code hosting Git service (a fork of Gogs).

user.go  (gitea-1.13.1):user.go  (gitea-1.13.2)
skipping to change at line 43 skipping to change at line 43
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"github.com/unknwon/com" "github.com/unknwon/com"
"golang.org/x/crypto/argon2" "golang.org/x/crypto/argon2"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/scrypt" "golang.org/x/crypto/scrypt"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"xorm.io/builder" "xorm.io/builder"
"xorm.io/xorm"
) )
// UserType defines the user type // UserType defines the user type
type UserType int type UserType int
const ( const (
// UserTypeIndividual defines an individual user // UserTypeIndividual defines an individual user
UserTypeIndividual UserType = iota // Historic reason to make it starts a t 0. UserTypeIndividual UserType = iota // Historic reason to make it starts a t 0.
// UserTypeOrganization defines an organization // UserTypeOrganization defines an organization
skipping to change at line 926 skipping to change at line 925
if has, _ := x.Get(emailAddress); has { if has, _ := x.Get(emailAddress); has {
return emailAddress return emailAddress
} }
} }
} }
return nil return nil
} }
// ChangeUserName changes all corresponding setting from old user name to new on e. // ChangeUserName changes all corresponding setting from old user name to new on e.
func ChangeUserName(u *User, newUserName string) (err error) { func ChangeUserName(u *User, newUserName string) (err error) {
oldUserName := u.Name
if err = IsUsableUsername(newUserName); err != nil { if err = IsUsableUsername(newUserName); err != nil {
return err return err
} }
isExist, err := IsUserExist(0, newUserName) isExist, err := IsUserExist(0, newUserName)
if err != nil { if err != nil {
return err return err
} else if isExist { } else if isExist {
return ErrUserAlreadyExist{newUserName} return ErrUserAlreadyExist{newUserName}
} }
sess := x.NewSession() sess := x.NewSession()
defer sess.Close() defer sess.Close()
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
return err return err
} }
if _, err = sess.Exec("UPDATE `repository` SET owner_name=? WHERE owner_n ame=?", newUserName, u.Name); err != nil { if _, err = sess.Exec("UPDATE `repository` SET owner_name=? WHERE owner_n ame=?", newUserName, oldUserName); err != nil {
return fmt.Errorf("Change repo owner name: %v", err) return fmt.Errorf("Change repo owner name: %v", err)
} }
// Do not fail if directory does not exist // Do not fail if directory does not exist
if err = os.Rename(UserPath(u.Name), UserPath(newUserName)); err != nil & & !os.IsNotExist(err) { if err = os.Rename(UserPath(oldUserName), UserPath(newUserName)); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("Rename user directory: %v", err) return fmt.Errorf("Rename user directory: %v", err)
} }
return sess.Commit() if err = sess.Commit(); err != nil {
if err2 := os.Rename(UserPath(newUserName), UserPath(oldUserName)
); err2 != nil && !os.IsNotExist(err2) {
log.Critical("Unable to rollback directory change during
failed username change from: %s to: %s. DB Error: %v. Filesystem Error: %v", old
UserName, newUserName, err, err2)
return fmt.Errorf("failed to rollback directory change du
ring failed username change from: %s to: %s. DB Error: %w. Filesystem Error: %v"
, oldUserName, newUserName, err, err2)
}
return err
}
return nil
} }
// checkDupEmail checks whether there are the same email with the user // checkDupEmail checks whether there are the same email with the user
func checkDupEmail(e Engine, u *User) error { func checkDupEmail(e Engine, u *User) error {
u.Email = strings.ToLower(u.Email) u.Email = strings.ToLower(u.Email)
has, err := e. has, err := e.
Where("id!=?", u.ID). Where("id!=?", u.ID).
And("type=?", u.Type). And("type=?", u.Type).
And("email=?", u.Email). And("email=?", u.Email).
Get(new(User)) Get(new(User))
skipping to change at line 1023 skipping to change at line 1031
// deleteBeans deletes all given beans, beans should contain delete conditions. // deleteBeans deletes all given beans, beans should contain delete conditions.
func deleteBeans(e Engine, beans ...interface{}) (err error) { func deleteBeans(e Engine, beans ...interface{}) (err error) {
for i := range beans { for i := range beans {
if _, err = e.Delete(beans[i]); err != nil { if _, err = e.Delete(beans[i]); err != nil {
return err return err
} }
} }
return nil return nil
} }
// FIXME: need some kind of mechanism to record failure. HINT: system notice func deleteUser(e Engine, u *User) error {
func deleteUser(e *xorm.Session, u *User) error {
// Note: A user owns any repository or belongs to any organization // Note: A user owns any repository or belongs to any organization
// cannot perform delete operation. // cannot perform delete operation.
// Check ownership of repository. // Check ownership of repository.
count, err := getRepositoryCount(e, u) count, err := getRepositoryCount(e, u)
if err != nil { if err != nil {
return fmt.Errorf("GetRepositoryCount: %v", err) return fmt.Errorf("GetRepositoryCount: %v", err)
} else if count > 0 { } else if count > 0 {
return ErrUserOwnRepos{UID: u.ID} return ErrUserOwnRepos{UID: u.ID}
} }
skipping to change at line 1138 skipping to change at line 1145
// ***** START: ExternalLoginUser ***** // ***** START: ExternalLoginUser *****
if err = removeAllAccountLinks(e, u); err != nil { if err = removeAllAccountLinks(e, u); err != nil {
return fmt.Errorf("ExternalLoginUser: %v", err) return fmt.Errorf("ExternalLoginUser: %v", err)
} }
// ***** END: ExternalLoginUser ***** // ***** END: ExternalLoginUser *****
if _, err = e.ID(u.ID).Delete(new(User)); err != nil { if _, err = e.ID(u.ID).Delete(new(User)); err != nil {
return fmt.Errorf("Delete: %v", err) return fmt.Errorf("Delete: %v", err)
} }
// FIXME: system notice
// Note: There are something just cannot be roll back, // Note: There are something just cannot be roll back,
// so just keep error logs of those operations. // so just keep error logs of those operations.
path := UserPath(u.Name) path := UserPath(u.Name)
if err := util.RemoveAll(path); err != nil { if err = util.RemoveAll(path); err != nil {
return fmt.Errorf("Failed to RemoveAll %s: %v", path, err) err = fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
_ = createNotice(e, NoticeTask, fmt.Sprintf("delete user '%s': %v
", u.Name, err))
return err
} }
if len(u.Avatar) > 0 { if len(u.Avatar) > 0 {
avatarPath := u.CustomAvatarRelativePath() avatarPath := u.CustomAvatarRelativePath()
if err := storage.Avatars.Delete(avatarPath); err != nil { if err = storage.Avatars.Delete(avatarPath); err != nil {
return fmt.Errorf("Failed to remove %s: %v", avatarPath, err = fmt.Errorf("Failed to remove %s: %v", avatarPath, e
err) rr)
_ = createNotice(e, NoticeTask, fmt.Sprintf("delete user
'%s': %v", u.Name, err))
return err
} }
} }
return nil return nil
} }
// DeleteUser completely and permanently deletes everything of a user, // DeleteUser completely and permanently deletes everything of a user,
// but issues/comments/pulls will be kept and shown as someone has been deleted. // but issues/comments/pulls will be kept and shown as someone has been deleted.
func DeleteUser(u *User) (err error) { func DeleteUser(u *User) (err error) {
if u.IsOrganization() { if u.IsOrganization() {
 End of changes. 9 change blocks. 
12 lines changed or deleted 29 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)