Conflicts:
	skolehjem/routes/web.php
This commit is contained in:
Neerholt 2020-08-03 10:09:54 +02:00
commit d7c4f2052b
13 changed files with 220 additions and 37 deletions

View File

@ -31,7 +31,7 @@ class EventController extends Controller
public function index(Request $request) 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. //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. //also Response::detect checks screen size to determine if user is on a computer or mobile.

View File

@ -29,7 +29,7 @@ class FeedbackController extends Controller
*/ */
public function index(Request $request) 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 ]); return Response::detect("feedbacks.index", [ "feedback" => $feedback ]);
} }
@ -60,7 +60,7 @@ class FeedbackController extends Controller
$feedbacks = new Feedbacks($requestBody); $feedbacks = new Feedbacks($requestBody);
$feedbacks->save(); $feedbacks->save();
return Response::detect("root.index"); return redirect()->route("root.index");
} }
/** /**

View File

@ -18,14 +18,16 @@ class UserController extends Controller
{ {
public function __construct() public function __construct()
{ {
$this->middleware([ "auth" ])->only(["logout", "accountedit", "accounteditpass"]); $this->middleware([ "auth" ])->only("logout");
$this->middleware([ "guest" ])->only("login"); $this->middleware([ "guest" ])->only("login");
$this->middleware([ "check.auth:user.list" ])->only("index"); $this->middleware([ "check.auth:user.list" ])->only("index");
$this->middleware([ "check.auth:user.show" ])->only("show"); $this->middleware([ "check.auth:user.show" ])->only("show");
$this->middleware([ "check.auth:user.create" ])->only("create"); $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: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) public function update(Request $request, $id)
{ {
$data = $request->all(); return redirect()->route("users.account");
$user = User::find($id); $user = User::find($id);
if($id === Auth::id() || auth()->user()->hasPermissionTo("user.edit")) { 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 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
/** @var User $user */ if ($request->password != "") { // If you have edited the password, then run this
$user->update($data); 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', '<p>Der stod ikke det samme i `Password` & `Confirm Password`!</p>');
}
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->roles()->detach();
$user->forgetCachedPermissions(); $user->forgetCachedPermissions();
foreach ($request->roles as $role) { foreach ($request->roles as $role) {
$user->assignRole($role); $user->assignRole($role);
} }
//$user->save();
} else { // Else if you're not on the admin site (user site) } else { // Else if you're not on the admin site (user site)
if ($request->input('password') != null) { // If you're editing the password 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. 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', '<p class="text-center">Der stod ikke det samme i `Nyt Password` & `Bekræft Nyt Password`!</p>'); return redirect()->route("users.accounteditpass")->with('error#notsamepass', '<p class="text-center">Der stod ikke det samme i `Nyt Password` & `Bekræft Nyt Password`!</p>');
} 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. } 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); $user->update($data);
Auth::logout(); Auth::logout();
return redirect()->route("users.login")->with('success#passwordchange', '<p class="text-center">Dit password er hermed ændret!</p>'); return redirect()->route("users.login")->with('success#passwordchange', '<p class="text-center text-white">Dit password er hermed ændret!</p>');
} }
} else { // Else if you're not editing the password but anything else (Email, Phone Number). Then update user. } 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); $user->update($data);
return redirect()->route("users.account")->with('success#credentialschanged', '<p class="text-center">Dine oplysninger er hermed ændret!</p>'); return redirect()->route("users.account")->with('success#credentialschanged', '<p class="text-center">Dine oplysninger er hermed ændret!</p>');
@ -248,6 +261,41 @@ class UserController extends Controller
return Response::detect("users.editpass"); 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', '<p class="text-center">Der stod ikke det samme i `Nyt Password` & `Bekræft Nyt Password`!</p>');
} 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', '<p class="text-center">Det indtastede password i `Nuværende Password` er ikke dit nuværende password!</p>');
} 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', '<p class="text-center text-white">Dit password er hermed ændret!</p>');
}
} 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', '<p class="text-center">Dine oplysninger er hermed ændret!</p>');
}
$users = User::query()->paginate(20);
return Response::detect("users.index", [
"users" => $users
]);
}
public function search(Request $request){ public function search(Request $request){
if($request->ajax()){ if($request->ajax()){

View File

@ -22,6 +22,7 @@ class PermissionSeeder extends Seeder
"user.show" => "Shows another user profile.", "user.show" => "Shows another user profile.",
"user.edit" => "Allows editing of other users.", "user.edit" => "Allows editing of other users.",
"user.delete" => "Allows deleting of other users.", "user.delete" => "Allows deleting of other users.",
"ownuser.edit" => "Allows editing of your own user",
/** /**
* The CALENDAR specific permissions * The CALENDAR specific permissions

View File

@ -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.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.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", "=", "washing.machine.reservation.list")->first());
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "ownuser.edit")->first());
//Give permissions to Bruger (id: 2) //Give permissions to Bruger (id: 2)
foreach ($brugerPermissions as $permission) { foreach ($brugerPermissions as $permission) {

View File

@ -26,6 +26,15 @@ form {
justify-content: center; 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 { .btn {
border: 0; border: 0;
border-radius: 4px; border-radius: 4px;
@ -97,6 +106,23 @@ input.appinput {
color: white; 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 { .d-flex {
display: flex; display: flex;
} }

View File

@ -26,6 +26,15 @@ form {
justify-content: center; 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 { .btn {
border: 0; border: 0;
border-radius: 4px; border-radius: 4px;
@ -97,6 +106,23 @@ input.appinput {
color: white; 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 { .d-flex {
display: flex; display: flex;
} }
@ -6633,6 +6659,14 @@ main {
p { p {
font-size: 4vw; font-size: 4vw;
} }
.links {
position: absolute;
width: calc(100% - 40px);
bottom: 8px;
height: 2rem;
justify-content: center;
}
} }
.mock-up-link { .mock-up-link {
@ -6943,9 +6977,3 @@ main {
display: inline-block; display: inline-block;
} }
.spaneye {
position: absolute;
font-size: 25px;
color: grey;
margin: 7.5px 0 0 -45px;
}

View File

@ -6,6 +6,15 @@ form {
justify-content: center; 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 { .btn {
border: 0; border: 0;
border-radius: 4px; border-radius: 4px;
@ -60,3 +69,23 @@ input.appinput {
opacity: 1; opacity: 1;
color: white; 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;
}

View File

@ -66,6 +66,14 @@ and (max-width : 900px)
p { p {
font-size: 4vw; font-size: 4vw;
} }
.links {
position: absolute;
width: calc(100% - 40px);
bottom: 8px;
height: 2rem;
justify-content: center;
}
} }

View File

@ -11,7 +11,8 @@
@section("content") @section("content")
<h1>Rediger Bruger:</h1> <h1>Rediger Bruger:</h1>
<form method="post" action="{{ route("users.update", ['user' => $user]) }}"> {!! session()->get('error#passnotsame') !!}
<form method="post" action="{{ route("users.update", ['user' => $user]) }}" style="display: inline-table;">
@csrf @csrf
@method("put") @method("put")
<label for="name_first">Fornavn:</label> <label for="name_first">Fornavn:</label>
@ -21,13 +22,15 @@
<label for="email">Email:</label> <label for="email">Email:</label>
<input type="email" name="email" id="email" value="{{ $user->email }}" required> <input type="email" name="email" id="email" value="{{ $user->email }}" required>
<label for="password1">Password: (Forblives blank, hvis password ikke skal ændres)</label> <label for="password1">Password: (Forblives blank, hvis password ikke skal ændres)</label>
<input type="password" name="password" id="password1" value=""> <input type="password" name="password" id="password1" value="" placeholder="******">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password" id="fa-new" onclick="show('password1', 'fa-new')"></span>
<label for="password2">Confirm Password: (Forblives blank, hvis password ikke skal ændres)</label> <label for="password2">Confirm Password: (Forblives blank, hvis password ikke skal ændres)</label>
<input type="password" id="password2" value=""> <input type="password" name="password2" id="password2" value="" placeholder="******">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password" id="fa-confirm" onclick="show('password2', 'fa-confirm')"></span>
<label for="tel">Telefon nr:</label> <label for="tel">Telefon nr:</label>
<input type="tel" name="phone" id="tel" value="{{ $user->phone }}" required> <input type="tel" name="phone" id="tel" value="{{ $user->phone }}" required>
<label for="role">Rolle: (Brug ctrl og shift til at vælge flere)</label> <label for="role">Rolle: (Brug ctrl og shift til at vælge flere)</label>
<select name="roles[]" id="roles" class="mb-2" multiple="multiple" required> <select class="w-100" name="roles[]" id="roles" class="mb-2" multiple="multiple" required>
@if(count($user->roles) == 0) @if(count($user->roles) == 0)
<option disabled selected> -- Vælg Rolle(r) -- </option> <option disabled selected> -- Vælg Rolle(r) -- </option>
<option value>Ingen Rolle</option> <option value>Ingen Rolle</option>
@ -51,4 +54,34 @@
</select> </select>
<input type="submit" class="btn btn-dark text-white" value="Rediger"> <input type="submit" class="btn btn-dark text-white" value="Rediger">
</form> </form>
<style>
input {
width: calc(100% - 8px);
}
.fa-eye {
position: absolute;
font-size: 25px;
color: grey;
margin: 7.5px 0 0 -45px;
}
</style>
@endsection
@section("scripts")
<script>
function show($passID, $faID) {
var inputPass = document.getElementById($passID);
var faEye = document.getElementById($faID);
if (inputPass.type === "password") {
inputPass.type = "text";
faEye.style.color = "#000";
} else {
inputPass.type = "password";
faEye.style.color = "#808080";
}
}
</script>
@endsection @endsection

View File

@ -7,7 +7,7 @@
@section("content") @section("content")
<main> <main>
<h1 class="text-center sde-blue mt-0">Konto</h1> <h1 class="text-center sde-blue mt-0">Konto</h1>
<form method="post" action="{{ route("users.update", ['user' => Auth::user()]) }}"> <form method="post" action="{{ route("users.accountupdate", ['user' => Auth::user()]) }}">
@csrf @csrf
@method("put") @method("put")
<span>Navn:</span> <span>Navn:</span>

View File

@ -7,23 +7,34 @@
@section("content") @section("content")
<main> <main>
<h1 class="text-center sde-blue mt-0">Konto</h1> <h1 class="text-center sde-blue mt-0">Konto</h1>
<form method="post" action="{{ route("users.update", ['user' => Auth::user()]) }}" style="display: block;"> <form method="post" action="{{ route("users.accountupdate", ['user' => Auth::user()]) }}" style="display: inline-table;">
@csrf @csrf
@method("put") @method("put")
<span>Nuværende Password:</span> <span>Nuværende Password:</span>
<input type="password" name="oldpassword" id="old" placeholder="******" required style="width: calc(100% - 12px)"> <div class="input-group text-left">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password spaneye" id="fa-old" onclick="show('old', 'fa-old')"></span> <input type="password" class="form-control" name="oldpassword" id="old" placeholder="******">
<span class="fa fa-fw fa-eye field-icon toggle-password" id="fa-old" onclick="show('old', 'fa-old')"></span>
</div>
<span>Nyt Password:</span> <span>Nyt Password:</span>
<input class="w-100" type="password" name="password" id="new" placeholder="******" required style="width: calc(100% - 12px)"> <div class="input-group text-left">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password spaneye" id="fa-new" onclick="show('new', 'fa-new')"></span> <input type="password" class="form-control" name="password" id="new" placeholder="******" required>
<span class="fa fa-fw fa-eye field-icon toggle-password" id="fa-new" onclick="show('new', 'fa-new')"></span>
</div>
<span>Bekræft Nyt Password:</span> <span>Bekræft Nyt Password:</span>
<input class="w-100" type="password" name="confirmpassword" id="confirm" placeholder="******" required style="width: calc(100% - 12px)"> <div class="input-group text-left">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password spaneye" id="fa-confirm" onclick="show('confirm', 'fa-confirm')"></span> <input type="password" class="form-control" name="confirmpassword" id="confirm" placeholder="******" required>
<span class="fa fa-fw fa-eye field-icon toggle-password" id="fa-confirm" onclick="show('confirm', 'fa-confirm')"></span>
</div>
{!! session()->get('error#notsamepass') !!} {!! session()->get('error#notsamepass') !!}
{!! session()->get('error#oldpass') !!} {!! session()->get('error#oldpass') !!}
<button type="submit" class="btn text-center btn-sde-blue mt-1">Rediger</button> <button type="submit" class="btn text-center btn-sde-blue mt-1">Rediger</button>
</form> </form>
</main> </main>
<style>
input {
width: calc(100% - 8px);
}
</style>
@endsection @endsection
@section("scripts") @section("scripts")

View File

@ -13,10 +13,6 @@ use Illuminate\Support\Facades\Route;
| |
*/ */
//Route::get('/', function () {
// return view('welcome');
//});
Route::get("/", "RootController@index")->name("root.index"); Route::get("/", "RootController@index")->name("root.index");
Route::get("/home", "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", "UserController@account")->name("users.account");
Route::get("/account/edit", "UserController@accountedit")->name("users.accountedit"); Route::get("/account/edit", "UserController@accountedit")->name("users.accountedit");
Route::get("/account/editpass", "UserController@accounteditpass")->name("users.accounteditpass"); 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("/events/signups", "EventController@signups")->name("events.signups");
Route::get("phones", "PhoneController@index")->name("phones.index"); 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("/contactsapi", "ContactController@search")->name("contacts.search");
Route::get("/eventsapi", "EventController@search")->name("events.search"); Route::get("/eventsapi", "EventController@search")->name("events.search");
Route::get("/menuplansapi", "MenuPlanController@search")->name("menu-plans.search"); Route::get("/menuplansapi", "MenuPlanController@search")->name("menu-plans.search");
Route::get("/rolesapi", "RolesController@search")->name("roles.search"); Route::get("/rolesapi", "RolesController@search")->name("roles.search");
Route::get("/userapi", "UserController@search")->name("users.search"); Route::get("/userapi", "UserController@search")->name("users.search");
Route::get("/vaskeapi", "WashingReservationController@search")->name("washing-reservations.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"); Route::get("/risrosapi", "FeedbackController@search")->name("feedbacks.search");