Skip to content

Commit

Permalink
add option to disable username changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Dec 11, 2023
1 parent 2a0a93f commit c943a4b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
3 changes: 3 additions & 0 deletions app/Services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public function updateUsername($username, $user) {
DB::beginTransaction();

try {
if (!config('lorekeeper.settings.allow_username_changes')) {
throw new \Exception('Username changes are currently disabled.');
}
if (!$username) {
throw new \Exception('Please enter a username.');
}
Expand Down
9 changes: 7 additions & 2 deletions config/lorekeeper/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,17 @@

/*
|--------------------------------------------------------------------------
| User Username Change Cooldown
| User Username Changes
|--------------------------------------------------------------------------
|
| Cooldown period, in days, before a user can change their username again.
| allow_username_changes: Whether or not users can change their usernames.
| Set to 0 to disable.
|
| username_change_cooldown: Cooldown period, in days, before a user can change their username again.
| Set to 0 / null to disable.
|
*/

'allow_username_changes' => 0,
'username_change_cooldown' => 30,
];
52 changes: 27 additions & 25 deletions resources/views/account/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,37 @@
{!! Form::close() !!}
</div>

<div class="card p-3 mb-2">
<h3>Change Username</h3>
@if (config('lorekeeper.settings.username_change_cooldown'))
<div class="alert alert-info">
You can change your username once every {{ config('lorekeeper.settings.username_change_cooldown') }} days.
</div>
@if (Auth::user()->logs()->where('type', 'Username Change')->orderBy('created_at', 'desc')->first())
<div class="alert alert-warning">
You last changed your username on {{ Auth::user()->logs()->where('type', 'Username Change')->orderBy('created_at', 'desc')->first()->created_at->format('F jS, Y') }}.
<br />
<b>
You will be able to change your username again on
{{ Auth::user()->logs()->where('type', 'Username Change')->orderBy('created_at', 'desc')->first()->created_at->addDays(config('lorekeeper.settings.username_change_cooldown'))->format('F jS, Y') }}.
</b>
@if (config('lorekeeper.settings.allow_username_changes'))
<div class="card p-3 mb-2">
<h3>Change Username</h3>
@if (config('lorekeeper.settings.username_change_cooldown'))
<div class="alert alert-info">
You can change your username once every {{ config('lorekeeper.settings.username_change_cooldown') }} days.
</div>
@if (Auth::user()->logs()->where('type', 'Username Change')->orderBy('created_at', 'desc')->first())
<div class="alert alert-warning">
You last changed your username on {{ Auth::user()->logs()->where('type', 'Username Change')->orderBy('created_at', 'desc')->first()->created_at->format('F jS, Y') }}.
<br />
<b>
You will be able to change your username again on
{{ Auth::user()->logs()->where('type', 'Username Change')->orderBy('created_at', 'desc')->first()->created_at->addDays(config('lorekeeper.settings.username_change_cooldown'))->format('F jS, Y') }}.
</b>
</div>
@endif
@endif
@endif
{!! Form::open(['url' => 'account/username']) !!}
<div class="form-group row">
<label class="col-md-2 col-form-label">Username</label>
<div class="col-md-10">
{!! Form::text('username', Auth::user()->name, ['class' => 'form-control']) !!}
{!! Form::open(['url' => 'account/username']) !!}
<div class="form-group row">
<label class="col-md-2 col-form-label">Username</label>
<div class="col-md-10">
{!! Form::text('username', Auth::user()->name, ['class' => 'form-control']) !!}
</div>
</div>
<div class="text-right">
{!! Form::submit('Edit', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
<div class="text-right">
{!! Form::submit('Edit', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
@endif

<div class="card p-3 mb-2">
<h3>Profile</h3>
Expand Down

0 comments on commit c943a4b

Please sign in to comment.