-
Notifications
You must be signed in to change notification settings - Fork 1
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
d350d78
commit 1320e12
Showing
15 changed files
with
171 additions
and
60 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
|
@@ -71,17 +71,7 @@ public function store(Request $request): RedirectResponse | |
*/ | ||
public function store_client(Request $request): RedirectResponse | ||
{ | ||
dd($request->all()); | ||
/*array:7 [▼ // app/Http/Controllers/Auth/RegisteredUserController.php:73 | ||
"_token" => "8SSZoXpatAKSZRaDSOAEfdid3SbuC45fHlNeo0ym" | ||
"name" => "Raccoon" | ||
"email" => "[email protected]" | ||
"phone_number" => "88818912" | ||
"address" => "22" | ||
"password" => "222" | ||
"password_confirmation" => "2222" | ||
] | ||
*/ | ||
// Validate the request | ||
$request->validate([ | ||
"name" => ["required", "string", "max:255"], | ||
"email" => [ | ||
|
@@ -97,30 +87,41 @@ public function store_client(Request $request): RedirectResponse | |
"max:10", | ||
"unique:" . User::class, | ||
], | ||
"address" => ["required", "string"], | ||
"password" => ["required", "confirmed", Rules\Password::defaults()], | ||
]); | ||
|
||
// Validate the phone number | ||
$phone_number_validated = $this->validateNumber($request->phone_number); | ||
if (!$phone_number_validated) { | ||
return redirect()->back()->with("error", "Invalid phone number"); | ||
} | ||
|
||
// Create the user | ||
$user = User::create([ | ||
"name" => $request->name, | ||
"email" => $request->email, | ||
"role" => "client", | ||
"role" => "client", // Assign the role of client | ||
"phone_number" => $phone_number_validated, | ||
"password" => Hash::make($request->password), | ||
]); | ||
|
||
event(new Registered($user)); | ||
|
||
// Log in the new user | ||
Auth::login($user); | ||
$user->last_login_at = now(); | ||
|
||
//create a client | ||
// Create the client and associate it with the user | ||
$client = new Client([ | ||
"address" => $request->address, | ||
// TODO! add other client-specific fields | ||
// - Location data is useful for location-based services | ||
]); | ||
$user->client()->save($client); // Assuming you have a client relation defined on the User model | ||
|
||
return redirect(RouteServiceProvider::HOME); | ||
// Optionally, redirect with a success message | ||
return redirect(RouteServiceProvider::HOME)->with( | ||
"success", | ||
"Client account created successfully." | ||
); | ||
} | ||
|
||
private function validateNumber(mixed $phone_number): int|bool | ||
|
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,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class RoleMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next | ||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse | ||
*/ | ||
public function handle(Request $request, Closure $next, ...$roles) | ||
{ | ||
if (!Auth::check()) { | ||
return redirect("/login"); | ||
} | ||
|
||
$user = Auth::user(); | ||
|
||
if (in_array($user->role, $roles)) { | ||
return $next($request); | ||
} | ||
|
||
return redirect("/unauthorized"); | ||
} | ||
} |
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!--Check if there are any messages within the session--> | ||
@if(session('success')) | ||
<div class="alert rounded mt-3 alert-success"> | ||
{{ session('success') }} | ||
</div> | ||
@endif | ||
|
||
@if(session('error')) | ||
<div class="alert rounded mt-3 bg-red-500 alert-danger"> | ||
{{ session('error') }} | ||
</div> | ||
@endif | ||
|
||
@if ($errors->any()) | ||
<div class="alert rounded mt-3 bg-red-500 alert-danger"> | ||
<ul> | ||
@foreach ($errors->all() as $error) | ||
<li>{{ $error }}</li> | ||
@endforeach | ||
</ul> | ||
</div> | ||
@endif |
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,12 @@ | ||
<x-guest-layout> | ||
|
||
<div class="mb-4 text-sm text-gray-300"> | ||
{{ __('You are not authorized to access this page.') }} | ||
</div> | ||
|
||
<div class="mt-4 flex items-center justify-between"> | ||
<button> | ||
<a href="{{ route('dashboard') }}">Go Back</a> | ||
</button> | ||
</div> | ||
</x-guest-layout> |
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
Binary file not shown.
Binary file not shown.