-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b8c0c8
commit e2abe1c
Showing
47 changed files
with
3,627 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Auth\Events\Verified; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Http\RedirectResponse; | ||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Auth\Access\AuthorizationException; | ||
|
||
class EmailVerificationController extends Controller | ||
{ | ||
public function __invoke(string $id, string $hash): RedirectResponse | ||
{ | ||
if (!hash_equals((string) $id, (string) Auth::user()->getKey())) { | ||
throw new AuthorizationException(); | ||
} | ||
|
||
if (!hash_equals((string) $hash, sha1(Auth::user()->getEmailForVerification()))) { | ||
throw new AuthorizationException(); | ||
} | ||
|
||
if (Auth::user()->hasVerifiedEmail()) { | ||
return redirect(route('home')); | ||
} | ||
|
||
if (Auth::user()->markEmailAsVerified()) { | ||
event(new Verified(Auth::user())); | ||
} | ||
|
||
return redirect(route('home')); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Http\RedirectResponse; | ||
|
||
class LogoutController extends Controller | ||
{ | ||
public function __invoke(): RedirectResponse | ||
{ | ||
Auth::logout(); | ||
|
||
return redirect(route('home')); | ||
} | ||
} |
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
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,41 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Auth; | ||
|
||
use Illuminate\Support\Facades\Auth; | ||
use Livewire\Component; | ||
|
||
class Login extends Component | ||
{ | ||
/** @var string */ | ||
public $email = ''; | ||
|
||
/** @var string */ | ||
public $password = ''; | ||
|
||
/** @var bool */ | ||
public $remember = false; | ||
|
||
protected $rules = [ | ||
'email' => ['required', 'email'], | ||
'password' => ['required'], | ||
]; | ||
|
||
public function authenticate() | ||
{ | ||
$this->validate(); | ||
|
||
if (!Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) { | ||
$this->addError('email', trans('auth.failed')); | ||
|
||
return; | ||
} | ||
|
||
return redirect()->intended(route('home')); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.login')->extends('layouts.auth'); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Auth\Passwords; | ||
|
||
use Livewire\Component; | ||
|
||
class Confirm extends Component | ||
{ | ||
/** @var string */ | ||
public $password = ''; | ||
|
||
public function confirm() | ||
{ | ||
$this->validate([ | ||
'password' => 'required|current_password', | ||
]); | ||
|
||
session()->put('auth.password_confirmed_at', time()); | ||
|
||
return redirect()->intended(route('home')); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.passwords.confirm')->extends('layouts.auth'); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Auth\Passwords; | ||
|
||
use Livewire\Component; | ||
use Illuminate\Support\Facades\Password; | ||
|
||
class Email extends Component | ||
{ | ||
/** @var string */ | ||
public $email; | ||
|
||
/** @var string|null */ | ||
public $emailSentMessage = false; | ||
|
||
public function sendResetPasswordLink() | ||
{ | ||
$this->validate([ | ||
'email' => ['required', 'email'], | ||
]); | ||
|
||
$response = $this->broker()->sendResetLink(['email' => $this->email]); | ||
|
||
if ($response == Password::RESET_LINK_SENT) { | ||
$this->emailSentMessage = trans($response); | ||
|
||
return; | ||
} | ||
|
||
$this->addError('email', trans($response)); | ||
} | ||
|
||
/** | ||
* Get the broker to be used during password reset. | ||
* | ||
* @return \Illuminate\Contracts\Auth\PasswordBroker | ||
*/ | ||
public function broker() | ||
{ | ||
return Password::broker(); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.passwords.email')->extends('layouts.auth'); | ||
} | ||
} |
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,93 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Auth\Passwords; | ||
|
||
use App\Providers\RouteServiceProvider; | ||
use Livewire\Component; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Password; | ||
use Illuminate\Auth\Events\PasswordReset; | ||
|
||
class Reset extends Component | ||
{ | ||
/** @var string */ | ||
public $token; | ||
|
||
/** @var string */ | ||
public $email; | ||
|
||
/** @var string */ | ||
public $password; | ||
|
||
/** @var string */ | ||
public $passwordConfirmation; | ||
|
||
public function mount($token) | ||
{ | ||
$this->email = request()->query('email', ''); | ||
$this->token = $token; | ||
} | ||
|
||
public function resetPassword() | ||
{ | ||
$this->validate([ | ||
'token' => 'required', | ||
'email' => 'required|email', | ||
'password' => 'required|min:8|same:passwordConfirmation', | ||
]); | ||
|
||
$response = $this->broker()->reset( | ||
[ | ||
'token' => $this->token, | ||
'email' => $this->email, | ||
'password' => $this->password | ||
], | ||
function ($user, $password) { | ||
$user->password = Hash::make($password); | ||
|
||
$user->setRememberToken(Str::random(60)); | ||
|
||
$user->save(); | ||
|
||
event(new PasswordReset($user)); | ||
|
||
$this->guard()->login($user); | ||
} | ||
); | ||
|
||
if ($response == Password::PASSWORD_RESET) { | ||
session()->flash(trans($response)); | ||
|
||
return redirect(route('home')); | ||
} | ||
|
||
$this->addError('email', trans($response)); | ||
} | ||
|
||
/** | ||
* Get the broker to be used during password reset. | ||
* | ||
* @return \Illuminate\Contracts\Auth\PasswordBroker | ||
*/ | ||
public function broker() | ||
{ | ||
return Password::broker(); | ||
} | ||
|
||
/** | ||
* Get the guard to be used during password reset. | ||
* | ||
* @return \Illuminate\Contracts\Auth\StatefulGuard | ||
*/ | ||
protected function guard() | ||
{ | ||
return Auth::guard(); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.passwords.reset')->extends('layouts.auth'); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Auth; | ||
|
||
use App\Providers\RouteServiceProvider; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Auth\Events\Registered; | ||
use Livewire\Component; | ||
|
||
class Register extends Component | ||
{ | ||
/** @var string */ | ||
public $name = ''; | ||
|
||
/** @var string */ | ||
public $email = ''; | ||
|
||
/** @var string */ | ||
public $password = ''; | ||
|
||
/** @var string */ | ||
public $passwordConfirmation = ''; | ||
|
||
public function register() | ||
{ | ||
$this->validate([ | ||
'name' => ['required'], | ||
'email' => ['required', 'email', 'unique:users'], | ||
'password' => ['required', 'min:8', 'same:passwordConfirmation'], | ||
]); | ||
|
||
$user = User::create([ | ||
'email' => $this->email, | ||
'name' => $this->name, | ||
'password' => Hash::make($this->password), | ||
]); | ||
|
||
event(new Registered($user)); | ||
|
||
Auth::login($user, true); | ||
|
||
return redirect()->intended(route('home')); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.register')->extends('layouts.auth'); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Auth; | ||
|
||
use App\Providers\RouteServiceProvider; | ||
use Illuminate\Support\Facades\Auth; | ||
use Livewire\Component; | ||
|
||
class Verify extends Component | ||
{ | ||
public function resend() | ||
{ | ||
if (Auth::user()->hasVerifiedEmail()) { | ||
redirect(route('home')); | ||
} | ||
|
||
Auth::user()->sendEmailVerificationNotification(); | ||
|
||
$this->dispatch('resent'); | ||
|
||
session()->flash('resent'); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.verify')->extends('layouts.auth'); | ||
} | ||
} |
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
Oops, something went wrong.