diff --git a/skolehjem/app/Http/Controllers/EventController.php b/skolehjem/app/Http/Controllers/EventController.php index db61a07..881efd2 100644 --- a/skolehjem/app/Http/Controllers/EventController.php +++ b/skolehjem/app/Http/Controllers/EventController.php @@ -2,18 +2,21 @@ namespace App\Http\Controllers; +use App\User; use Illuminate\Http\Request; class EventController extends Controller { /** - * Display a listing of the resource. + * Display a listing of the resource.. * * @return \Illuminate\Http\Response */ - public function index() + public function index(Request $request) { - // + $users = User::query()->paginate($request->query("limit", 20)); + + return view("user.index", [ "users" => $users]); } /** @@ -23,7 +26,7 @@ class EventController extends Controller */ public function create() { - // + return view("user.create"); } /** diff --git a/skolehjem/app/Http/Controllers/UserController.php b/skolehjem/app/Http/Controllers/UserController.php index ecc9490..4f1c783 100644 --- a/skolehjem/app/Http/Controllers/UserController.php +++ b/skolehjem/app/Http/Controllers/UserController.php @@ -52,7 +52,7 @@ class UserController extends Controller $user = new User($data); $user->save(); - return view("user.success"); + return view("user.store"); } /** @@ -90,22 +90,59 @@ class UserController extends Controller * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function update(Request $request, $id) { - // + $data = $request->validate([ + "name_first" => "max:255", + "name_last" => "max:255", + "email" => "email|unique:users", + "password" => "max:60", + "phone" => "unique:users", + ]); + + // Validates if the user is updating itself or another user. + if($id === Auth::id()) { + $user = Auth::user(); + + $user->update($data); + + $user->save(); + } + else if(Auth::user()->hasPermissionTo("user.edit")) { + $user = User::find($id); + + /** @var User $user */ + $user->update($data); + + $user->save(); + } + + return view("user.edit", [ + "user" => $user + ]); } /** * Remove the specified resource from storage. * * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function destroy($id) { - // + if($id === Auth::id()) { + $user = Auth::user(); + $user->delete(); + } + else if(Auth::user()->hasPermissionTo("user.delete")) { + $user = User::find($id); + + $user->delete(); + } + + return view("user.delete"); } /*******************************************/ @@ -116,9 +153,16 @@ class UserController extends Controller $data = $request->only("email", "password"); if(Auth::attempt($data)) { + //TODO: Implement home? return view("user.home", [ "user" => Auth::user() ]); } - return redirect()->back(400); + return redirect()->back(403); + } + + public function logout(Request $request) { + Auth::logout(); + + return redirect()->to("/"); } } diff --git a/skolehjem/app/Http/Controllers/WashingMachineController.php b/skolehjem/app/Http/Controllers/WashingMachineController.php index ed0179d..f39aca5 100644 --- a/skolehjem/app/Http/Controllers/WashingMachineController.php +++ b/skolehjem/app/Http/Controllers/WashingMachineController.php @@ -4,59 +4,79 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\WashingMachine; + class WashingMachineController extends Controller { /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @param Request $request + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function index() + public function index(Request $request) { - // + $machines = WashingMachine::query()->paginate($request->query("page", 1)); + + return view("washing-machine.index", [ "machines" => $machines ]); } /** * Show the form for creating a new resource. * - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function create() { - // + return view("washing-machine.create"); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function store(Request $request) { - // + $data = $request->validate([ + "time" => "required" + ]); + + $machine = new WashingMachine($data); + $machine->save(); + + return view("washing-machine.store"); } /** * Display the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show($id) { - // + $machine = WashingMachine::find($id); + + return view("washing-machine.show", [ + "machine" => $machine + ]); } /** * Show the form for editing the specified resource. * * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function edit($id) { - // + $machine = WashingMachine::find($id); + + return view("washing-machine.edit", [ + "machine" => $machine + ]); } /** @@ -64,21 +84,36 @@ class WashingMachineController extends Controller * * @param \Illuminate\Http\Request $request * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function update(Request $request, $id) { - // + $data = $request->validate([ + "time" => "required" + ]); + + $machine = WashingMachine::find($id); + + $machine->update($data); + + $machine->save(); + + return view("washing-machine.edit", [ + "machine" => $machine + ]); } /** * Remove the specified resource from storage. * * @param int $id - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function destroy($id) { - // + $machine = WashingMachine::find($id); + $machine->delete(); + + return view("washing-machine.destroy"); } } diff --git a/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php b/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php index 4aaf16b..e732b55 100644 --- a/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php +++ b/skolehjem/database/migrations/2020_06_08_085447_create_washing_reservations.php @@ -15,7 +15,7 @@ class CreateWashingReservations extends Migration { Schema::create('washing_reservations', function (Blueprint $table) { $table->id(); - $table->time("time"); + $table->timestamp("time"); $table->timestamps(); }); } diff --git a/skolehjem/database/migrations/2020_06_08_090004_create_events.php b/skolehjem/database/migrations/2020_06_08_090004_create_events.php index 9302b16..20f7676 100644 --- a/skolehjem/database/migrations/2020_06_08_090004_create_events.php +++ b/skolehjem/database/migrations/2020_06_08_090004_create_events.php @@ -15,6 +15,8 @@ class CreateEvents extends Migration { Schema::create('events', function (Blueprint $table) { $table->id(); + $table->string("name"); + $table->string("description"); $table->timestamps(); }); } diff --git a/skolehjem/database/migrations/2020_06_08_123954_create_washing_machines.php b/skolehjem/database/migrations/2020_06_08_123954_create_washing_machines.php index 6c78c5b..7ef26d1 100644 --- a/skolehjem/database/migrations/2020_06_08_123954_create_washing_machines.php +++ b/skolehjem/database/migrations/2020_06_08_123954_create_washing_machines.php @@ -15,6 +15,7 @@ class CreateWashingMachines extends Migration { Schema::create('washing_machines', function (Blueprint $table) { $table->id(); + $table->string("name")->unique(); $table->timestamps(); }); } diff --git a/skolehjem/database/migrations/2020_06_09_081126_alter_washing_reservations.php b/skolehjem/database/migrations/2020_06_09_081126_alter_washing_reservations.php index 06995b9..54cba2f 100644 --- a/skolehjem/database/migrations/2020_06_09_081126_alter_washing_reservations.php +++ b/skolehjem/database/migrations/2020_06_09_081126_alter_washing_reservations.php @@ -13,9 +13,8 @@ class AlterWashingReservations extends Migration */ public function up() { - // - } + } /** * Reverse the migrations. * diff --git a/skolehjem/laravel.sqlite b/skolehjem/laravel.sqlite new file mode 100644 index 0000000..e69de29 diff --git a/skolehjem/resources/views/user/index.blade.php b/skolehjem/resources/views/user/index.blade.php new file mode 100644 index 0000000..f6cd88a --- /dev/null +++ b/skolehjem/resources/views/user/index.blade.php @@ -0,0 +1,9 @@ +@extends('layout.base') + +@section('content') + + + +@endsection diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index cc84197..a2dcba3 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -22,3 +22,7 @@ Route::middleware(["auth"])->group(function () { }); Route::get("/", "RootController@index")->name("root.index"); + + +Route::get("/login", "UserController@login")->name("user.login"); +Route::get("/logout", "UserController@logout")->name("user.logout");