summaryrefslogtreecommitdiffstats
path: root/store/sql_user_store.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-05-03 14:10:36 -0400
committerChristopher Speller <crspeller@gmail.com>2016-05-03 14:10:36 -0400
commit87989b8afd4666a72940389db716b6500d0a9ec3 (patch)
treed4b0270eb4a9adbff0dd1b6f527ddcccbc9a83d9 /store/sql_user_store.go
parente76a30bca0690bad53a4cabd6c7c629e89c17268 (diff)
downloadchat-87989b8afd4666a72940389db716b6500d0a9ec3.tar.gz
chat-87989b8afd4666a72940389db716b6500d0a9ec3.tar.bz2
chat-87989b8afd4666a72940389db716b6500d0a9ec3.zip
PLT-2258 Unified login screen and related APIs (#2820)
* Unified login screen and related APIs * Refactored login API call to be less convoluted * Removed LDAP login prompt from invite process * Fixed existing LDAP users being able to log in if LDAP was configured, but disabled * Gofmt * Future proofed login API * Updated login APIs based on feedback * Added additional auditing to login API * Actually removed loginById
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r--store/sql_user_store.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 4d18aabd1..37bc148e1 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -716,6 +716,47 @@ func (us SqlUserStore) GetByUsername(username string) StoreChannel {
return storeChannel
}
+func (us SqlUserStore) GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail, ldapEnabled bool) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ params := map[string]interface{}{
+ "LoginId": loginId,
+ "AllowSignInWithUsername": allowSignInWithUsername,
+ "AllowSignInWithEmail": allowSignInWithEmail,
+ "LdapEnabled": ldapEnabled,
+ }
+
+ users := []*model.User{}
+ if _, err := us.GetReplica().Select(
+ &users,
+ `SELECT
+ *
+ FROM
+ Users
+ WHERE
+ (:AllowSignInWithUsername AND Username = :LoginId)
+ OR (:AllowSignInWithEmail AND Email = :LoginId)
+ OR (:LdapEnabled AND AuthService = '`+model.USER_AUTH_SERVICE_LDAP+`' AND AuthData = :LoginId)`,
+ params); err != nil {
+ result.Err = model.NewLocAppError("SqlUserStore.GetForLogin", "store.sql_user.get_for_login.app_error", nil, err.Error())
+ } else if len(users) == 1 {
+ result.Data = users[0]
+ } else if len(users) > 1 {
+ result.Err = model.NewLocAppError("SqlUserStore.GetForLogin", "store.sql_user.get_for_login.multiple_users", nil, "")
+ } else {
+ result.Err = model.NewLocAppError("SqlUserStore.GetForLogin", "store.sql_user.get_for_login.app_error", nil, "")
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (us SqlUserStore) VerifyEmail(userId string) StoreChannel {
storeChannel := make(StoreChannel)