From c39e95c7cb1ad6e812aa3ce4000b4dfdf214e77e Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Wed, 15 Jul 2015 12:48:50 -0400 Subject: inital implementation of using GitLab OAuth2 provider for signup/login --- store/sql_user_store.go | 26 ++++++++++++++++++++++++++ store/store.go | 1 + 2 files changed, 27 insertions(+) (limited to 'store') diff --git a/store/sql_user_store.go b/store/sql_user_store.go index d8ab4482e..3c25dbb44 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -31,8 +31,10 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore { table.ColMap("Roles").SetMaxSize(64) table.ColMap("Props").SetMaxSize(4000) table.ColMap("NotifyProps").SetMaxSize(2000) + table.ColMap("AuthService").SetMaxSize(32) table.SetUniqueTogether("Email", "TeamId") table.SetUniqueTogether("Username", "TeamId") + table.SetUniqueTogether("AuthData", "AuthService", "TeamId") } return us @@ -57,6 +59,8 @@ func (us SqlUserStore) UpgradeSchemaIfNeeded() { panic("Failed to set last name from nickname " + err.Error()) } } + + us.CreateColumnIfNotExists("Users", "AuthService", "LastPictureUpdate", "varchar(32)", "") // for OAuth Client } //func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool { @@ -369,6 +373,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/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 -- cgit v1.2.3-1-g7c22 From 44cfa364fd3c328523054d8ee2221d6019ad6de1 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Wed, 22 Jul 2015 12:42:03 -0400 Subject: added error case for login and removed authdata + authservice unique constraint in users table --- store/sql_user_store.go | 1 - 1 file changed, 1 deletion(-) (limited to 'store') diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 3c25dbb44..fdc101b22 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -34,7 +34,6 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore { table.ColMap("AuthService").SetMaxSize(32) table.SetUniqueTogether("Email", "TeamId") table.SetUniqueTogether("Username", "TeamId") - table.SetUniqueTogether("AuthData", "AuthService", "TeamId") } return us -- cgit v1.2.3-1-g7c22 From 41bbbbf4462205348c978a2cce5162f73e35f6b7 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Wed, 22 Jul 2015 15:05:20 -0400 Subject: add changes from team review --- store/sql_user_store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'store') diff --git a/store/sql_user_store.go b/store/sql_user_store.go index fdc101b22..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) @@ -31,7 +32,6 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore { table.ColMap("Roles").SetMaxSize(64) table.ColMap("Props").SetMaxSize(4000) table.ColMap("NotifyProps").SetMaxSize(2000) - table.ColMap("AuthService").SetMaxSize(32) table.SetUniqueTogether("Email", "TeamId") table.SetUniqueTogether("Username", "TeamId") } @@ -59,7 +59,7 @@ func (us SqlUserStore) UpgradeSchemaIfNeeded() { } } - us.CreateColumnIfNotExists("Users", "AuthService", "LastPictureUpdate", "varchar(32)", "") // for OAuth Client + 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 { -- cgit v1.2.3-1-g7c22 From d42d0e3467c8eec38fdca429ba9ba5ac2af68db8 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 23 Jul 2015 08:19:51 -0400 Subject: added store unit test for user.GetByAuth and added password length checking in api.login --- store/sql_user_store_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'store') 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() -- cgit v1.2.3-1-g7c22