Auto-create account if team allows sign-up from login page and oauth account doesn't exist
Этот коммит содержится в:
12
api/user.go
12
api/user.go
@@ -246,7 +246,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
|
var user *model.User
|
||||||
provider := einterfaces.GetOauthProvider(service)
|
provider := einterfaces.GetOauthProvider(service)
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
@@ -478,7 +478,10 @@ func LoginByUsername(c *Context, w http.ResponseWriter, r *http.Request, usernam
|
|||||||
return nil
|
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 := ""
|
authData := ""
|
||||||
provider := einterfaces.GetOauthProvider(service)
|
provider := einterfaces.GetOauthProvider(service)
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
@@ -486,7 +489,7 @@ func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service st
|
|||||||
map[string]interface{}{"Service": service}, "")
|
map[string]interface{}{"Service": service}, "")
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
authData = provider.GetAuthDataFromJson(userData)
|
authData = provider.GetAuthDataFromJson(bytes.NewReader(buf.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(authData) == 0 {
|
if len(authData) == 0 {
|
||||||
@@ -497,6 +500,9 @@ func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service st
|
|||||||
|
|
||||||
var user *model.User
|
var user *model.User
|
||||||
if result := <-Srv.Store.User().GetByAuth(team.Id, authData, service); result.Err != nil {
|
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
|
c.Err = result.Err
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3068,7 +3068,11 @@
|
|||||||
"translation": "We encountered an error finding the account"
|
"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."
|
"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."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3068,7 +3068,7 @@
|
|||||||
"translation": "Encontramos un error buscando la cuenta"
|
"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."
|
"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."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3052,7 +3052,7 @@
|
|||||||
"translation": "Encontramos um erro ao procurar a conta"
|
"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."
|
"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."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
@@ -12,6 +13,7 @@ import (
|
|||||||
|
|
||||||
const (
|
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 {
|
type SqlUserStore struct {
|
||||||
@@ -481,8 +483,11 @@ func (us SqlUserStore) GetByAuth(teamId string, authData string, authService str
|
|||||||
user := model.User{}
|
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 {
|
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",
|
if err == sql.ErrNoRows {
|
||||||
nil, "teamId="+teamId+", authData="+authData+", authService="+authService+", "+err.Error())
|
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
|
result.Data = &user
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user