2amigos / yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension
https://github.com/2amigos/yii2-usuario
Other
294 stars 142 forks source link

Update PasswordExpireService.php #533

Closed niciz closed 9 months ago

niciz commented 10 months ago

Fix PasswordExpireService return error when user model attribute "password_changed_at" is already set at null.

Q A
Is bugfix? yes
New feature? no
Breaks BC? no
Tests pass? yes
Fixed issues
maxxer commented 9 months ago

Out of curiosity, what error is it throwing?

Please add entry in changelog.

niciz commented 9 months ago

`

/**
 * Forces the user to change password at next login
 * @param integer $id
 */
public function actionForcePasswordChange($id)
{
    /** @var User $user */
    $user = $this->userQuery->where(['id' => $id])->one();
    if ($this->make(PasswordExpireService::class, [$user])->run()) {
        Yii::$app->session->setFlash("success", Yii::t('usuario', 'User will be required to change password at next login'));
    } else {
        Yii::$app->session->setFlash("danger", Yii::t('usuario', 'There was an error in saving user'));
    }
    $this->redirect(['index']);
}

`

Is AdminController::actionForcePasswordChange() which set an error flash message when PasswordExpireService return false. But there's no error in PasswordExpireService, because user already has "password_changed_at" at NULL.

maxxer commented 9 months ago

Ok. So the if in the patch is not really required, you could just run the updateAttributes and always return true.

maxxer commented 9 months ago

please add changelog, then I'll merge. thanks