Skip to content

Commit

Permalink
adding tall stack
Browse files Browse the repository at this point in the history
  • Loading branch information
diegogit03 committed Jan 13, 2024
1 parent 3b8c0c8 commit e2abe1c
Show file tree
Hide file tree
Showing 47 changed files with 3,627 additions and 162 deletions.
34 changes: 34 additions & 0 deletions app/Http/Controllers/Auth/EmailVerificationController.php
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'));
}
}
18 changes: 18 additions & 0 deletions app/Http/Controllers/Auth/LogoutController.php
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'));
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp

foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
return redirect(route('home'));
}
}

Expand Down
41 changes: 41 additions & 0 deletions app/Livewire/Auth/Login.php
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');
}
}
27 changes: 27 additions & 0 deletions app/Livewire/Auth/Passwords/Confirm.php
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');
}
}
47 changes: 47 additions & 0 deletions app/Livewire/Auth/Passwords/Email.php
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');
}
}
93 changes: 93 additions & 0 deletions app/Livewire/Auth/Passwords/Reset.php
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');
}
}
51 changes: 51 additions & 0 deletions app/Livewire/Auth/Register.php
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');
}
}
28 changes: 28 additions & 0 deletions app/Livewire/Auth/Verify.php
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');
}
}
2 changes: 1 addition & 1 deletion app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
*
* @var string
*/
public const HOME = '/home';
public const HOME = '/';

/**
* Define your route model bindings, pattern filters, and other route configuration.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel-frontend-presets/tall": "^7.0",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8"
"laravel/tinker": "^2.8",
"livewire/livewire": "^3.3"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand Down
Loading

0 comments on commit e2abe1c

Please sign in to comment.