Migrating User Store VerifyEmail, GetByAuth and GetByEmail functions to sync by default (#10941)

Этот коммит содержится в:
Jesús Espino
2019-06-12 19:30:50 +02:00
коммит произвёл GitHub
родитель f49a0881bf
Коммит 76bab4f0c2
16 изменённых файлов: 181 добавлений и 164 удалений

Просмотреть файл

@@ -949,55 +949,45 @@ func (us SqlUserStore) GetSystemAdminProfiles() store.StoreChannel {
})
}
func (us SqlUserStore) GetByEmail(email string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
email = strings.ToLower(email)
func (us SqlUserStore) GetByEmail(email string) (*model.User, *model.AppError) {
email = strings.ToLower(email)
query := us.usersQuery.Where("Email = ?", email)
query := us.usersQuery.Where("Email = ?", email)
queryString, args, err := query.ToSql()
if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetByEmail", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
queryString, args, err := query.ToSql()
if err != nil {
return nil, model.NewAppError("SqlUserStore.GetByEmail", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
user := model.User{}
if err := us.GetReplica().SelectOne(&user, queryString, args...); err != nil {
result.Err = model.NewAppError("SqlUserStore.GetByEmail", store.MISSING_ACCOUNT_ERROR, nil, "email="+email+", "+err.Error(), http.StatusInternalServerError)
}
user := model.User{}
if err := us.GetReplica().SelectOne(&user, queryString, args...); err != nil {
return nil, model.NewAppError("SqlUserStore.GetByEmail", store.MISSING_ACCOUNT_ERROR, nil, "email="+email+", "+err.Error(), http.StatusInternalServerError)
}
result.Data = &user
})
return &user, nil
}
func (us SqlUserStore) GetByAuth(authData *string, authService string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if authData == nil || *authData == "" {
result.Err = model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData='', authService="+authService, http.StatusBadRequest)
return
}
func (us SqlUserStore) GetByAuth(authData *string, authService string) (*model.User, *model.AppError) {
if authData == nil || *authData == "" {
return nil, model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData='', authService="+authService, http.StatusBadRequest)
}
query := us.usersQuery.
Where("u.AuthData = ?", authData).
Where("u.AuthService = ?", authService)
query := us.usersQuery.
Where("u.AuthData = ?", authData).
Where("u.AuthService = ?", authService)
queryString, args, err := query.ToSql()
if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
queryString, args, err := query.ToSql()
if err != nil {
return nil, model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
user := model.User{}
if err := us.GetReplica().SelectOne(&user, queryString, args...); err == sql.ErrNoRows {
result.Err = model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError)
return
} else if err != nil {
result.Err = model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.get_by_auth.other.app_error", nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError)
return
}
result.Data = &user
})
user := model.User{}
if err := us.GetReplica().SelectOne(&user, queryString, args...); err == sql.ErrNoRows {
return nil, model.NewAppError("SqlUserStore.GetByAuth", store.MISSING_AUTH_ACCOUNT_ERROR, nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError)
} else if err != nil {
return nil, model.NewAppError("SqlUserStore.GetByAuth", "store.sql_user.get_by_auth.other.app_error", nil, "authData="+*authData+", authService="+authService+", "+err.Error(), http.StatusInternalServerError)
}
return &user, nil
}
func (us SqlUserStore) GetAllUsingAuthService(authService string) store.StoreChannel {
@@ -1083,15 +1073,13 @@ func (us SqlUserStore) GetForLogin(loginId string, allowSignInWithUsername, allo
})
}
func (us SqlUserStore) VerifyEmail(userId, email string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
curTime := model.GetMillis()
if _, err := us.GetMaster().Exec("UPDATE Users SET Email = :email, EmailVerified = true, UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"email": email, "Time": curTime, "UserId": userId}); err != nil {
result.Err = model.NewAppError("SqlUserStore.VerifyEmail", "store.sql_user.verify_email.app_error", nil, "userId="+userId+", "+err.Error(), http.StatusInternalServerError)
}
func (us SqlUserStore) VerifyEmail(userId, email string) (string, *model.AppError) {
curTime := model.GetMillis()
if _, err := us.GetMaster().Exec("UPDATE Users SET Email = :email, EmailVerified = true, UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"email": email, "Time": curTime, "UserId": userId}); err != nil {
return "", model.NewAppError("SqlUserStore.VerifyEmail", "store.sql_user.verify_email.app_error", nil, "userId="+userId+", "+err.Error(), http.StatusInternalServerError)
}
result.Data = userId
})
return userId, nil
}
func (us SqlUserStore) PermanentDelete(userId string) *model.AppError {