Skip to content

Commit 2f5ae85

Browse files
theangryangeltorkelo
authored andcommitted
Initial patch for grafana#4267 (grafana#5280)
1 parent 7cbaf06 commit 2f5ae85

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

pkg/services/sqlstore/user.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,23 @@ func GetUserByLogin(query *m.GetUserByLoginQuery) error {
161161
}
162162

163163
user := new(m.User)
164-
if strings.Contains(query.LoginOrEmail, "@") {
165-
user = &m.User{Email: query.LoginOrEmail}
166-
} else {
167-
user = &m.User{Login: query.LoginOrEmail}
168-
}
169164

165+
// Try and find the user by login first.
166+
// It's not sufficient to assume that a LoginOrEmail with an "@" is an email.
167+
user = &m.User{Login: query.LoginOrEmail}
170168
has, err := x.Get(user)
171169

170+
if err != nil {
171+
return err
172+
}
173+
174+
if has == false && strings.Contains(query.LoginOrEmail, "@") {
175+
// If the user wasn't found, and it contains an "@" fallback to finding the
176+
// user by email.
177+
user = &m.User{Email: query.LoginOrEmail}
178+
has, err = x.Get(user)
179+
}
180+
172181
if err != nil {
173182
return err
174183
} else if has == false {

0 commit comments

Comments
 (0)