Skip to content

Commit

Permalink
Merge pull request ppy#10875 from nanaya/pass-active
Browse files Browse the repository at this point in the history
Mark user active on password reset
  • Loading branch information
notbakaneko authored Jan 19, 2024
2 parents 0a0e215 + 84fcf27 commit 02e6f70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/PasswordResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Libraries\User\PasswordResetData;
use App\Models\User;
use App\Models\UserAccountHistory;
use Carbon\CarbonImmutable;

class PasswordResetController extends Controller
{
Expand Down Expand Up @@ -124,6 +125,7 @@ public function update()
}

$user->validatePasswordConfirmation();
$params['user']['user_lastvisit'] = CarbonImmutable::now();
if ($user->update($params['user'])) {
$user->resetSessions();
$this->login($user);
Expand Down
24 changes: 24 additions & 0 deletions tests/Controllers/PasswordResetControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Libraries\User\PasswordResetData;
use App\Mail\PasswordReset;
use App\Models\User;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;

Expand Down Expand Up @@ -194,6 +195,29 @@ public function testUpdateChangedPasswordExternally()
$this->assertTrue($user->fresh()->checkPassword($newPassword));
}

public function testUpdateFromInactive(): void
{
$changeTime = CarbonImmutable::now()->subMinutes(1);
$user = User::factory()->create(['user_lastvisit' => $changeTime->subYears(10)]);

$key = $this->generateKey($user);

$newPassword = static::randomPassword();

$this->put($this->path(), [
'key' => $key,
'user' => [
'password' => $newPassword,
'password_confirmation' => $newPassword,
],
'username' => $user->username,
])->assertRedirect(route('home'));

$user = $user->fresh();
$this->assertTrue($user->checkPassword($newPassword));
$this->assertTrue($user->user_lastvisit->greaterThan($changeTime));
}

public function testUpdateInvalidUsername()
{
$user = User::factory()->create();
Expand Down

0 comments on commit 02e6f70

Please sign in to comment.