-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4063 from Roardom/password-reset-history
(Add) Password reset history logging
- Loading branch information
Showing
14 changed files
with
363 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/Http/Controllers/Staff/PasswordResetHistoryController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* NOTICE OF LICENSE. | ||
* | ||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0 | ||
* The details is bundled with this project in the file LICENSE.txt. | ||
* | ||
* @project UNIT3D Community Edition | ||
* | ||
* @author Roardom <[email protected]> | ||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 | ||
*/ | ||
|
||
namespace App\Http\Controllers\Staff; | ||
|
||
use App\Http\Controllers\Controller; | ||
|
||
class PasswordResetHistoryController extends Controller | ||
{ | ||
/** | ||
* Display all user password reset histories. | ||
*/ | ||
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
{ | ||
return view('Staff.password-reset-history.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* NOTICE OF LICENSE. | ||
* | ||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0 | ||
* The details is bundled with this project in the file LICENSE.txt. | ||
* | ||
* @project UNIT3D Community Edition | ||
* | ||
* @author Roardom <[email protected]> | ||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 | ||
*/ | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Models\PasswordResetHistory; | ||
use App\Models\User; | ||
use App\Traits\LivewireSort; | ||
use Livewire\Attributes\Computed; | ||
use Livewire\Attributes\Url; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
/** | ||
* @property \Illuminate\Contracts\Pagination\LengthAwarePaginator<PasswordResetHistory> $passwordResetHistories | ||
*/ | ||
class PasswordResetHistorySearch extends Component | ||
{ | ||
use LivewireSort; | ||
use WithPagination; | ||
|
||
#TODO: Update URL attributes once Livewire 3 fixes upstream bug. See: https://github.com/livewire/livewire/discussions/7746 | ||
|
||
#[Url(history: true)] | ||
public string $username = ''; | ||
|
||
#[Url(history: true)] | ||
public string $sortField = 'created_at'; | ||
|
||
#[Url(history: true)] | ||
public string $sortDirection = 'desc'; | ||
|
||
#[Url(history: true)] | ||
public int $perPage = 25; | ||
|
||
/** | ||
* @return \Illuminate\Pagination\LengthAwarePaginator<PasswordResetHistory> | ||
*/ | ||
#[Computed] | ||
final public function passwordResetHistories(): \Illuminate\Pagination\LengthAwarePaginator | ||
{ | ||
return PasswordResetHistory::with([ | ||
'user' => fn ($query) => $query->withTrashed()->with('group'), | ||
]) | ||
->when($this->username, fn ($query) => $query->whereIn('user_id', User::withTrashed()->select('id')->where('username', 'LIKE', '%'.$this->username.'%'))) | ||
->orderBy($this->sortField, $this->sortDirection) | ||
->paginate($this->perPage); | ||
} | ||
|
||
final public function render(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application | ||
{ | ||
return view('livewire.password-reset-history-search', [ | ||
'passwordResetHistories' => $this->passwordResetHistories, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class PasswordResetHistory extends Model | ||
{ | ||
/** | ||
* Indicates If The Model Should Be Timestamped. | ||
* | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
|
||
/** | ||
* The attributes that aren't mass assignable. | ||
* | ||
* @var string[] | ||
*/ | ||
protected $guarded = ['id']; | ||
|
||
/** | ||
* Get the attributes that should be cast. | ||
* | ||
* @return array{created_at: 'datetime'} | ||
*/ | ||
protected function casts(): array | ||
{ | ||
return [ | ||
'created_at' => 'datetime', | ||
]; | ||
} | ||
|
||
/** | ||
* Has Many Torrents. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, $this> | ||
*/ | ||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
database/migrations/2024_08_17_140412_create_password_reset_history.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* NOTICE OF LICENSE. | ||
* | ||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0 | ||
* The details is bundled with this project in the file LICENSE.txt. | ||
* | ||
* @project UNIT3D Community Edition | ||
* | ||
* @author HDVinnie <[email protected]> | ||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 | ||
*/ | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('password_reset_histories', function (Blueprint $table): void { | ||
$table->increments('id'); | ||
$table->unsignedInteger('user_id'); | ||
$table->timestamp('created_at')->nullable()->useCurrent(); | ||
|
||
$table->foreign('user_id')->references('id')->on('users')->cascadeOnUpdate(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
resources/views/Staff/password-reset-history/index.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@extends('layout.default') | ||
|
||
@section('title') | ||
<title> | ||
{{ __('common.user') }} {{ __('user.password-resets') }} - | ||
{{ __('staff.staff-dashboard') }} - {{ config('other.title') }} | ||
</title> | ||
@endsection | ||
|
||
@section('meta') | ||
<meta | ||
name="description" | ||
content="{{ __('user.password-resets') }} - {{ __('staff.staff-dashboard') }}" | ||
/> | ||
@endsection | ||
|
||
@section('breadcrumbs') | ||
<li class="breadcrumbV2"> | ||
<a href="{{ route('staff.dashboard.index') }}" class="breadcrumb__link"> | ||
{{ __('staff.staff-dashboard') }} | ||
</a> | ||
</li> | ||
<li class="breadcrumb--active"> | ||
{{ __('user.password-resets') }} | ||
</li> | ||
@endsection | ||
|
||
@section('page', 'page__password-reset-history-log--index') | ||
|
||
@section('main') | ||
@livewire('password-reset-history-search') | ||
@endsection |
69 changes: 69 additions & 0 deletions
69
resources/views/livewire/password-reset-history-search.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<section class="panelV2"> | ||
<header class="panel__header"> | ||
<h2 class="panel__heading">{{ __('user.password-resets') }}</h2> | ||
<div class="panel__actions"> | ||
<div class="panel__action"> | ||
<div class="form__group"> | ||
<input | ||
id="username" | ||
class="form__text" | ||
type="text" | ||
wire:model.live="username" | ||
placeholder=" " | ||
/> | ||
<label class="form__label form__label--floating" for="username"> | ||
{{ __('common.username') }} | ||
</label> | ||
</div> | ||
</div> | ||
<div class="panel__action"> | ||
<div class="form__group"> | ||
<select id="quantity" class="form__select" wire:model="perPage" required> | ||
<option>25</option> | ||
<option>50</option> | ||
<option>100</option> | ||
</select> | ||
<label class="form__label form__label--floating" for="quantity"> | ||
{{ __('common.quantity') }} | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
</header> | ||
<div class="data-table-wrapper"> | ||
<table class="data-table"> | ||
<tbody> | ||
<tr> | ||
<th wire:click="sortBy('user_id')" role="columnheader button"> | ||
{{ __('common.username') }} | ||
@include('livewire.includes._sort-icon', ['field' => 'user_id']) | ||
</th> | ||
<th wire:click="sortBy('created_at')" role="columnheader button"> | ||
{{ __('common.created_at') }} | ||
@include('livewire.includes._sort-icon', ['field' => 'created_at']) | ||
</th> | ||
</tr> | ||
@forelse ($passwordResetHistories as $passwordResetHistory) | ||
<tr> | ||
<td> | ||
<x-user_tag :user="$passwordResetHistory->user" :anon="false" /> | ||
</td> | ||
<td> | ||
<time | ||
datetime="{{ $passwordResetHistory->created_at }}" | ||
title="{{ $passwordResetHistory->created_at }}" | ||
> | ||
{{ $passwordResetHistory->created_at }} | ||
</time> | ||
</td> | ||
</tr> | ||
@empty | ||
<tr> | ||
<td colspan="4">No Password Resets</td> | ||
</tr> | ||
@endforelse | ||
</tbody> | ||
</table> | ||
</div> | ||
{{ $passwordResetHistories->links('partials.pagination') }} | ||
</section> |
Oops, something went wrong.