- Timestamp:
- 02/08/24 16:15:01 (11 months ago)
- Branches:
- main
- Children:
- 6dec591
- Parents:
- 6b10b67
- Location:
- app/Http/Controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/OfficerController.php
r6b10b67 rcf84baa 4 4 5 5 use App\Models\Policeman; 6 use Illuminate\Contracts\Auth\Authenticatable; 6 7 use Illuminate\Http\Request; 7 8 use Illuminate\Support\Facades\DB; … … 21 22 return view('register-policeman'); 22 23 } 24 25 23 26 } -
app/Http/Controllers/PeopleController.php
r6b10b67 rcf84baa 4 4 5 5 use Illuminate\Http\Request; 6 use Illuminate\Support\Facades\DB; 6 7 7 8 class PeopleController extends Controller 8 9 { 9 10 function filter(){ 10 return view('filter'); 11 $peoples = DB::select('select * from people;'); 12 13 return view('filter', [ 14 'peoples' => $peoples 15 ]); 16 } 17 function filter_post(){ 18 $credentials = request()->validate([ 19 'embg' => 'required' 20 ]); 21 $embg = $credentials['embg']; 22 23 $peoples = DB::select('SELECT * FROM people WHERE embg ~ :embg', ['embg' => '^' . $embg]); 24 25 return view('filter', [ 26 'peoples' => $peoples 27 ]); 11 28 } 12 29 } -
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.