Skip to content

Commit

Permalink
Multi-auth
Browse files Browse the repository at this point in the history
-added new guard 'company'
-added new provider 'companies'
-set guard for Company model to company
-set middleware for CompanyController to auth:company
-created Route for register Company view
-created register Company view
  • Loading branch information
Daniel-Rdot committed Feb 22, 2023
1 parent 31cf7d4 commit 098e23c
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 18 deletions.
7 changes: 6 additions & 1 deletion app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

class CompanyController extends Controller
{
public function __construct()
{
$this->middleware('auth:company');
}

public function create()
{
return view('users.register');
return view('companies.register');
}
}
2 changes: 2 additions & 0 deletions app/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Company extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;

protected $guard = 'company';

/**
* The attributes that are mass assignable.
*
Expand Down
18 changes: 18 additions & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'company' => [
'driver' => 'session',
'provider' => 'companies',
],
],

/*
Expand All @@ -64,6 +72,10 @@
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'companies' => [
'driver' => 'eloquent',
'model' => App\Models\Company::class,
],

// 'users' => [
// 'driver' => 'database',
Expand Down Expand Up @@ -97,6 +109,12 @@
'expire' => 60,
'throttle' => 60,
],
'companies' => [
'provider' => 'companies',
'table' => 'password_reset_tokens',
'expire' => 60,
'throttle' => 60,
],
],

/*
Expand Down
91 changes: 91 additions & 0 deletions resources/views/companies/register.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<x-layout>
<div
class="bg-gray-50 border border-gray-200 p-10 rounded max-w-lg mx-auto mt-24">
<header class="text-center">
<h2 class="text-2xl font-bold uppercase mb-1">
Registrieren
</h2>
<p class="mb-4">Erstelle einen Firmenaccount, um Stellenanzeigen aufzugeben</p>
</header>

<form method="POST" action="/companies">
@csrf
<div class="mb-6">
<label for="name" class="inline-block text-lg mb-2">
Name
</label>
<input
type="text"
class="border border-gray-200 rounded p-2 w-full"
name="name"
value="{{old('name')}}"
/>
@error('name')
<p class="text-red-500 text-xs mt-1">{{$message}}</p>
@enderror
</div>

<div class="mb-6">
<label for="email" class="inline-block text-lg mb-2"
>Email</label
>
<input
type="email"
class="border border-gray-200 rounded p-2 w-full"
name="email"
value="{{old('email')}}"
/>
@error('email')
<p class="text-red-500 text-xs mt-1">{{$message}}</p>
@enderror
</div>

<div class="mb-6">
<label
for="password"
class="inline-block text-lg mb-2">
Passwort
</label>
<input
type="password"
class="border border-gray-200 rounded p-2 w-full"
name="password"
/>
@error('password')
<p class="text-red-500 text-xs mt-1">{{$message}}</p>
@enderror
</div>

<div class="mb-6">
<label
for="password2"
class="inline-block text-lg mb-2">
Passwort bestätigen
</label>
<input
type="password"
class="border border-gray-200 rounded p-2 w-full"
name="password_confirmation"
/>
@error('password_confirmation')
<p class="text-red-500 text-xs mt-1">{{$message}}</p>
@enderror
</div>

<div class="mb-6">
<button
type="submit"
class="bg-laravel text-white rounded py-2 px-4 hover:bg-black">
Erstellen
</button>
</div>

<div class="mt-8">
<p>
Du hast bereits einen Account?
<a href="/login" class="text-laravel">Einloggen</a>
</p>
</div>
</form>
</div>
</x-layout>
32 changes: 27 additions & 5 deletions resources/views/components/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,24 @@
{{-- auth helper can access user attributes--}}
Willkommen {{auth()->user()->name}}
</span>

</li>
@auth('company')
<li>
<a href="/listings/manage" class="hover:text-laravel">
<i class="fa-solid fa-object-group"></i> Stellenanzeigen verwalten
</a>
</li>
<li>
<a href="/companies/settings" class="hover:text-laravel">
<i class="fa-solid fa-gear"></i> Accountdetails
</a>
</li>
@endauth
<li>
<a href="/listings/manage" class="hover:text-laravel"
><i class="fa-solid fa-gear"></i> Stellenanzeigen verwalten</a>
<a href="/users/settings" class="hover:text-laravel">
<i class="fa-solid fa-gear"></i> Accountdetails
</a>
</li>
<li>
<form class="inline" method="POST" action="/logout">
Expand All @@ -51,6 +65,13 @@
</form>
</li>
@else
<li>
<span class="font-bold uppercase">
{{-- auth helper can access user attributes--}}
Auf der Suche nach deinem Traumjob? <i class="fa fa-long-arrow-right" aria-hidden="true"></i>
</span>

</li>
<li>
<a href="/register" class="hover:text-laravel"
><i class="fa-solid fa-user-plus"></i> Registrieren</a>
Expand All @@ -68,9 +89,10 @@
<footer
class="fixed bottom-0 left-0 w-full flex items-center justify-start font-bold bg-laravel text-white h-24 mt-24 opacity-90 md:justify-center">
<p class="ml-2">Copyright &copy; 2022, All Rights reserved</p>

<a href="/listings/create"
class="absolute top-1/3 right-10 bg-black text-white py-2 px-5">Neue Jobanzeige</a>
@auth('company')
<a href="/listings/create"
class="absolute top-1/3 right-10 bg-black text-white py-2 px-5">Neue Jobanzeige</a>
@endauth
</footer>
<x-flash-message/>
</body>
Expand Down
14 changes: 8 additions & 6 deletions resources/views/partials/_hero.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class="absolute top-0 left-0 w-full h-full opacity-10 bg-no-repeat bg-center"
<p class="text-2xl text-gray-200 font-bold my-4">
Finde deinen neuen Job - oder Mitarbeiter
</p>
<div>
<a href="register/company"
class="inline-block border-2 border-white text-white py-2 px-4 rounded-xl uppercase mt-2 hover:text-black hover:border-black">
Registriere dein Unternehmen hier, um eine Anzeige aufzugeben
</a>
</div>
@guest
<div>
<a href="register/company"
class="inline-block border-2 border-white text-white py-2 px-4 rounded-xl uppercase mt-2 hover:text-black hover:border-black">
Registriere dein Unternehmen hier, um eine Anzeige aufzugeben
</a>
</div>
@endguest
</div>
</section>
5 changes: 1 addition & 4 deletions resources/views/users/login.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<x-layout>
<div
class="bg-gray-50 border border-gray-200 p-10 rounded max-w-lg mx-auto mt-24"
>
<div class="bg-gray-50 border border-gray-200 p-10 rounded max-w-lg mx-auto mt-24">
<header class="text-center">
<h2 class="text-2xl font-bold uppercase mb-1">
Login
</h2>
<p class="mb-4">Logge dich ein, um Anzeigen aufzugeben</p>
</header>

<form method="POST" action="/users/authenticate">
Expand Down
5 changes: 3 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Route::get('/', [ListingController::class, 'index']);

// Show Create Form
Route::get('/listings/create', [ListingController::class, 'create'])->middleware('auth');
Route::get('/listings/create', [ListingController::class, 'create'])->middleware('auth:company');

// Create new Listing / Store
Route::post('/listings/', [ListingController::class, 'store'])->middleware('auth');
Expand Down Expand Up @@ -66,6 +66,7 @@
Route::post('/users/authenticate', [UserController::class, 'authenticate']);

// Show Register/Create Company Form
Route::get('/register/company', [CompanyController::class, 'create'])->middleware('auth');
Route::get('/register/company', [CompanyController::class, 'create']);


// TO-DO: user/company settings/details

0 comments on commit 098e23c

Please sign in to comment.