Users: Enable case insensitive login by default (#66134)

* enable case insensitive by default

* fix missing case-insensitive query

* fix missing case insensitive query

* fix missing case insensitive query in temp_user

* skip integration testing in mysql

* skip integration testing in mysql

* use t.cleanup

* lowercase only once

* aligned to only using sql as that is what we do in other parts

---------

Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com>
This commit is contained in:
Jo
2023-04-28 16:38:58 +01:00
committed by GitHub
co-authored by Eric Leijonmarck
parent 7448427739
commit 8df54a6daa
6 changed files with 138 additions and 8 deletions
+11 -2
View File
@@ -88,8 +88,16 @@ func (ss *sqlStore) Insert(ctx context.Context, cmd *user.User) (int64, error) {
}
func (ss *sqlStore) Get(ctx context.Context, usr *user.User) (*user.User, error) {
ret := &user.User{}
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
exists, err := sess.Where("email=? OR login=?", usr.Email, usr.Login).Get(usr)
where := "email=? OR login=?"
login := usr.Login
email := usr.Email
if ss.cfg.CaseInsensitiveLogin {
where = "LOWER(email)=LOWER(?) OR LOWER(login)=LOWER(?)"
}
exists, err := sess.Where(where, email, login).Get(ret)
if !exists {
return user.ErrUserNotFound
}
@@ -101,7 +109,8 @@ func (ss *sqlStore) Get(ctx context.Context, usr *user.User) (*user.User, error)
if err != nil {
return nil, err
}
return usr, nil
return ret, nil
}
func (ss *sqlStore) Delete(ctx context.Context, userID int64) error {