You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Pablo\Ae3auth\app\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
class InvalidateExpiredPasswordsCommand extends Command
|
|
{
|
|
protected $signature = 'ae3auth:invalidate-expired-passwords';
|
|
|
|
protected $description = 'Invalidate passwords when reach the expiration date';
|
|
|
|
public function handle(): void
|
|
{
|
|
try {
|
|
$userModel = config('ae3auth-config.user.user_model');
|
|
$users = $userModel::whereDate(
|
|
config('ae3auth-config.user.expires_password_column_name'), '<=', now()
|
|
)
|
|
->orWhereNull(config('ae3auth-config.user.expires_password_column_name'))
|
|
->get();
|
|
$forceChangePasswordColumnName = config('ae3auth-config.user.force_change_column_name');
|
|
\DB::beginTransaction();
|
|
$users->each(function ($user) use ($forceChangePasswordColumnName) {
|
|
tap($user, fn($model) => $model->update([
|
|
$forceChangePasswordColumnName => true
|
|
]));
|
|
});
|
|
\DB::commit();
|
|
$this->info(__('expirated_passwords_invalidated'));
|
|
} catch (\Exception $exception) {
|
|
\DB::rollBack();
|
|
$this->error(__('expirated_passwords_invalidated_error'));
|
|
}
|
|
}
|
|
}
|