|
|
|
@ -185,14 +185,14 @@ func (ss *sqlStore) GetByEmail(ctx context.Context, query *user.GetUserByEmailQu |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LoginConflict returns an error if the provided email or login are already
|
|
|
|
|
// associated with a user. If caseInsensitive is true the search is not case
|
|
|
|
|
// sensitive.
|
|
|
|
|
// associated with a user.
|
|
|
|
|
func (ss *sqlStore) LoginConflict(ctx context.Context, login, email string) error { |
|
|
|
|
// enforcement of lowercase due to forcement of caseinsensitive login
|
|
|
|
|
login = strings.ToLower(login) |
|
|
|
|
email = strings.ToLower(email) |
|
|
|
|
|
|
|
|
|
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error { |
|
|
|
|
users := make([]user.User, 0) |
|
|
|
|
where := "email=? OR login=?" |
|
|
|
|
login = strings.ToLower(login) |
|
|
|
|
email = strings.ToLower(email) |
|
|
|
|
|
|
|
|
|
exists, err := sess.Where(where, email, login).Get(&user.User{}) |
|
|
|
|
if err != nil { |
|
|
|
@ -201,14 +201,7 @@ func (ss *sqlStore) LoginConflict(ctx context.Context, login, email string) erro |
|
|
|
|
if exists { |
|
|
|
|
return user.ErrUserAlreadyExists |
|
|
|
|
} |
|
|
|
|
if err := sess.Where("LOWER(email)=LOWER(?) OR LOWER(login)=LOWER(?)", |
|
|
|
|
email, login).Find(&users); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(users) > 1 { |
|
|
|
|
return &user.ErrCaseInsensitiveLoginConflict{Users: users} |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
}) |
|
|
|
|
return err |
|
|
|
|