Changeset cf84baa for app


Ignore:
Timestamp:
02/08/24 16:15:01 (9 months ago)
Author:
bube-ristovska <ristovska725@…>
Branches:
main
Children:
6dec591
Parents:
6b10b67
Message:

Added querries half done

Location:
app/Http/Controllers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/OfficerController.php

    r6b10b67 rcf84baa  
    44
    55use App\Models\Policeman;
     6use Illuminate\Contracts\Auth\Authenticatable;
    67use Illuminate\Http\Request;
    78use Illuminate\Support\Facades\DB;
     
    2122        return view('register-policeman');
    2223    }
     24
     25
    2326}
  • app/Http/Controllers/PeopleController.php

    r6b10b67 rcf84baa  
    44
    55use Illuminate\Http\Request;
     6use Illuminate\Support\Facades\DB;
    67
    78class PeopleController extends Controller
    89{
    910    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        ]);
    1128    }
    1229}
  • app/Http/Controllers/SessionsController.php

    r6b10b67 rcf84baa  
    33namespace App\Http\Controllers;
    44
     5use App\Models\Officer;
    56use Illuminate\Http\Request;
     7use Illuminate\Support\Facades\Auth;
     8use Illuminate\Support\Facades\DB;
     9use Illuminate\Support\Facades\Session;
    610
    711class SessionsController extends Controller
    812{
    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    }
    1057}
Note: See TracChangeset for help on using the changeset viewer.