Commit 2f5ae85d by Karl Committed by Torkel Ödegaard

Initial patch for grafana/grafana#4267 (#5280)

parent 7cbaf060
...@@ -161,16 +161,25 @@ func GetUserByLogin(query *m.GetUserByLoginQuery) error { ...@@ -161,16 +161,25 @@ func GetUserByLogin(query *m.GetUserByLoginQuery) error {
} }
user := new(m.User) user := new(m.User)
if strings.Contains(query.LoginOrEmail, "@") {
user = &m.User{Email: query.LoginOrEmail}
} else {
user = &m.User{Login: query.LoginOrEmail}
}
// Try and find the user by login first.
// It's not sufficient to assume that a LoginOrEmail with an "@" is an email.
user = &m.User{Login: query.LoginOrEmail}
has, err := x.Get(user) has, err := x.Get(user)
if err != nil { if err != nil {
return err return err
}
if has == false && strings.Contains(query.LoginOrEmail, "@") {
// If the user wasn't found, and it contains an "@" fallback to finding the
// user by email.
user = &m.User{Email: query.LoginOrEmail}
has, err = x.Get(user)
}
if err != nil {
return err
} else if has == false { } else if has == false {
return m.ErrUserNotFound return m.ErrUserNotFound
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment