From fb9a6c76113e5913d2ad7edb595a05e8567a3e85 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 11 Mar 2016 10:48:43 -0500 Subject: Auto-create account if team allows sign-up from login page and oauth account doesn't exist --- store/sql_user_store.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'store') diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 47c6ea61a..cc6829b94 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -4,6 +4,7 @@ package store import ( + "database/sql" "fmt" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" @@ -11,7 +12,8 @@ import ( ) const ( - MISSING_ACCOUNT_ERROR = "store.sql_user.missing_account.const" + MISSING_ACCOUNT_ERROR = "store.sql_user.missing_account.const" + MISSING_AUTH_ACCOUNT_ERROR = "store.sql_user.get_by_auth.missing_account.app_error" ) type SqlUserStore struct { @@ -481,8 +483,11 @@ func (us SqlUserStore) GetByAuth(teamId string, authData string, authService str user := model.User{} if err := us.GetReplica().SelectOne(&user, "SELECT * FROM Users WHERE TeamId = :TeamId AND AuthData = :AuthData AND AuthService = :AuthService", map[string]interface{}{"TeamId": teamId, "AuthData": authData, "AuthService": authService}); err != nil { - result.Err = model.NewLocAppError("SqlUserStore.GetByAuth", "store.sql_user.get_by_auth.app_error", - nil, "teamId="+teamId+", authData="+authData+", authService="+authService+", "+err.Error()) + if err == sql.ErrNoRows { + result.Err = model.NewLocAppError("SqlUserStore.GetByAuth", MISSING_AUTH_ACCOUNT_ERROR, nil, "teamId="+teamId+", authData="+authData+", authService="+authService+", "+err.Error()) + } else { + result.Err = model.NewLocAppError("SqlUserStore.GetByAuth", "store.sql_user.get_by_auth.other.app_error", nil, "teamId="+teamId+", authData="+authData+", authService="+authService+", "+err.Error()) + } } result.Data = &user -- cgit v1.2.3-1-g7c22