This commit is contained in:
Neerholt 2020-06-29 12:21:27 +02:00
commit 6820dc3e3b
12 changed files with 413 additions and 0 deletions

View File

@ -0,0 +1,203 @@
<?php
namespace App\Http\Controllers;
use App\Staff;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class StaffController extends Controller
{
public function __construct()
{
// $this->middleware([ "auth" ])->only("logout");
// $this->middleware([ "guest" ])->only("login");
//
// $this->middleware([ "permission:user.list", "role:admin" ])->only("index");
// $this->middleware([ "permission:user.show", "role:admin" ])->only("show");
// $this->middleware([ "permission:user.edit", "role:admin" ])->only([ "edit", "update" ]);
// $this->middleware([ "permission:user.delete", "role:admin" ])->only("delete");
}
/**
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request)
{
$staff = Staff::query()->paginate($request->query("page", 20));
return Response::detect("staff.index", [ "staff" => $staff ]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
{
return Response::detect("staff.create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function store(Request $request)
{
Log::debug("STORE FUNCTION");
$data = $request->validate([
"name_first" => "required|max:255",
"name_last" => "required|max:255",
"email" => "required|email|unique:users",
"password" => "required|max:60",
"phone" => "required|unique:users",
]);
Log::debug("FINISHED VALIDATION?");
$staff = new Staff($data);
Log::debug("CREATED USER [NOT PERSISTED YET]");
$staff->save();
Log::debug("SAVED STAFF");
return view("staff.store");
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show($id)
{
$staff = Staff::find($id);
return Response::detect("staff.show", [
"staff" => $staff
]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function edit($id)
{
$staff = Staff::find($id);
return Response::detect("staff.edit", [
"staff" => $staff
]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function update(Request $request, $id)
{
$data = $request->all();
// $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();
// return Response::detect("users.edit", [
// "user" => $user
// ]);
// }
//TODO: Implement when security's ready!!!
// else if(Auth::user()->hasPermissionTo("user.edit")) {
$staff = Staff::find($id);
/** @var Staff $staff */
$staff->update($data);
$staff->save();
// }
$staffs = Staff::query()->paginate(20);
return Response::detect("users.index", [
"staffs" => $staffs
]);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @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")) {
$staff = Staff::find($id);
$staff->delete();
// }
return redirect()->route("staff.index");
}
/*******************************************/
/* Authentication */
/*******************************************/
public function showLogin() {
return view("admin.staff.login");
}
public function login(Request $request) {
$data = $request->only("email", "password");
if(Auth::attempt($data)) {
//TODO: Implement home?
return redirect()->route("staff.index");
}
return redirect()->back(303);
}
public function logout(Request $request) {
Auth::logout();
return redirect()->to("/");
}
}

10
skolehjem/app/Staff.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Staff extends Model
{
//
}

View File

@ -0,0 +1,30 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Personal - Opret
@endsection
@section("path")
<a href="{{ route('staff.create') }}" class="text-white">Opret Personal</a> /
@endsection
@section("content")
<h1>Opret Personal:</h1>
<form method="post" action="{{ route("staff.store") }}">
@csrf
<label for="name_first">Fornavn:</label>
<input type="text" name="name_first" id="name_first" placeholder="Fornavn" required>
<label for="name_last">Efternavn:</label>
<input type="text" name="name_last" id="name_last" placeholder="Efternavn" required>
<label for="email">Email:</label>
<input type="email" name="email" id="email" placeholder="x@y.z" required>
<label for="password1">Password:</label>
<input type="password" name="password" placeholder="Password" id="password1" required>
<label for="password2">Bekræft Password:</label>
<input type="password" id="password2" placeholder="Bekræft Password" required>
<label for="tel">Telefon nr:</label>
<input type="tel" name="phone" id="tel" placeholder="12345678" pattern="[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{2}" required>
<input type="submit" class="btn btn-dark text-white" value="Opret">
</form>
@endsection

View File

@ -0,0 +1,13 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Personal - Fjern
@endsection
@section("path")
<a href="{{ route('staff.delete') }}" class="text-white">Fjern Personal</a> /
@endsection
@section("content")
@endsection

View File

@ -0,0 +1,31 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Personal - Rediger
@endsection
@section("path")
<a href="{{ route('staff.edit', ['staff' => $staff]) }}" class="text-white">Rediger Personal</a> /
@endsection
@section("content")
<h1>Rediger Personal:</h1>
<form method="post" action="{{ route("staff.update", ['staff' => $staff]) }}">
@csrf
@method("put")
<label for="name_first">Fornavn:</label>
<input type="text" name="name_first" id="name_first" value="{{ $staff->name_first }}" required>
<label for="name_last">Efternavn:</label>
<input type="text" name="name_last" id="name_last" value="{{ $staff->name_last }}" required>
<label for="email">Email:</label>
<input type="email" name="email" id="email" value="{{ $staff->name_email }}" required>
<label for="password1">Password:</label>
<input type="password" name="password" id="password1" value="" required>
<label for="password2">Confirm Password:</label>
<input type="password" id="password2" value="" required>
<label for="tel">Telefon nr:</label>
<input type="tel" name="phone" id="tel" value="{{ $staff->phone }}" required>
<input type="submit" class="btn btn-dark text-white" value="Rediger">
</form>
@endsection

View File

@ -0,0 +1,42 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Personal - Vis
@endsection
@section("path")
<a href="{{ route('staff.index') }}" class="text-white">Vis Personal</a> /
@endsection
@section("content")
<table class="tbl">
<tr>
<th>Fornavn</th>
<th>Efternavn</th>
<th>Email</th>
<th>Tlf nr</th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/pencil.svg') }}" alt="Update"></th>
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th>
</tr>
@foreach($staffs as $staff)
<tr>
<td>{{ $staff->name_first }}</td>
<td>{{ $staff->name_last }}</td>
<td>{{ $staff->email }}</td>
<td>{{ $staff->phone }}</td>
<td><a href="{{ route("users.edit", [ "staff" => $staff->id ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
<td>
<form method="post" action="{{ route("users.destroy", [ "staff" => $staff ]) }}" class="w-100">
@csrf
@method("delete")
<button type="submit"><img class="w-100" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
</form>
</td>
</tr>
@endforeach
</table>
{{ $staff->links() }}
@endsection

View File

@ -0,0 +1,27 @@
@extends("app.layout.base")
@section("title")
Login
@endsection
@section("content")
<main style="background-color: #00788a; height: 100%;">
<div class="brand">
<img src="{{URL::asset('/images/logos/Logo-hvid.svg')}}" alt="Syddansk Erhvervsskole">
</div>
<form action="" method="post">
@csrf
<input class="appinput" type="email" name="email" placeholder="Email" required>
<input class="appinput" type="password" name="password" placeholder="Password" required>
<label class="toggle">
<input class="toggle__input" type="checkbox" name="rememberpassword">
<span class="toggle__label">
<span class="toggle__text text-white">Remember password</span>
</span>
</label>
<input class="btn btn-dark" type="submit" value="Sign in">
<button class="btn" onclick="window.location = '';">Sign up</button>
</form>
<a class="text-white text-center" href="">Forgot password?</a>
</main>
@endsection

View File

@ -0,0 +1,14 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Home - Logud
@endsection
@section("path")
<a href="{{ route('staff.logout') }}" class="text-white">Logud</a> /
@endsection
@section("content")
@endsection

View File

@ -0,0 +1,14 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Personal - Vis
@endsection
@section("path")
<a href="{{ route('staff.index') }}" class="text-white">Vis Personal</a> /
@endsection
@section("content")
show.blade.php
@endsection

View File

@ -0,0 +1,14 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Personal - Opret
@endsection
@section("path")
<a href="{{ route('staff.create') }}" class="text-white">Opret Personal</a> /
@endsection
@section("content")
Personal blev (ikke) oprettet.
@endsection

View File

@ -0,0 +1,14 @@
@extends("admin.layout.base")
@extends("admin.layout.header")
@section("title")
Personal - Rediger
@endsection
@section("path")
<a href="{{ route('staff.edit') }}" class="text-white">Rediger Personal</a> /
@endsection
@section("content")
Din Personal blev (ikke) redigeret.
@endsection

View File

@ -29,6 +29,7 @@ Route::get("/logout", "UserController@logout")->name("users.logout");
Route::resource("contacts", "ContactController");
Route::resource("menu-plans", "MenuPlanController");
Route::resource("users", "UserController");
Route::resource("staff", "StaffController");
Route::resource("events", "EventController");
Route::resource("washing-machines", "WashingMachineController");
Route::resource("washing-reservations", "WashingReservationController");