started work on OTP and disabled registration

This commit is contained in:
Kwesi Banson Jnr
2026-08-26 23:03:11 +00:00
parent 006a974044
commit ff66dbbabe
13 changed files with 938 additions and 3 deletions

View File

@@ -4,6 +4,9 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use App\Mail\LoginOtpMail;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Mail;
class LoginController extends Controller
{
@@ -37,4 +40,36 @@ class LoginController extends Controller
$this->middleware('guest')->except('logout');
$this->middleware('auth')->only('logout');
}
public function authenticate(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required',
]);
$staff = StaffMember::where('email', $request->email)->where('status', 'ACTIVE')->first();
// 1. Check if staff exists and password is correct
if ($staff && Hash::check($request->password, $staff->password)) {
// 2. Generate 6-digit OTP
$otp = rand(100000, 999999);
// 3. Save to database with 10-minute expiration
$staff->update([
'otp_code' => $otp,
'otp_expires_at' => now()->addMinutes(10)
]);
// 4. Send Email
Mail::to($staff->email)->send(new LoginOtpMail($otp));
// 5. Store staff ID in session
session(['otp_staff_id' => $staff->id]);
return redirect()->route('otp.verify');
}
return back()->withErrors(['email' => 'Invalid credentials or inactive account.']);
}
}