summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-03-16 18:22:50 -0400
committerChristopher Speller <crspeller@gmail.com>2016-03-16 18:22:50 -0400
commit08a12ac4f4d1131dfbcb9d7a3c732125a34d4f3c (patch)
treead1bd1cf64ccf8dc6e771f96e0616df0362f1f08
parent45eee993ea2e3aa230255253f71c08b223760a70 (diff)
parentfb9a6c76113e5913d2ad7edb595a05e8567a3e85 (diff)
downloadchat-08a12ac4f4d1131dfbcb9d7a3c732125a34d4f3c.tar.gz
chat-08a12ac4f4d1131dfbcb9d7a3c732125a34d4f3c.tar.bz2
chat-08a12ac4f4d1131dfbcb9d7a3c732125a34d4f3c.zip
Merge pull request #2419 from mattermost/plt-2044
PLT-2044 Auto-create account if team allows sign-up from login page and oauth …
-rw-r--r--api/user.go12
-rw-r--r--i18n/en.json6
-rw-r--r--i18n/es.json2
-rw-r--r--i18n/pt.json4
-rw-r--r--store/sql_user_store.go11
5 files changed, 25 insertions, 10 deletions
diff --git a/api/user.go b/api/user.go
index 2c8185209..aadf735d0 100644
--- a/api/user.go
+++ b/api/user.go
@@ -249,7 +249,7 @@ func CreateUser(team *model.Team, user *model.User) (*model.User, *model.AppErro
}
}
-func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service string, userData io.ReadCloser, team *model.Team) *model.User {
+func CreateOAuthUser(c *Context, w http.ResponseWriter, r *http.Request, service string, userData io.Reader, team *model.Team) *model.User {
var user *model.User
provider := einterfaces.GetOauthProvider(service)
if provider == nil {
@@ -481,7 +481,10 @@ func LoginByUsername(c *Context, w http.ResponseWriter, r *http.Request, usernam
return nil
}
-func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service string, userData io.ReadCloser, team *model.Team) *model.User {
+func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service string, userData io.Reader, team *model.Team) *model.User {
+ buf := bytes.Buffer{}
+ buf.ReadFrom(userData)
+
authData := ""
provider := einterfaces.GetOauthProvider(service)
if provider == nil {
@@ -489,7 +492,7 @@ func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service st
map[string]interface{}{"Service": service}, "")
return nil
} else {
- authData = provider.GetAuthDataFromJson(userData)
+ authData = provider.GetAuthDataFromJson(bytes.NewReader(buf.Bytes()))
}
if len(authData) == 0 {
@@ -500,6 +503,9 @@ func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service st
var user *model.User
if result := <-Srv.Store.User().GetByAuth(team.Id, authData, service); result.Err != nil {
+ if result.Err.Id == store.MISSING_AUTH_ACCOUNT_ERROR && team.AllowOpenInvite {
+ return CreateOAuthUser(c, w, r, service, bytes.NewReader(buf.Bytes()), team)
+ }
c.Err = result.Err
return nil
} else {
diff --git a/i18n/en.json b/i18n/en.json
index d16de7dbb..9b9f57fca 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -3072,7 +3072,11 @@
"translation": "We encountered an error finding the account"
},
{
- "id": "store.sql_user.get_by_auth.app_error",
+ "id": "store.sql_user.get_by_auth.other.app_error",
+ "translation": "We encountered an error trying to find the account by authentication type."
+ },
+ {
+ "id": "store.sql_user.get_by_auth.missing_account.app_error",
"translation": "We couldn't find an existing account matching your authentication type for this team. This team may require an invite from the team owner to join."
},
{
diff --git a/i18n/es.json b/i18n/es.json
index 93ffb2341..b86c1d868 100644
--- a/i18n/es.json
+++ b/i18n/es.json
@@ -3068,7 +3068,7 @@
"translation": "Encontramos un error buscando la cuenta"
},
{
- "id": "store.sql_user.get_by_auth.app_error",
+ "id": "store.sql_user.get_by_auth.missing_account.app_error",
"translation": "No pudimos encontrar una cuenta existente que coincida con tu tipo de autenticación para este equipo. Es posible que necesites una invitación por parte del dueño del equipo para unirte."
},
{
diff --git a/i18n/pt.json b/i18n/pt.json
index 29c8c58c7..19bf04a90 100644
--- a/i18n/pt.json
+++ b/i18n/pt.json
@@ -3068,7 +3068,7 @@
"translation": "Encontramos um erro ao procurar a conta"
},
{
- "id": "store.sql_user.get_by_auth.app_error",
+ "id": "store.sql_user.get_by_auth.missing_account.app_error",
"translation": "Não foi possível encontrar uma conta correspondente ao seu tipo de autenticação para esta equipe. Esta equipe pode exigir um convite do dono da equipe para participar."
},
{
@@ -3607,4 +3607,4 @@
"id": "web.watcher_fail.error",
"translation": "Falha ao adicionar diretório observador %v"
}
-] \ No newline at end of file
+]
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