diff --git a/skolehjem/app/Http/Controllers/EventController.php b/skolehjem/app/Http/Controllers/EventController.php index 656c4cb..199fa94 100644 --- a/skolehjem/app/Http/Controllers/EventController.php +++ b/skolehjem/app/Http/Controllers/EventController.php @@ -31,7 +31,7 @@ class EventController extends Controller public function index(Request $request) { - $events = Event::query()->paginate($request->input("limit", 20)); + $events = Event::query()->orderBY('date' , 'asc')->paginate($request->input("limit", 20)); //returns the function with events index page and a parameter of events. //also Response::detect checks screen size to determine if user is on a computer or mobile. diff --git a/skolehjem/app/Http/Controllers/FeedbackController.php b/skolehjem/app/Http/Controllers/FeedbackController.php index 0c84a6a..821ce83 100644 --- a/skolehjem/app/Http/Controllers/FeedbackController.php +++ b/skolehjem/app/Http/Controllers/FeedbackController.php @@ -29,7 +29,7 @@ class FeedbackController extends Controller */ public function index(Request $request) { - $feedback = Feedbacks::query()->paginate($request->input("limit", 20)); + $feedback = Feedbacks::query()->orderBy('created_at', 'desc')->paginate($request->input("limit", 20)); return Response::detect("feedbacks.index", [ "feedback" => $feedback ]); } @@ -60,7 +60,7 @@ class FeedbackController extends Controller $feedbacks = new Feedbacks($requestBody); $feedbacks->save(); - return Response::detect("root.index"); + return redirect()->route("root.index"); } /** diff --git a/skolehjem/app/Http/Controllers/UserController.php b/skolehjem/app/Http/Controllers/UserController.php index 3abe711..7dd52d5 100644 --- a/skolehjem/app/Http/Controllers/UserController.php +++ b/skolehjem/app/Http/Controllers/UserController.php @@ -18,14 +18,16 @@ class UserController extends Controller { public function __construct() { - $this->middleware([ "auth" ])->only(["logout", "accountedit", "accounteditpass"]); + $this->middleware([ "auth" ])->only("logout"); $this->middleware([ "guest" ])->only("login"); $this->middleware([ "check.auth:user.list" ])->only("index"); $this->middleware([ "check.auth:user.show" ])->only("show"); $this->middleware([ "check.auth:user.create" ])->only("create"); - $this->middleware([ "check.auth:user.edit" ])->only("edit", "update"); + $this->middleware([ "check.auth:user.edit" ])->only(["edit", "update"]); $this->middleware([ "check.auth:user.delete" ])->only("delete"); + + $this->middleware([ "check.auth:ownuser.edit" ])->only(["accountupdate", "accountedit", "accounteditpass", "account"]); } /** @@ -121,24 +123,34 @@ class UserController extends Controller */ public function update(Request $request, $id) { - $data = $request->all(); - + return redirect()->route("users.account"); $user = User::find($id); if($id === Auth::id() || auth()->user()->hasPermissionTo("user.edit")) { - if ($request->roles != null) { //You can only edit roles on the admin site, so if there is an input roles, then update user info and edit roles - /** @var User $user */ - $user->update($data); + if ($request->roles != null && auth()->user()->hasPermissionTo("user.edit")) { //You can only edit roles on the admin site, so if there is an input roles, then update user info and edit roles + if ($request->password != "") { // If you have edited the password, then run this + if ($request->password == $request->password2) { // If the password is the same as confirm password, then update everything from user + $data = $request->all(); + /** @var User $user */ + $user->update($data); + } else // Else go back with an error message + return redirect()->route("users.edit", ['user' => $id])->with('error#passnotsame', '

Der stod ikke det samme i `Password` & `Confirm Password`!

'); + } + else { // If you haven't touched the password, then update everything else but password + $data = $request->only(['name_first', 'name_last', 'email', 'phone', 'roles']); + /** @var User $user */ + $user->update($data); + } + $user->roles()->detach(); $user->forgetCachedPermissions(); foreach ($request->roles as $role) { $user->assignRole($role); } - - //$user->save(); } else { // Else if you're not on the admin site (user site) if ($request->input('password') != null) { // If you're editing the password + $data = $request->only(['name_first', 'name_last', 'email', 'phone', 'password']); if ($request->input('password') != $request->input('confirmpassword')) { // If new password and new password confirm is not the same, go back with fail message. return redirect()->route("users.accounteditpass")->with('error#notsamepass', '

Der stod ikke det samme i `Nyt Password` & `Bekræft Nyt Password`!

'); } elseif (!Hash::check($request->input('oldpassword'), $user->password)) { // If the written current password and current password in DB is not the same, go back with fail message. @@ -148,9 +160,10 @@ class UserController extends Controller $user->update($data); Auth::logout(); - return redirect()->route("users.login")->with('success#passwordchange', '

Dit password er hermed ændret!

'); + return redirect()->route("users.login")->with('success#passwordchange', '

Dit password er hermed ændret!

'); } } else { // Else if you're not editing the password but anything else (Email, Phone Number). Then update user. + $data = $request->only(['email', 'phone']); $user->update($data); return redirect()->route("users.account")->with('success#credentialschanged', '

Dine oplysninger er hermed ændret!

'); @@ -248,6 +261,41 @@ class UserController extends Controller return Response::detect("users.editpass"); } + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function accountupdate(Request $request) + { + $user = User::find(Auth::id()); + + if ($request->input('password') != null) { // If you're editing the password + $data = $request->only(['name_first', 'name_last', 'email', 'phone', 'password']); + if ($request->input('password') != $request->input('confirmpassword')) { // If new password and new password confirm is not the same, go back with fail message. + return redirect()->route("users.accounteditpass")->with('error#notsamepass', '

Der stod ikke det samme i `Nyt Password` & `Bekræft Nyt Password`!

'); + } elseif (!Hash::check($request->input('oldpassword'), $user->password)) { // If the written current password and current password in DB is not the same, go back with fail message. + return redirect()->route("users.accounteditpass")->with('error#oldpass', '

Det indtastede password i `Nuværende Password` er ikke dit nuværende password!

'); + } else { // If new password and current password is the same AND current written and current DB password is the same. Then update and logout. + /** @var User $user */ + $user->update($data); + Auth::logout(); + + return redirect()->route("users.login")->with('success#passwordchange', '

Dit password er hermed ændret!

'); + } + } else { // Else if you're not editing the password but anything else (Email, Phone Number). Then update user. + $data = $request->only(['email', 'phone']); + $user->update($data); + + return redirect()->route("users.account")->with('success#credentialschanged', '

Dine oplysninger er hermed ændret!

'); + } + $users = User::query()->paginate(20); + + return Response::detect("users.index", [ + "users" => $users + ]); + } public function search(Request $request){ if($request->ajax()){ diff --git a/skolehjem/database/seeds/PermissionSeeder.php b/skolehjem/database/seeds/PermissionSeeder.php index 4c6c995..fb01e2a 100644 --- a/skolehjem/database/seeds/PermissionSeeder.php +++ b/skolehjem/database/seeds/PermissionSeeder.php @@ -22,6 +22,7 @@ class PermissionSeeder extends Seeder "user.show" => "Shows another user profile.", "user.edit" => "Allows editing of other users.", "user.delete" => "Allows deleting of other users.", + "ownuser.edit" => "Allows editing of your own user", /** * The CALENDAR specific permissions diff --git a/skolehjem/database/seeds/RoleSeeder.php b/skolehjem/database/seeds/RoleSeeder.php index 4d90468..f369303 100644 --- a/skolehjem/database/seeds/RoleSeeder.php +++ b/skolehjem/database/seeds/RoleSeeder.php @@ -48,6 +48,7 @@ class RoleSeeder extends Seeder $brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "washing.machine.reservation.create")->first()); $brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "washing.machine.reservation.delete")->first()); $brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "washing.machine.reservation.list")->first()); + $brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "ownuser.edit")->first()); //Give permissions to Bruger (id: 2) foreach ($brugerPermissions as $permission) { diff --git a/skolehjem/public/css/admin.css b/skolehjem/public/css/admin.css index a07022c..507ef22 100644 --- a/skolehjem/public/css/admin.css +++ b/skolehjem/public/css/admin.css @@ -26,6 +26,15 @@ form { justify-content: center; } +.fa-eye { + font-size: 25px; + color: grey; + margin: 0 0 16px -35px; + align-self: center; + z-index: 98; + background-color: white; +} + .btn { border: 0; border-radius: 4px; @@ -97,6 +106,23 @@ input.appinput { color: white; } +.form-control { + flex: 1 1 auto; + width: 1%; +} + +.input-group { + position: relative; + display: flex; + flex-wrap: wrap; + align-items: stretch; + width: 100%; +} + +.input-group-append { + display: flex; +} + .d-flex { display: flex; } diff --git a/skolehjem/public/css/webapp.css b/skolehjem/public/css/webapp.css index 9c36886..b5c435a 100644 --- a/skolehjem/public/css/webapp.css +++ b/skolehjem/public/css/webapp.css @@ -26,6 +26,15 @@ form { justify-content: center; } +.fa-eye { + font-size: 25px; + color: grey; + margin: 0 0 16px -35px; + align-self: center; + z-index: 98; + background-color: white; +} + .btn { border: 0; border-radius: 4px; @@ -97,6 +106,23 @@ input.appinput { color: white; } +.form-control { + flex: 1 1 auto; + width: 1%; +} + +.input-group { + position: relative; + display: flex; + flex-wrap: wrap; + align-items: stretch; + width: 100%; +} + +.input-group-append { + display: flex; +} + .d-flex { display: flex; } @@ -6633,6 +6659,14 @@ main { p { font-size: 4vw; } + + .links { + position: absolute; + width: calc(100% - 40px); + bottom: 8px; + height: 2rem; + justify-content: center; + } } .mock-up-link { @@ -6943,9 +6977,3 @@ main { display: inline-block; } -.spaneye { - position: absolute; - font-size: 25px; - color: grey; - margin: 7.5px 0 0 -45px; -} diff --git a/skolehjem/resources/sass/app/forms/_forms.scss b/skolehjem/resources/sass/app/forms/_forms.scss index 15a1e8b..e270bfe 100644 --- a/skolehjem/resources/sass/app/forms/_forms.scss +++ b/skolehjem/resources/sass/app/forms/_forms.scss @@ -6,6 +6,15 @@ form { justify-content: center; } +.fa-eye { + font-size: 25px; + color: grey; + margin: 0 0 16px -35px; + align-self: center; + z-index: 98; + background-color: white; +} + .btn { border: 0; border-radius: 4px; @@ -60,3 +69,23 @@ input.appinput { opacity: 1; color: white; } + +.form-control { + flex: 1 1 auto; + width: 1%; +} + +.input-group { + position: relative; + display: -ms-flexbox; + display: flex; + -ms-flex-wrap: wrap; + flex-wrap: wrap; + -ms-flex-align: stretch; + align-items: stretch; + width: 100%; +} + +.input-group-append { + display: flex; +} diff --git a/skolehjem/resources/sass/webapp/_default.scss b/skolehjem/resources/sass/webapp/_default.scss index ad64af2..0d23f7f 100644 --- a/skolehjem/resources/sass/webapp/_default.scss +++ b/skolehjem/resources/sass/webapp/_default.scss @@ -66,6 +66,14 @@ and (max-width : 900px) p { font-size: 4vw; } + + .links { + position: absolute; + width: calc(100% - 40px); + bottom: 8px; + height: 2rem; + justify-content: center; + } } diff --git a/skolehjem/resources/views/admin/users/edit.blade.php b/skolehjem/resources/views/admin/users/edit.blade.php index 4fc653d..b3feb3a 100644 --- a/skolehjem/resources/views/admin/users/edit.blade.php +++ b/skolehjem/resources/views/admin/users/edit.blade.php @@ -11,7 +11,8 @@ @section("content")

Rediger Bruger:

-
$user]) }}"> + {!! session()->get('error#passnotsame') !!} + $user]) }}" style="display: inline-table;"> @csrf @method("put") @@ -21,13 +22,15 @@ - + + - + + - @if(count($user->roles) == 0) @@ -51,4 +54,34 @@
+ +@endsection + +@section("scripts") + @endsection diff --git a/skolehjem/resources/views/app/users/edit.blade.php b/skolehjem/resources/views/app/users/edit.blade.php index 17f6a1f..6cdbf83 100644 --- a/skolehjem/resources/views/app/users/edit.blade.php +++ b/skolehjem/resources/views/app/users/edit.blade.php @@ -7,7 +7,7 @@ @section("content")

Konto

-
Auth::user()]) }}"> + Auth::user()]) }}"> @csrf @method("put") Navn: diff --git a/skolehjem/resources/views/app/users/editpass.blade.php b/skolehjem/resources/views/app/users/editpass.blade.php index b1da050..bb0f78a 100644 --- a/skolehjem/resources/views/app/users/editpass.blade.php +++ b/skolehjem/resources/views/app/users/editpass.blade.php @@ -7,23 +7,34 @@ @section("content")

Konto

- Auth::user()]) }}" style="display: block;"> + Auth::user()]) }}" style="display: inline-table;"> @csrf @method("put") Nuværende Password: - - +
+ + +
Nyt Password: - - +
+ + +
Bekræft Nyt Password: - - +
+ + +
{!! session()->get('error#notsamepass') !!} {!! session()->get('error#oldpass') !!}
+ @endsection @section("scripts") diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index 3745858..85cde52 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -13,10 +13,6 @@ use Illuminate\Support\Facades\Route; | */ -//Route::get('/', function () { -// return view('welcome'); -//}); - Route::get("/", "RootController@index")->name("root.index"); Route::get("/home", "RootController@index")->name("root.index"); @@ -28,16 +24,18 @@ Route::post("/forgot", "UserController@forgot")->name("users.forgot"); Route::get("/account", "UserController@account")->name("users.account"); Route::get("/account/edit", "UserController@accountedit")->name("users.accountedit"); Route::get("/account/editpass", "UserController@accounteditpass")->name("users.accounteditpass"); -Route::post("/account/update", "UserController@update")->name("users.accountupdate"); +Route::put("/account/update", "UserController@accountupdate")->name("users.accountupdate"); Route::get("/events/signups", "EventController@signups")->name("events.signups"); Route::get("phones", "PhoneController@index")->name("phones.index"); +Route::get("/washing-reservationsapi", "WashingReservationController@api")->name("washing-reservations.api"); + +//Search/Filter Route::get("/contactsapi", "ContactController@search")->name("contacts.search"); Route::get("/eventsapi", "EventController@search")->name("events.search"); Route::get("/menuplansapi", "MenuPlanController@search")->name("menu-plans.search"); Route::get("/rolesapi", "RolesController@search")->name("roles.search"); Route::get("/userapi", "UserController@search")->name("users.search"); Route::get("/vaskeapi", "WashingReservationController@search")->name("washing-reservations.search"); -Route::get("/washing-reservationsapi", "WashingReservationController@api")->name("washing-reservations.api"); Route::get("/risrosapi", "FeedbackController@search")->name("feedbacks.search");