Changeset cf84baa for app/Http/Controllers/SessionsController.php
- Timestamp:
- 02/08/24 16:15:01 (9 months ago)
- Branches:
- main
- Children:
- 6dec591
- Parents:
- 6b10b67
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/SessionsController.php
r6b10b67 rcf84baa 3 3 namespace App\Http\Controllers; 4 4 5 use App\Models\Officer; 5 6 use Illuminate\Http\Request; 7 use Illuminate\Support\Facades\Auth; 8 use Illuminate\Support\Facades\DB; 9 use Illuminate\Support\Facades\Session; 6 10 7 11 class SessionsController extends Controller 8 12 { 9 // 13 public function store() 14 { 15 16 $credentials = request()->validate([ 17 'badge_no' => 'required', 18 'password' => 'required' 19 ]); 20 $password = $credentials['password']; 21 $badge_no = $credentials['badge_no']; 22 $policeman = true; 23 $exists = DB::select('select * from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]); 24 $pass = DB::select('select p_password from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]); 25 if($exists == null) { 26 $exists = DB::select('select * from officer where o_badge_no = :badge_no;', ['badge_no' => $badge_no]); 27 $pass = DB::select('select o_password from officer where o_badge_no = :badge_no;', ['badge_no' => $badge_no]); 28 $policeman = false; 29 } 30 if($exists == null) { 31 return back()->withErrors(['badge_no' => 'Invalid credentials']); 32 } 33 34 foreach ($pass[0] as $key => $val) { 35 $value = $val; 36 break; // Break after the first key-value pair 37 } 38 39 40 if ($value == $password) { 41 // Authentication passed 42 Session::put('badge_no', $badge_no); 43 Session::put('is_policeman', $policeman); 44 return redirect()->intended('/'); 45 } 46 47 // Authentication failed 48 return back()->withErrors(['password' => 'Invalid credentials']); 49 } 50 51 public function logout() 52 { 53 Session::forget('badge_no'); 54 Session::forget('is_policeman'); 55 return redirect('/login'); 56 } 10 57 }
Note:
See TracChangeset
for help on using the changeset viewer.