Ignore:
Timestamp:
08/26/24 12:43:09 (4 months ago)
Author:
bube-ristovska <ristovska725@…>
Branches:
main
Children:
092fcda
Parents:
768f473
Message:

Corrected authentication

File:
1 edited

Legend:

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

    r768f473 r69e9f5d  
    1919        $password = $credentials['password'];
    2020        $badge_no = $credentials['badge_no'];
     21        // mozhe da se najavi kako policaec i kako officer, znaeme koj e koj po znachkata
     22
    2123        $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]);
     24        $is_policeman = DB::select('select * from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]);
     25        $is_officer = DB::select('select * from officer where o_badge_no = :badge_no;', ['badge_no' => $badge_no]);
     26        if($is_officer==null && $is_policeman==null) {
     27            return back()->withErrors(['password' => 'Invalid credentials']);
     28        }
     29        if($is_officer!=null) {
     30            $pass = DB::select('select o_password from officer where o_badge_no = :o_badge_no;', ['o_badge_no' => $badge_no]);
    2731            $policeman = false;
    28         }
    29         if($exists == null) {
    30             return back()->withErrors(['badge_no' => 'Invalid badge_no']);
     32        } else {
     33            $pass = DB::select('select p_password from policeman where badge_no = :badge_no;', ['badge_no' => $badge_no]);
    3134        }
    3235
     
    3639        }
    3740
    38 
    3941        if ($value == $password) {
    4042            // Authentication passed
     
    4244            Session::put('is_policeman', $policeman);
    4345            if($policeman){
    44                 Session::put('p_id', $exists[0]->p_id);
     46                Session::put('pe_id', $is_policeman[0]->pe_id);
    4547            } else {
    46                 Session::put('pe_id', $exists[0]->pe_id);
     48                Session::put('pe_id', $is_officer[0]->pe_id);
    4749            }
    4850            return view('welcome');
     
    5658    {
    5759        Session::forget('badge_no');
     60        Session::forget('p_id');
     61        Session::forget('pe_id');
    5862        Session::forget('is_policeman');
    5963        return redirect('/login');
Note: See TracChangeset for help on using the changeset viewer.