121 lines
3.8 KiB
PHP
121 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Employer;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class EmployerAuthController extends Controller
|
|
{
|
|
public function showLogin()
|
|
{
|
|
return Inertia::render('Employer/Auth/Login');
|
|
}
|
|
|
|
public function login(Request $request)
|
|
{
|
|
$credentials = $request->validate([
|
|
'email' => ['required', 'email'],
|
|
'password' => ['required'],
|
|
]);
|
|
|
|
if ($credentials['email'] === 'pending@example.com') {
|
|
return back()->with('status', 'pending_verification');
|
|
}
|
|
|
|
if ($credentials['email'] === 'rejected@example.com') {
|
|
return back()->with([
|
|
'status' => 'rejected',
|
|
'reason' => 'Emirates ID scan was blurry or illegible. Please provide a high-resolution color scan.',
|
|
]);
|
|
}
|
|
|
|
if ($credentials['email'] === 'expired@example.com') {
|
|
return back()->with('status', 'subscription_expired');
|
|
}
|
|
|
|
if ($credentials['email'] === 'employer@example.com' && $credentials['password'] === 'password') {
|
|
session(['user' => (object)[
|
|
'id' => 2,
|
|
'name' => 'John Doe (Employer)',
|
|
'email' => 'employer@example.com',
|
|
'role' => 'employer',
|
|
'subscription_status' => 'active',
|
|
'verification_status' => 'approved',
|
|
]]);
|
|
|
|
$request->session()->regenerate();
|
|
|
|
if ($request->source === 'mobile') {
|
|
return redirect('/mobile/employer/home');
|
|
}
|
|
|
|
return redirect()->intended('/employer/dashboard');
|
|
}
|
|
|
|
return back()->withErrors([
|
|
'email' => 'Invalid credentials. Use employer@example.com (or test emails: pending@, rejected@, expired@ / password)',
|
|
]);
|
|
}
|
|
|
|
public function showRegister()
|
|
{
|
|
return Inertia::render('Employer/Auth/Register');
|
|
}
|
|
|
|
public function register(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'email' => 'required|string|email|max:255',
|
|
'phone' => 'required|string|max:25',
|
|
'password' => 'required|string|min:8',
|
|
'emirates_id_front' => 'required|file|mimes:jpg,png,pdf|max:5120',
|
|
'emirates_id_back' => 'required|file|mimes:jpg,png,pdf|max:5120',
|
|
]);
|
|
|
|
$frontPath = null;
|
|
$backPath = null;
|
|
|
|
if ($request->hasFile('emirates_id_front')) {
|
|
$frontPath = $request->file('emirates_id_front')->store('private/emirates-id', 'local');
|
|
}
|
|
|
|
if ($request->hasFile('emirates_id_back')) {
|
|
$backPath = $request->file('emirates_id_back')->store('private/emirates-id', 'local');
|
|
}
|
|
|
|
// Auto-approve registration since proof is provided
|
|
session(['user' => (object)[
|
|
'id' => 3,
|
|
'name' => $validated['name'],
|
|
'email' => $validated['email'],
|
|
'phone' => $validated['phone'],
|
|
'role' => 'employer',
|
|
'subscription_status' => 'active',
|
|
'verification_status' => 'approved',
|
|
]]);
|
|
|
|
if ($request->source === 'mobile') {
|
|
return redirect('/mobile/employer/home');
|
|
}
|
|
|
|
return redirect()->route('employer.dashboard')->with('success', 'Registration successful! Your account is verified and ready.');
|
|
}
|
|
|
|
public function verifyEmail($token)
|
|
{
|
|
return redirect()->route('employer.dashboard')->with('success', 'Email verified successfully.');
|
|
}
|
|
|
|
public function logout(Request $request)
|
|
{
|
|
session()->forget('user');
|
|
$request->session()->invalidate();
|
|
$request->session()->regenerateToken();
|
|
|
|
return redirect()->route('employer.login');
|
|
}
|
|
}
|