source: app/Http/Controllers/SessionsController.php@ 6dec591

main
Last change on this file since 6dec591 was 6dec591, checked in by bube-ristovska <ristovska725@…>, 9 months ago

Cases listing

  • Property mode set to 100644
File size: 1.9 KB
Line 
1<?php
2
3namespace App\Http\Controllers;
4
5use App\Models\Officer;
6use Illuminate\Http\Request;
7use Illuminate\Support\Facades\Auth;
8use Illuminate\Support\Facades\DB;
9use Illuminate\Support\Facades\Session;
10
11class SessionsController extends Controller
12{
13 public function store()
14 {
15 $credentials = request()->validate([
16 'badge_no' => 'required',
17 'password' => 'required'
18 ]);
19 $password = $credentials['password'];
20 $badge_no = $credentials['badge_no'];
21 $policeman = true;
22 $exists = DB::select('select * from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]);
23 $pass = DB::select('select p_password from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]);
24 if($exists == null) {
25 $exists = DB::select('select * from officer where o_badge_no = :badge_no;', ['badge_no' => $badge_no]);
26 $pass = DB::select('select o_password from officer where o_badge_no = :badge_no;', ['badge_no' => $badge_no]);
27 $policeman = false;
28 }
29 if($exists == null) {
30 return back()->withErrors(['badge_no' => 'Invalid credentials']);
31 }
32
33 foreach ($pass[0] as $key => $val) {
34 $value = $val;
35 break; // Break after the first key-value pair
36 }
37
38
39 if ($value == $password) {
40 // Authentication passed
41 Session::put('badge_no', $badge_no);
42 Session::put('is_policeman', $policeman);
43 Session::put('pe_id', $exists[0]->pe_id);
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 }
57}
Note: See TracBrowser for help on using the repository browser.