Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cholladay0816 committed Dec 27, 2023
2 parents e278aea + ebd5453 commit e4460da
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 8 deletions.
85 changes: 85 additions & 0 deletions app/Http/Livewire/DeleteUserForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Livewire;

use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;
use Laravel\Jetstream\Contracts\DeletesUsers;
use Livewire\Component;

class DeleteUserForm extends Component
{
/**
* Indicates if user deletion is being confirmed.
*
* @var bool
*/
public $confirmingUserDeletion = false;

/**
* The user's current password.
*
* @var string
*/
public $password = '';

/**
* Confirm that the user would like to delete their account.
*
* @return void
*/
public function confirmUserDeletion()
{
$this->resetErrorBag();

$this->password = '';

$this->dispatchBrowserEvent('confirming-delete-user');

$this->confirmingUserDeletion = true;
}

/**
* Delete the current user.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Jetstream\Contracts\DeletesUsers $deleter
* @param \Illuminate\Contracts\Auth\StatefulGuard $auth
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
*/
public function deleteUser(Request $request, DeletesUsers $deleter, StatefulGuard $auth)
{
$this->resetErrorBag();
if(Auth::user()->passwordSet()) {
if (!Hash::check($this->password, Auth::user()->password)) {
throw ValidationException::withMessages([
'password' => [__('This password does not match our records.')],
]);
}
}

$deleter->delete(Auth::user()->fresh());

$auth->logout();

if ($request->hasSession()) {
$request->session()->invalidate();
$request->session()->regenerateToken();
}

return redirect(config('fortify.redirects.logout') ?? '/');
}

/**
* Render the component.
*
* @return \Illuminate\View\View
*/
public function render()
{
return view('profile.delete-user-form');
}
}
11 changes: 8 additions & 3 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ public function addStrike($reason = 'No reason provided.')
//TODO: check for three, then suspend
}

public function gallery()
public function gallery(): HasMany
{
return $this->hasMany(Gallery::class);
}

public function reviews()
public function reviews(): HasMany
{
return $this->hasMany(Review::class);
}

public function ratings()
public function ratings(): HasManyThrough
{
return $this->hasManyThrough(Review::class, Commission::class, 'creator_id', 'commission_id');
}
Expand Down Expand Up @@ -414,4 +414,9 @@ function () {
}
);
}

public function passwordSet(): bool
{
return !(empty($this->password));
}
}
4 changes: 4 additions & 0 deletions app/Models/UserStatistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* The purpose of this model is to provide statistics about a user,
* primarily for the purpose of sorting a creator on the Explore page
*/
class UserStatistic extends Model
{
use HasFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*
Expand Down
3 changes: 2 additions & 1 deletion resources/views/profile/delete-user-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<x-slot name="content">
{{ __('Are you sure you want to delete your account? Once your account is deleted, all of its resources and data will be permanently deleted. Please enter your password to confirm you would like to permanently delete your account.') }}

@if(auth()->user()->passwordSet())
<div class="mt-4" x-data="{}" x-on:confirming-delete-user.window="setTimeout(() => $refs.password.focus(), 250)">
<x-jet-input type="password" class="mt-1 block w-3/4"
placeholder="{{ __('Password') }}"
Expand All @@ -36,6 +36,7 @@

<x-jet-input-error for="password" class="mt-2" />
</div>
@endif
</x-slot>

<x-slot name="footer">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/profile/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<x-jet-section-border />
@endif

@if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::updatePasswords()))
@if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::updatePasswords()) && $user->passwordSet())
<div class="mt-10 sm:mt-0">
@livewire('profile.update-password-form')
</div>
Expand Down Expand Up @@ -48,7 +48,7 @@
<x-jet-section-border />

<div class="mt-10 sm:mt-0">
@livewire('profile.delete-user-form')
@livewire('delete-user-form')
</div>
@endif
</div>
Expand Down

0 comments on commit e4460da

Please sign in to comment.