Changeset 5372778


Ignore:
Timestamp:
08/26/24 14:20:34 (3 months ago)
Author:
bube-ristovska <ristovska725@…>
Branches:
main
Children:
3c89e27
Parents:
8a258ab
Message:

Middleware for permissions based on officer, policeman or both

Files:
4 added
3 edited

Legend:

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

    r8a258ab r5372778  
    5454        if ($this->verifyPassword($password, $value, $value2)) {
    5555            // Authentication passed
     56            Session::put('auth', true);
    5657            Session::put('badge_no', $badge_no);
    5758            Session::put('is_policeman', $policeman);
  • app/Http/Kernel.php

    r8a258ab r5372778  
    2222        \App\Http\Middleware\TrimStrings::class,
    2323        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
     24    ];
     25    protected $routeMiddleware = [
     26        // other middleware
     27        'policeman' => \App\Http\Middleware\CheckPoliceman::class,
     28        'officer' => \App\Http\Middleware\CheckOfficer::class,
     29        'both' => \App\Http\Middleware\CheckBoth::class,
    2430    ];
    2531
  • routes/web.php

    r8a258ab r5372778  
    1919*/
    2020
    21 Route::get('/', function () {
    22     return view('welcome');
    23 });
     21// UNAUTHORIZED
    2422Route::get('/login', function () {
    2523    return view('login');
    2624
    2725});
    28 
    2926Route::post('/login', [SessionsController::class, 'store']);
    3027
     28Route::get('/unauth', function () {
     29    return view('unauth');  // Make sure there is a view file named `unauth.blade.php`
     30})->name('unauth');  // Name the route 'unauth'
    3131
     32// AUTHORIZED
     33// POLICEMAN
     34Route::get('register-statement', [CrimeCaseController::class, 'register_statement'])->middleware('policeman');
     35Route::post('register-statement', [CrimeCaseController::class, 'register_statement_post'])->middleware('policeman');
     36
     37// OFFICER
     38Route::get('register-policeman', [OfficerController::class, 'register'])->middleware('officer');
     39Route::post('register-policeman', [OfficerController::class, 'register_post'])->middleware('officer');
     40
     41// BOTH
     42Route::get('/', function () {
     43    return view('welcome');
     44})->middleware('both');
    3245Route::get('logout', [SessionsController::class, 'logout']);
    3346
     47Route::get('employees', [OfficerController::class, 'employees'])->middleware('both');
     48Route::get('/employees/{id}', [OfficerController::class, 'show'])->middleware('both');
    3449
     50Route::get('filter', [PeopleController::class, 'filter'])->middleware('both');
     51Route::post('filter', [PeopleController::class, 'filter_post'])->middleware('both');
    3552
    36 Route::get('employees', [OfficerController::class, 'employees'])->middleware('guest');
    37 Route::get('/employees/{id}', [OfficerController::class, 'show']);
     53Route::get('cases', [CrimeCaseController::class, 'cases'])->middleware('both');
     54Route::get('case/{wildcard}', [CrimeCaseController::class, 'case'])->middleware('both');
     55Route::get('finished_cases', [CrimeCaseController::class, 'finished_cases'])->middleware('both');
    3856
    39 Route::get('filter', [PeopleController::class, 'filter'])->middleware('guest');
    40 Route::post('filter', [PeopleController::class, 'filter_post'])->middleware('guest');
    41 
    42 Route::get('cases', [CrimeCaseController::class, 'cases'])->middleware('guest');
    43 
    44 Route::get('case/{wildcard}', [CrimeCaseController::class, 'case'])->name('case')->middleware('guest');
    45 
    46 Route::get('finished_cases', [CrimeCaseController::class, 'finished_cases'])->middleware('guest');
    47 
    48 
    49 Route::get('register-policeman', [OfficerController::class, 'register'])->middleware('guest');
    50 Route::post('register-policeman', [OfficerController::class, 'register_post'])->middleware('guest');
    51 
    52 Route::get('register-statement', [CrimeCaseController::class, 'register_statement'])->middleware('guest');
    53 Route::post('register-statement', [CrimeCaseController::class, 'register_statement_post'])->middleware('guest');
    54 
    55 
    56 
    57 Route::post('/get-person', [PeopleController::class, 'getPerson']);
     57Route::post('/get-person', [PeopleController::class, 'getPerson'])->middleware('both');
Note: See TracChangeset for help on using the changeset viewer.