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)
{
$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.

View File

@ -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");
}
/**

View File

@ -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
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', '<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->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', '<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.
@ -148,9 +160,10 @@ class UserController extends Controller
$user->update($data);
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.
$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>');
@ -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', '<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){
if($request->ajax()){

View File

@ -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

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.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) {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -11,7 +11,8 @@
@section("content")
<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
@method("put")
<label for="name_first">Fornavn:</label>
@ -21,13 +22,15 @@
<label for="email">Email:</label>
<input type="email" name="email" id="email" value="{{ $user->email }}" required>
<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>
<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>
<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>
<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)
<option disabled selected> -- Vælg Rolle(r) -- </option>
<option value>Ingen Rolle</option>
@ -51,4 +54,34 @@
</select>
<input type="submit" class="btn btn-dark text-white" value="Rediger">
</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

View File

@ -7,7 +7,7 @@
@section("content")
<main>
<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
@method("put")
<span>Navn:</span>

View File

@ -7,23 +7,34 @@
@section("content")
<main>
<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
@method("put")
<span>Nuværende Password:</span>
<input type="password" name="oldpassword" id="old" placeholder="******" required style="width: calc(100% - 12px)">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password spaneye" id="fa-old" onclick="show('old', 'fa-old')"></span>
<div class="input-group text-left">
<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>
<input class="w-100" type="password" name="password" id="new" placeholder="******" required style="width: calc(100% - 12px)">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password spaneye" id="fa-new" onclick="show('new', 'fa-new')"></span>
<div class="input-group text-left">
<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>
<input class="w-100" type="password" name="confirmpassword" id="confirm" placeholder="******" required style="width: calc(100% - 12px)">
<span toggle="#password-field" class="fa fa-fw fa-eye field-icon toggle-password spaneye" id="fa-confirm" onclick="show('confirm', 'fa-confirm')"></span>
<div class="input-group text-left">
<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#oldpass') !!}
<button type="submit" class="btn text-center btn-sde-blue mt-1">Rediger</button>
</form>
</main>
<style>
input {
width: calc(100% - 8px);
}
</style>
@endsection
@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("/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");