Migrating User Store VerifyEmail, GetByAuth and GetByEmail functions to sync by default (#10941)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f49a0881bf
Коммит
76bab4f0c2
@@ -48,7 +48,10 @@ func (a *App) CreateBasicUser(client *model.Client4) *model.AppError {
|
||||
if resp.Error != nil {
|
||||
return resp.Error
|
||||
}
|
||||
store.Must(a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email))
|
||||
_, err := a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
store.Must(a.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}, *a.Config().TeamSettings.MaxUsersPerTeam))
|
||||
}
|
||||
return nil
|
||||
@@ -83,7 +86,10 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
|
||||
}
|
||||
|
||||
// We need to cheat to verify the user's email
|
||||
store.Must(cfg.app.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email))
|
||||
_, err := cfg.app.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return ruser, true
|
||||
}
|
||||
|
||||
17
app/oauth.go
17
app/oauth.go
@@ -594,22 +594,21 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.blank_email.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.User().GetByEmail(email)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
if err := a.RevokeAllSessions(user.Id); err != nil {
|
||||
user, err := a.Srv.Store.User().GetByEmail(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result = <-a.Srv.Store.User().UpdateAuthData(user.Id, service, &authData, ssoEmail, true); result.Err != nil {
|
||||
if err = a.RevokeAllSessions(user.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.User().UpdateAuthData(user.Id, service, &authData, ssoEmail, true); result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
a.Srv.Go(func() {
|
||||
if err := a.SendSignInChangeEmail(user.Email, strings.Title(service)+" SSO", user.Locale, a.GetSiteURL()); err != nil {
|
||||
if err = a.SendSignInChangeEmail(user.Email, strings.Title(service)+" SSO", user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -168,8 +168,7 @@ func (a *App) SlackAddUsers(teamId string, slackusers []SlackUser, importerLog *
|
||||
password := model.NewId()
|
||||
|
||||
// Check for email conflict and use existing user if found
|
||||
if result := <-a.Srv.Store.User().GetByEmail(email); result.Err == nil {
|
||||
existingUser := result.Data.(*model.User)
|
||||
if existingUser, err := a.Srv.Store.User().GetByEmail(email); err == nil {
|
||||
addedUsers[sUser.Id] = existingUser
|
||||
if err := a.JoinUserToTeam(team, addedUsers[sUser.Id], ""); err != nil {
|
||||
importerLog.WriteString(utils.T("api.slackimport.slack_add_users.merge_existing_failed", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username}))
|
||||
@@ -795,8 +794,8 @@ func (a *App) OldImportUser(team *model.Team, user *model.User) *model.User {
|
||||
}
|
||||
ruser := result.Data.(*model.User)
|
||||
|
||||
if cresult := <-a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email); cresult.Err != nil {
|
||||
mlog.Error(fmt.Sprintf("Failed to set email verified err=%v", cresult.Err))
|
||||
if _, err := a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email); err != nil {
|
||||
mlog.Error(fmt.Sprintf("Failed to set email verified err=%v", err))
|
||||
}
|
||||
|
||||
if err := a.JoinUserToTeam(team, user, ""); err != nil {
|
||||
|
||||
39
app/user.go
39
app/user.go
@@ -337,8 +337,18 @@ func (a *App) CreateOAuthUser(service string, userData io.Reader, teamId string)
|
||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]interface{}{"Service": service}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
suchan := a.Srv.Store.User().GetByAuth(user.AuthData, service)
|
||||
euchan := a.Srv.Store.User().GetByEmail(user.Email)
|
||||
suchan := make(chan store.StoreResult, 1)
|
||||
euchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
userByAuth, err := a.Srv.Store.User().GetByAuth(user.AuthData, service)
|
||||
suchan <- store.StoreResult{Data: userByAuth, Err: err}
|
||||
close(suchan)
|
||||
}()
|
||||
go func() {
|
||||
userByEmail, err := a.Srv.Store.User().GetByEmail(user.Email)
|
||||
euchan <- store.StoreResult{Data: userByEmail, Err: err}
|
||||
close(euchan)
|
||||
}()
|
||||
|
||||
found := true
|
||||
count := 0
|
||||
@@ -427,24 +437,20 @@ func (a *App) GetUserByUsername(username string) (*model.User, *model.AppError)
|
||||
}
|
||||
|
||||
func (a *App) GetUserByEmail(email string) (*model.User, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().GetByEmail(email)
|
||||
if result.Err != nil {
|
||||
if result.Err.Id == "store.sql_user.missing_account.const" {
|
||||
result.Err.StatusCode = http.StatusNotFound
|
||||
return nil, result.Err
|
||||
user, err := a.Srv.Store.User().GetByEmail(email)
|
||||
if err != nil {
|
||||
if err.Id == "store.sql_user.missing_account.const" {
|
||||
err.StatusCode = http.StatusNotFound
|
||||
return nil, err
|
||||
}
|
||||
result.Err.StatusCode = http.StatusBadRequest
|
||||
return nil, result.Err
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
}
|
||||
return result.Data.(*model.User), nil
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (a *App) GetUserByAuth(authData *string, authService string) (*model.User, *model.AppError) {
|
||||
result := <-a.Srv.Store.User().GetByAuth(authData, authService)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.(*model.User), nil
|
||||
return a.Srv.Store.User().GetByAuth(authData, authService)
|
||||
}
|
||||
|
||||
func (a *App) GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError) {
|
||||
@@ -1636,8 +1642,7 @@ func (a *App) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions)
|
||||
}
|
||||
|
||||
func (a *App) VerifyUserEmail(userId, email string) *model.AppError {
|
||||
err := (<-a.Srv.Store.User().VerifyEmail(userId, email)).Err
|
||||
|
||||
_, err := a.Srv.Store.User().VerifyEmail(userId, email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user