summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2015-07-23 09:21:14 -0800
committerCorey Hulen <corey@hulen.com>2015-07-23 09:21:14 -0800
commita9d48ff994cd2d03f8e1b2438e50fc6dd0d9bdc2 (patch)
treef1b1c37242136098941d3d96b32245bf2b6a528c /store
parentdc79707787b521ea5fc0d9088ccd9069780c8e0c (diff)
parentd42d0e3467c8eec38fdca429ba9ba5ac2af68db8 (diff)
downloadchat-a9d48ff994cd2d03f8e1b2438e50fc6dd0d9bdc2.tar.gz
chat-a9d48ff994cd2d03f8e1b2438e50fc6dd0d9bdc2.tar.bz2
chat-a9d48ff994cd2d03f8e1b2438e50fc6dd0d9bdc2.zip
Merge pull request #237 from mattermost/mm-1570
fixes mm-1570 adds support for using mattermost as an OAuth client
Diffstat (limited to 'store')
-rw-r--r--store/sql_user_store.go25
-rw-r--r--store/sql_user_store_test.go19
-rw-r--r--store/store.go1
3 files changed, 45 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index d8ab4482e..6cf12f5b8 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -24,6 +24,7 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore {
table.ColMap("Username").SetMaxSize(64)
table.ColMap("Password").SetMaxSize(128)
table.ColMap("AuthData").SetMaxSize(128)
+ table.ColMap("AuthService").SetMaxSize(32)
table.ColMap("Email").SetMaxSize(128)
table.ColMap("Nickname").SetMaxSize(64)
table.ColMap("FirstName").SetMaxSize(64)
@@ -57,6 +58,8 @@ func (us SqlUserStore) UpgradeSchemaIfNeeded() {
panic("Failed to set last name from nickname " + err.Error())
}
}
+
+ us.CreateColumnIfNotExists("Users", "AuthService", "AuthData", "varchar(32)", "") // for OAuth Client
}
//func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool {
@@ -369,6 +372,28 @@ func (us SqlUserStore) GetByEmail(teamId string, email string) StoreChannel {
return storeChannel
}
+func (us SqlUserStore) GetByAuth(teamId string, authData string, authService string) StoreChannel {
+
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ user := model.User{}
+
+ if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId=? AND AuthData=? AND AuthService=?", teamId, authData, authService); err != nil {
+ result.Err = model.NewAppError("SqlUserStore.GetByAuth", "We couldn't find the existing account", "teamId="+teamId+", authData="+authData+", authService="+authService+", "+err.Error())
+ }
+
+ result.Data = &user
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (us SqlUserStore) GetByUsername(teamId string, username string) StoreChannel {
storeChannel := make(StoreChannel)
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go
index 12737caa8..1f94021b2 100644
--- a/store/sql_user_store_test.go
+++ b/store/sql_user_store_test.go
@@ -236,6 +236,25 @@ func TestUserStoreGetByEmail(t *testing.T) {
}
}
+func TestUserStoreGetByAuthData(t *testing.T) {
+ Setup()
+
+ u1 := model.User{}
+ u1.TeamId = model.NewId()
+ u1.Email = model.NewId()
+ u1.AuthData = "123"
+ u1.AuthService = "service"
+ Must(store.User().Save(&u1))
+
+ if err := (<-store.User().GetByAuth(u1.TeamId, u1.AuthData, u1.AuthService)).Err; err != nil {
+ t.Fatal(err)
+ }
+
+ if err := (<-store.User().GetByAuth("", "", "")).Err; err == nil {
+ t.Fatal("Should have failed because of missing auth data")
+ }
+}
+
func TestUserStoreGetByUsername(t *testing.T) {
Setup()
diff --git a/store/store.go b/store/store.go
index 5b0e13fce..fac3a5bdb 100644
--- a/store/store.go
+++ b/store/store.go
@@ -85,6 +85,7 @@ type UserStore interface {
Get(id string) StoreChannel
GetProfiles(teamId string) StoreChannel
GetByEmail(teamId string, email string) StoreChannel
+ GetByAuth(teamId string, authData string, authService string) StoreChannel
GetByUsername(teamId string, username string) StoreChannel
VerifyEmail(userId string) StoreChannel
GetEtagForProfiles(teamId string) StoreChannel