-
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.
Rework blade component to replace it with VueJs in Inertia (#18)
- Loading branch information
Showing
243 changed files
with
7,354 additions
and
3,443 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
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
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
87 changes: 87 additions & 0 deletions
87
app/Http/Controllers/Auth/AuthenticatedSessionController.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,87 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Actions\StoreSpaceInSessionAction; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\Auth\LoginRequest; | ||
use App\Models\User; | ||
use App\Providers\RouteServiceProvider; | ||
use App\Repositories\LoginAttemptRepository; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Route; | ||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
use Nette\Schema\ValidationException; | ||
|
||
class AuthenticatedSessionController extends Controller | ||
{ | ||
private LoginAttemptRepository $loginAttemptRepository; | ||
|
||
public function __construct(LoginAttemptRepository $loginAttemptRepository) | ||
{ | ||
$this->loginAttemptRepository = $loginAttemptRepository; | ||
} | ||
|
||
/** | ||
* Display the login view. | ||
* | ||
* @return Response | ||
*/ | ||
public function create(): Response | ||
{ | ||
return Inertia::render('Auth/Login', [ | ||
'canResetPassword' => Route::has('password.request'), | ||
'status' => session('status'), | ||
]); | ||
} | ||
|
||
/** | ||
* Handle an incoming authentication request. | ||
* | ||
* @param LoginRequest $request | ||
* @return RedirectResponse | ||
* @throws \Illuminate\Validation\ValidationException | ||
*/ | ||
public function store(LoginRequest $request): RedirectResponse | ||
{ | ||
try { | ||
$request->authenticate(); | ||
|
||
$user = Auth::user(); | ||
$request->session()->regenerate(); | ||
$this->loginAttemptRepository->create($user->id, $request->ip(), false); | ||
if (count($user->spaces) > 0) { | ||
(new StoreSpaceInSessionAction())->execute($user->spaces[0]->id); | ||
} | ||
|
||
return redirect()->intended(RouteServiceProvider::HOME); | ||
} catch (ValidationException $validationException) { | ||
if ($request->input('email')) { | ||
$user = User::where('email', $request->input('email'))->first(); | ||
|
||
$this->loginAttemptRepository->create($user?->id, $request->ip(), true); | ||
} | ||
throw $validationException; | ||
} | ||
} | ||
|
||
/** | ||
* Destroy an authenticated session. | ||
* | ||
* @param Request $request | ||
* @return RedirectResponse | ||
*/ | ||
public function destroy(Request $request): RedirectResponse | ||
{ | ||
Auth::guard('web')->logout(); | ||
|
||
$request->session()->invalidate(); | ||
|
||
$request->session()->regenerateToken(); | ||
|
||
return redirect('/'); | ||
} | ||
} |
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\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Mail\ResetPassword; | ||
use App\Models\User; | ||
use App\Repositories\PasswordResetRepository; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\Str; | ||
use Inertia\Inertia; | ||
|
||
class PasswordResetLinkController extends Controller | ||
{ | ||
private PasswordResetRepository $passwordResetRepository; | ||
|
||
public function __construct(PasswordResetRepository $passwordResetRepository) | ||
{ | ||
$this->passwordResetRepository = $passwordResetRepository; | ||
} | ||
|
||
/** | ||
* Display the password reset link request view. | ||
* | ||
* @return \Inertia\Response | ||
*/ | ||
public function create(Request $request) | ||
{ | ||
return Inertia::render('Auth/ForgotPassword', [ | ||
'status' => session('status'), | ||
'token' => $request->get('token'), | ||
]); | ||
} | ||
|
||
/** | ||
* Handle an incoming password reset link request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\RedirectResponse | ||
* | ||
* @throws \Illuminate\Validation\ValidationException | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$request->validate(User::getValidationRulesForPasswordReset()); | ||
|
||
if ($request->input('email') && !$request->has('token')) { | ||
$email = $request->input('email'); | ||
|
||
$existingUser = User::where('email', $email)->first(); | ||
|
||
if ($existingUser) { | ||
$existingRecord = $this->passwordResetRepository->getByEmail($email); | ||
|
||
if (!$existingRecord) { | ||
$shippingToken = Str::random(100); | ||
|
||
$this->passwordResetRepository->create($email, $shippingToken); | ||
} else { | ||
$shippingToken = $existingRecord->token; | ||
} | ||
|
||
try { | ||
Mail::to($email)->queue(new ResetPassword($shippingToken)); | ||
} catch (\Exception $e) { | ||
} | ||
} | ||
|
||
$request->session()->flash('message', 'success'); | ||
return back(); | ||
} elseif ($request->has('token') && $request->has('password') && !$request->has('email')) { | ||
$token = $request->input('token'); | ||
$password = $request->input('password'); | ||
|
||
$record = $this->passwordResetRepository->getByToken($token); | ||
|
||
if ($record) { | ||
$user = User::where('email', $record->email)->first(); | ||
|
||
$user->update(['password' => Hash::make($password)]); | ||
} | ||
|
||
$this->passwordResetRepository->delete($token); | ||
$request->session()->flash('message', 'success'); | ||
return redirect() | ||
->route('login'); | ||
} | ||
|
||
return back(); | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Actions\CreateUserAction; | ||
use App\Actions\SendVerificationMailAction; | ||
use App\Actions\StoreSpaceInSessionAction; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Currency; | ||
use App\Models\User; | ||
use App\Providers\RouteServiceProvider; | ||
use App\Repositories\LoginAttemptRepository; | ||
use App\Repositories\SpaceRepository; | ||
use Illuminate\Auth\Events\Registered; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
|
||
class RegisteredUserController extends Controller | ||
{ | ||
private SpaceRepository $spaceRepository; | ||
private LoginAttemptRepository $loginAttemptRepository; | ||
|
||
public function __construct( | ||
SpaceRepository $spaceRepository, | ||
LoginAttemptRepository $loginAttemptRepository | ||
) { | ||
$this->spaceRepository = $spaceRepository; | ||
$this->loginAttemptRepository = $loginAttemptRepository; | ||
} | ||
|
||
/** | ||
* Display the registration view. | ||
* | ||
* @return Response | ||
*/ | ||
public function create(): Response | ||
{ | ||
if (config('app.disable_registration')) { | ||
abort(404); | ||
} | ||
|
||
return Inertia::render('Auth/Register', [ | ||
'currencies' => Currency::orderBy('name')->get() | ||
]); | ||
} | ||
|
||
/** | ||
* Handle an incoming registration request. | ||
* | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
if (config('app.disable_registration')) { | ||
abort(404); | ||
} | ||
|
||
$request->validate(User::getValidationRulesForRegistration()); | ||
$user = (new CreateUserAction())->execute($request->name, $request->email, $request->password); | ||
$space = $this->spaceRepository->create($request->currency, $user->name . '\'s Space'); | ||
$user->spaces()->attach($space->id, ['role' => 'admin']); | ||
|
||
event(new Registered($user)); | ||
|
||
Auth::login($user); | ||
|
||
$this->loginAttemptRepository->create($user->id, $request->ip(), false); | ||
|
||
(new StoreSpaceInSessionAction())->execute($user->spaces[0]->id); | ||
|
||
(new SendVerificationMailAction())->execute($user->id); | ||
|
||
return redirect(RouteServiceProvider::HOME); | ||
} | ||
} |
Oops, something went wrong.