Skip to content

Commit 43079fb

Browse files
authored
Merge pull request #11135 from nanaya/inactive-always
Add option to always reset password of inactive users
2 parents 97997d9 + 12061fd commit 43079fb

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

Diff for: .env.example

+13-10
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ CLIENT_CHECK_VERSION=false
265265
# NOTIFICATION_CLEANUP_MAX_DELETE=50000
266266

267267
# The open source bounty info page/form url
268-
#OS_BOUNTY_URL=http://example.com/bounty_form
268+
# OS_BOUNTY_URL=http://example.com/bounty_form
269269

270270
# OAUTH_MAX_USER_CLIENTS=1
271271

@@ -292,16 +292,16 @@ CLIENT_CHECK_VERSION=false
292292
# PAGINATION_MAX_COUNT=10000
293293

294294
## Limits for the allowed number of simultaneous beatmapset uploads (displayed on the support page: /home/support)
295-
#BEATMAPSET_UPLOAD_ALLOWED=4
296-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED=1
297-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX=2
298-
#BEATMAPSET_UPLOAD_ALLOWED_SUPPORTER=8
299-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED_SUPPORTER=1
300-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX_SUPPORTER=12
295+
# BEATMAPSET_UPLOAD_ALLOWED=4
296+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED=1
297+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX=2
298+
# BEATMAPSET_UPLOAD_ALLOWED_SUPPORTER=8
299+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED_SUPPORTER=1
300+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX_SUPPORTER=12
301301

302-
#RECAPTCHA_SECRET=
303-
#RECAPTCHA_SITEKEY=
304-
#RECAPTCHA_THRESHOLD=
302+
# RECAPTCHA_SECRET=
303+
# RECAPTCHA_SITEKEY=
304+
# RECAPTCHA_THRESHOLD=
305305

306306
# TWITCH_CLIENT_ID=
307307
# TWITCH_CLIENT_SECRET=
@@ -336,3 +336,6 @@ CLIENT_CHECK_VERSION=false
336336

337337
# USER_COUNTRY_CHANGE_MAX_MIXED_MONTHS=2
338338
# USER_COUNTRY_CHANGE_MIN_MONTHS=6
339+
340+
# USER_INACTIVE_DAYS_VERIFICATION=180
341+
# USER_INACTIVE_FORCE_PASSWORD_RESET=false

Diff for: app/Libraries/User/ForceReactivation.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class ForceReactivation
1515
{
16+
const INACTIVE = 'inactive';
1617
const INACTIVE_DIFFERENT_COUNTRY = 'inactive_different_country';
1718

1819
private $country;
@@ -27,8 +28,12 @@ public function __construct($user, $request)
2728

2829
$this->country = request_country($this->request);
2930

30-
if ($this->user->isInactive() && $this->user->country_acronym !== $this->country) {
31-
$this->reason = static::INACTIVE_DIFFERENT_COUNTRY;
31+
if ($this->user->isInactive()) {
32+
if ($this->user->country_acronym !== $this->country) {
33+
$this->reason = static::INACTIVE_DIFFERENT_COUNTRY;
34+
} elseif ($GLOBALS['cfg']['osu']['user']['inactive_force_password_reset']) {
35+
$this->reason = static::INACTIVE;
36+
}
3237
}
3338
}
3439

@@ -62,9 +67,11 @@ public function run()
6267

6368
private function addHistoryNote()
6469
{
65-
if ($this->reason === static::INACTIVE_DIFFERENT_COUNTRY) {
66-
$message = "First login after {$this->user->user_lastvisit->diffInDays()} days from {$this->country}. Forcing password reset.";
67-
}
70+
$message = match ($this->reason) {
71+
static::INACTIVE => "First login after {$this->user->user_lastvisit->diffInDays()} days. Forcing password reset.",
72+
static::INACTIVE_DIFFERENT_COUNTRY => "First login after {$this->user->user_lastvisit->diffInDays()} days from {$this->country}. Forcing password reset.",
73+
default => null,
74+
};
6875

6976
if ($message !== null) {
7077
UserAccountHistory::addNote($this->user, $message);

Diff for: config/osu.php

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
'allowed_rename_groups' => explode(' ', env('USER_ALLOWED_RENAME_GROUPS', 'default')),
248248
'bypass_verification' => get_bool(env('USER_BYPASS_VERIFICATION')) ?? false,
249249
'hide_pinned_solo_scores' => get_bool(env('USER_HIDE_PINNED_SOLO_SCORES')) ?? true,
250+
'inactive_force_password_reset' => get_bool(env('USER_INACTIVE_FORCE_PASSWORD_RESET') ?? false),
250251
'inactive_seconds_verification' => (get_int(env('USER_INACTIVE_DAYS_VERIFICATION')) ?? 180) * 86400,
251252
'min_plays_for_posting' => get_int(env('USER_MIN_PLAYS_FOR_POSTING')) ?? 10,
252253
'min_plays_allow_verified_bypass' => get_bool(env('USER_MIN_PLAYS_ALLOW_VERIFIED_BYPASS')) ?? true,

Diff for: resources/lang/en/users.php

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797

9898
'force_reactivation' => [
9999
'reason' => [
100+
'inactive' => "Your account hasn't been used in a long time.",
100101
'inactive_different_country' => "Your account hasn't been used in a long time.",
101102
],
102103
],

Diff for: tests/Controllers/SessionsControllerTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ public function testLoginInactiveUser()
4545
$this->get(route('home'))->assertStatus(401);
4646
}
4747

48+
public function testLoginInactiveUserForceReset(): void
49+
{
50+
config_set('osu.user.inactive_force_password_reset', true);
51+
52+
$password = 'password1';
53+
$countryAcronym = (Country::first() ?? Country::factory()->create())->getKey();
54+
$user = User::factory()->create(['password' => $password, 'country_acronym' => $countryAcronym]);
55+
$user->update(['user_lastvisit' => time() - $GLOBALS['cfg']['osu']['user']['inactive_seconds_verification'] - 1]);
56+
57+
$this->post(route('login'), [
58+
'username' => $user->username,
59+
'password' => $password,
60+
], [
61+
'CF_IPCOUNTRY' => $countryAcronym,
62+
])->assertStatus(302);
63+
64+
$this->assertGuest();
65+
}
66+
4867
public function testLoginInactiveUserDifferentCountry()
4968
{
5069
$password = 'password1';

0 commit comments

Comments
 (0)