Migrate User.UpdateFailedPasswordAttempts to sync by default (#11507)
* Migrate User.UpdateFailedPasswordAttempts to sync by default * Removed unused return value
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
2ecca12bed
Коммит
7da08e7a0f
@@ -51,8 +51,8 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := a.checkUserPassword(user, password); err != nil {
|
if err := a.checkUserPassword(user, password); err != nil {
|
||||||
if result := <-a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); result.Err != nil {
|
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||||
return result.Err
|
return passErr
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -61,15 +61,15 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa
|
|||||||
// If the mfaToken is not set, we assume the client used this as a pre-flight request to query the server
|
// If the mfaToken is not set, we assume the client used this as a pre-flight request to query the server
|
||||||
// about the MFA state of the user in question
|
// about the MFA state of the user in question
|
||||||
if mfaToken != "" {
|
if mfaToken != "" {
|
||||||
if result := <-a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); result.Err != nil {
|
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||||
return result.Err
|
return passErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); result.Err != nil {
|
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil {
|
||||||
return result.Err
|
return passErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.CheckUserPostflightAuthenticationCriteria(user); err != nil {
|
if err := a.CheckUserPostflightAuthenticationCriteria(user); err != nil {
|
||||||
@@ -86,14 +86,14 @@ func (a *App) DoubleCheckPassword(user *model.User, password string) *model.AppE
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := a.checkUserPassword(user, password); err != nil {
|
if err := a.checkUserPassword(user, password); err != nil {
|
||||||
if result := <-a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); result.Err != nil {
|
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||||
return result.Err
|
return passErr
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); result.Err != nil {
|
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil {
|
||||||
return result.Err
|
return passErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -255,14 +255,12 @@ func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) store.Store
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) store.StoreChannel {
|
func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) *model.AppError {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
if _, err := us.GetMaster().Exec("UPDATE Users SET FailedAttempts = :FailedAttempts WHERE Id = :UserId", map[string]interface{}{"FailedAttempts": attempts, "UserId": userId}); err != nil {
|
||||||
if _, err := us.GetMaster().Exec("UPDATE Users SET FailedAttempts = :FailedAttempts WHERE Id = :UserId", map[string]interface{}{"FailedAttempts": attempts, "UserId": userId}); err != nil {
|
return model.NewAppError("SqlUserStore.UpdateFailedPasswordAttempts", "store.sql_user.update_failed_pwd_attempts.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
|
||||||
result.Err = model.NewAppError("SqlUserStore.UpdateFailedPasswordAttempts", "store.sql_user.update_failed_pwd_attempts.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
|
}
|
||||||
} else {
|
|
||||||
result.Data = userId
|
return nil
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError) {
|
func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError) {
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ type UserStore interface {
|
|||||||
VerifyEmail(userId, email string) (string, *model.AppError)
|
VerifyEmail(userId, email string) (string, *model.AppError)
|
||||||
GetEtagForAllProfiles() string
|
GetEtagForAllProfiles() string
|
||||||
GetEtagForProfiles(teamId string) string
|
GetEtagForProfiles(teamId string) string
|
||||||
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
|
UpdateFailedPasswordAttempts(userId string, attempts int) *model.AppError
|
||||||
GetSystemAdminProfiles() (map[string]*model.User, *model.AppError)
|
GetSystemAdminProfiles() (map[string]*model.User, *model.AppError)
|
||||||
PermanentDelete(userId string) *model.AppError
|
PermanentDelete(userId string) *model.AppError
|
||||||
AnalyticsActiveCount(time int64) (int64, *model.AppError)
|
AnalyticsActiveCount(time int64) (int64, *model.AppError)
|
||||||
|
|||||||
@@ -1072,15 +1072,15 @@ func (_m *UserStore) UpdateAuthData(userId string, service string, authData *str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateFailedPasswordAttempts provides a mock function with given fields: userId, attempts
|
// UpdateFailedPasswordAttempts provides a mock function with given fields: userId, attempts
|
||||||
func (_m *UserStore) UpdateFailedPasswordAttempts(userId string, attempts int) store.StoreChannel {
|
func (_m *UserStore) UpdateFailedPasswordAttempts(userId string, attempts int) *model.AppError {
|
||||||
ret := _m.Called(userId, attempts)
|
ret := _m.Called(userId, attempts)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.AppError
|
||||||
if rf, ok := ret.Get(0).(func(string, int) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, int) *model.AppError); ok {
|
||||||
r0 = rf(userId, attempts)
|
r0 = rf(userId, attempts)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ func testUserStoreUpdateFailedPasswordAttempts(t *testing.T, ss store.Store) {
|
|||||||
defer func() { require.Nil(t, ss.User().PermanentDelete(u1.Id)) }()
|
defer func() { require.Nil(t, ss.User().PermanentDelete(u1.Id)) }()
|
||||||
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id}, -1))
|
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id}, -1))
|
||||||
|
|
||||||
if err := (<-ss.User().UpdateFailedPasswordAttempts(u1.Id, 3)).Err; err != nil {
|
if err := ss.User().UpdateFailedPasswordAttempts(u1.Id, 3); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user