Changeset cf84baa


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

Files:
11 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}
  • resources/views/case.blade.php

    r6b10b67 rcf84baa  
    7474                <a href="#" class="block px-4 py-2 account-link hover:text-white">Профил</a>
    7575                <a href="#" class="block px-4 py-2 account-link hover:text-white">Помош</a>
    76                 <a href="#" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
     76                <a href="/logout" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
    7777            </div>
    7878        </div>
  • resources/views/cases.blade.php

    r6b10b67 rcf84baa  
    7474                <a href="#" class="block px-4 py-2 account-link hover:text-white">Профил</a>
    7575                <a href="#" class="block px-4 py-2 account-link hover:text-white">Помош</a>
    76                 <a href="#" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
     76                <a href="/logout" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
    7777            </div>
    7878        </div>
  • resources/views/employees.blade.php

    r6b10b67 rcf84baa  
    101101                <a href="#" class="block px-4 py-2 account-link hover:text-white">Профил</a>
    102102                <a href="#" class="block px-4 py-2 account-link hover:text-white">Помош</a>
    103                 <a href="#" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
     103                <a href="/logout" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
    104104            </div>
    105105        </div>
  • resources/views/filter.blade.php

    r6b10b67 rcf84baa  
    154154                <a href="#" class="block px-4 py-2 account-link hover:text-white">Профил</a>
    155155                <a href="#" class="block px-4 py-2 account-link hover:text-white">Помош</a>
    156                 <a href="#" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
     156                <a href="/logout" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
    157157            </div>
    158158        </div>
     
    216216        <h1 class="text-3xl text-black pb-6">Контролна табла</h1>
    217217        <div style="width: 600px">
    218             <form>
    219                 <label for="default-search" class="mb-2 text-sm font-medium text-gray-900 sr-only dark:text-white">Search</label>
     218            <form action="/filter" method="post">
     219                @csrf
    220220                <div class="relative">
    221221                    <div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
     
    224224                        </svg>
    225225                    </div>
    226                     <input type="search" id="default-search" class="block w-full p-4 ps-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Пребарај матичен број..." required>
     226
     227                    <label for="embg" class="mb-2 text-sm font-medium text-gray-900 sr-only dark:text-white">Search</label>
     228                    <input type="text" id="embg" name="embg" class="block w-full p-4 ps-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Пребарај матичен број..." required>
    227229                    <button type="submit" class="text-white absolute end-2.5 bottom-2.5 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Search</button>
    228230                </div>
     
    269271
    270272
    271         <div class="w-full mt-12">
    272             <p class="text-xl pb-3 flex items-center">
    273                 <i class="fas fa-list mr-3"></i> Граѓани
    274             </p>
    275 
    276             <div class="bg-white overflow-auto">
     273            <div class="bg-white overflow-auto max-h-96">
    277274                <table class="min-w-full bg-white">
    278275                    <thead class="bg-gray-800 text-white">
     
    289286                    </thead>
    290287                    <tbody class="text-gray-700">
    291                     <tr>
    292                         <td class="w-1/3 text-left py-3 px-4">1011001470303</td>
    293                         <td class="w-1/3 text-left py-3 px-4">Емир</td>
    294                         <td class="w-1/3 text-left py-3 px-4">Абази</td>
    295                         <td class="w-1/3 text-left py-3 px-4">М</td>
    296                         <td class="w-1/3 text-left py-3 px-4">ул.Македонија бр.80 Тетово</td>
    297                         <td class="w-1/3 text-left py-3 px-4">Македонија</td>
    298                         <td class="w-1/3 text-left py-3 px-4">Албанец</td>
    299                         <td class="text-left py-3 px-4"><a class="hover:text-blue-500" href="tel:622322662">622322662</a></td>
    300                     </tr>
    301                     <tr class="bg-gray-200">
    302                         <td class="w-1/3 text-left py-3 px-4">0302954470303</td>
    303                         <td class="w-1/3 text-left py-3 px-4">Василија</td>
    304                         <td class="w-1/3 text-left py-3 px-4">Васиљоска</td>
    305                         <td class="w-1/3 text-left py-3 px-4">Ж</td>
    306                         <td class="w-1/3 text-left py-3 px-4">ул.154 бр.20 Скопје</td>
    307                         <td class="w-1/3 text-left py-3 px-4">Македонија</td>
    308                         <td class="w-1/3 text-left py-3 px-4">Македонка</td>
    309                         <td class="text-left py-3 px-4"><a class="hover:text-blue-500" href="tel:622322662">622322662</a></td>
    310                     </tr>
     288
     289                    @foreach($peoples as $people)
     290                        <tr>
     291                            <td class="w-1/3 text-left py-3 px-4">{{$people->embg}}</td>
     292                            <td class="w-1/3 text-left py-3 px-4">{{$people->first_name}}</td>
     293                            <td class="w-1/3 text-left py-3 px-4">{{$people->last_name}}</td>
     294                            <td class="w-1/3 text-left py-3 px-4">{{$people->gender}}</td>
     295                            <td class="w-1/3 text-left py-3 px-4">{{$people->address}}</td>
     296                            <td class="w-1/3 text-left py-3 px-4">{{$people->country}}</td>
     297                            <td class="w-1/3 text-left py-3 px-4">{{$people->nationality}}</td>
     298                            <td class="text-left py-3 px-4"><a class="hover:text-blue-500" href="tel:622322662">{{$people->contact}}</a></td>
     299                        </tr>
     300                    @endforeach
    311301                    </tbody>
    312302                </table>
  • resources/views/login.blade.php

    r6b10b67 rcf84baa  
    4444                            Најави се на твојот профил
    4545                        </h1>
    46                         <form class="space-y-4 md:space-y-6" action="#">
     46                        <form class="space-y-4 md:space-y-6" method="POST" action="/login" >
     47                            @csrf
    4748                            <div>
    48                                 <label for="email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Е-маил</label>
    49                                 <input type="email" name="email" id="email" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="ime.prezime@policiska_stanica.mk" required="">
     49                                <label for="badge_no" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Број на значка</label>
     50                                <input type="text" name="badge_no" id="badge_no" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Број на значка" required="">
    5051                            </div>
     52                            @error('badge_no')
     53                            <p class="text-red-500 text-xs mt-1">{{$message}}</p>
     54                            @enderror
    5155                            <div>
    5256                                <label for="password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Лозинка</label>
    5357                                <input type="password" name="password" id="password" placeholder="••••••••" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required="">
    5458                            </div>
     59                            @error('password')
     60                            <p class="text-red-500 text-xs mt-1">{{$message}}</p>
     61                            @enderror
     62
    5563                            <div class="flex items-center justify-between">
    5664                                <div class="flex items-start">
    5765                                    <div class="flex items-center h-5">
    58                                         <input id="remember" aria-describedby="remember" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800" required="">
     66                                        <input id="remember" aria-describedby="remember" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800">
    5967                                    </div>
    6068                                    <div class="ml-3 text-sm">
  • resources/views/register-policeman.blade.php

    r6b10b67 rcf84baa  
    164164                <a href="#" class="block px-4 py-2 account-link hover:text-white">Профил</a>
    165165                <a href="#" class="block px-4 py-2 account-link hover:text-white">Помош</a>
    166                 <a href="#" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
     166                <a href="/logout"class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
    167167            </div>
    168168        </div>
  • resources/views/welcome.blade.php

    r6b10b67 rcf84baa  
    2929    <aside class="relative bg-sidebar h-screen w-64 hidden sm:block shadow-xl">
    3030            <div class="p-6">
    31                 <a href="#" class="text-white text-3xl font-semibold uppercase hover:text-gray-300">Началник</a>
     31                @if (Session::get('is_policeman'))
     32                    <a href="#" class="text-white text-3xl font-semibold uppercase hover:text-gray-300">Полицаец</a>
     33                    @else
     34                    <a href="#" class="text-white text-3xl font-semibold uppercase hover:text-gray-300">Началник</a>
     35                @endif
    3236                <button class="w-full bg-white cta-btn font-semibold py-2 mt-5 rounded-br-lg rounded-bl-lg rounded-tr-lg shadow-lg hover:shadow-xl hover:bg-gray-300 flex items-center justify-center">
    3337                    <i class="fas fa-plus mr-3"></i> Додади полицаец
     
    7478                        <a href="#" class="block px-4 py-2 account-link hover:text-white">Профил</a>
    7579                        <a href="#" class="block px-4 py-2 account-link hover:text-white">Помош</a>
    76                         <a href="#" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
     80                        <a href="/logout" class="block px-4 py-2 account-link hover:text-white">Одјави се</a>
    7781                    </div>
    7882                </div>
  • routes/web.php

    r6b10b67 rcf84baa  
    2323Route::get('/login', function () {
    2424    return view('login');
     25
    2526});
    2627
    27 Route::post('logout', [SessionsController::class, 'destroy'])->middleware('auth');
     28Route::post('/login', [SessionsController::class, 'store']);
     29
     30
     31Route::get('logout', [SessionsController::class, 'logout']);
    2832
    2933
     
    3135Route::get('employees', [OfficerController::class, 'employees'])->middleware('guest');
    3236Route::get('filter', [PeopleController::class, 'filter'])->middleware('guest');
     37Route::post('filter', [PeopleController::class, 'filter_post'])->middleware('guest');
     38
    3339Route::get('cases', [CrimeCaseController::class, 'cases'])->middleware('guest');
    3440Route::get('case', [CrimeCaseController::class, 'case'])->middleware('guest');
Note: See TracChangeset for help on using the changeset viewer.