This commit is contained in:
2020-08-04 15:29:18 +02:00
33 changed files with 45 additions and 634 deletions
-34
View File
@@ -1,34 +0,0 @@
<?php
//The Model to a certain Controller, should contain a class with Controller name to which it belongs.
// Allows needed strings to passed onto the database. if there is none needed. the class should appear empty.
//Reference to where the file belongs.
namespace App;
//allows the use of Model library
use Illuminate\Database\Eloquent\Model;
//Class of which should extend Model Library
class Album extends Model
{
//protected variable which contains name of database field(s) to be filled.
protected $fillable = [
'name'
];
public function parentAlbum()
{
return $this->belongsTo('App\Album');
}
public function images()
{
return $this->hasMany('App\Image');
}
public function videos()
{
return $this->hasMany('App\Video');
}
}
-16
View File
@@ -1,16 +0,0 @@
<?php
//The Model to a certain Controller, should contain a class with Controller name to which it belongs.
// Allows needed strings to passed onto the database. if there is none. class should appear empty.
//Reference to where the file belongs.
namespace App;
//allows the use of Model library
use Illuminate\Database\Eloquent\Model;
//Class of which should extend Model Library
class CalendarDate extends Model
{
//
}
-17
View File
@@ -1,17 +0,0 @@
<?php
//The Model to a certain Controller, should contain a class with Controller name to which it belongs.
// Allows needed strings to passed onto the database. if there is none. class should appear empty.
//Reference to where the file belongs.
namespace App;
//allows the use of Model library
use Illuminate\Database\Eloquent\Model;
//Class of which should extend Model Library
class CalendarEvent extends Model
{
//
}
-25
View File
@@ -1,25 +0,0 @@
<?php
//The Model to a certain Controller, should contain a class with Controller name to which it belongs.
// Allows needed strings to passed onto the database. if there is none. class should appear empty.
//Reference to where the file belongs.
namespace App;
//allows the use of Model library
use Illuminate\Database\Eloquent\Model;
//Class of which should extend Model Library
class ExternalLink extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
//protected variable which contains name of database field(s) to be filled.
protected $fillable = [
'name', "link"
];
}
+1 -1
View File
@@ -7,6 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class Guide extends Model
{
protected $fillable = [
'name', 'guideArticles'
'name', 'guide_articles'
];
}
@@ -1,85 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Album;
use Illuminate\Http\Request;
class AlbumController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Album $album
* @return \Illuminate\Http\Response
*/
public function show(Album $album)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Album $album
* @return \Illuminate\Http\Response
*/
public function edit(Album $album)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Album $album
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Album $album)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Album $album
* @return \Illuminate\Http\Response
*/
public function destroy(Album $album)
{
//
}
}
@@ -1,130 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\ExternalLink;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class ExternalLinkController extends Controller
{
function __construct()
{
$this->middleware([ "auth" ]);
$this->middleware("permission:link.external.list")->only("index");
$this->middleware("permission:link.external.create")->only(["create", "store"]);
$this->middleware("permission:link.external.show")->only("show");
$this->middleware("permission:link.external.edit")->only(["edit", "update"]);
$this->middleware("permission:link.external.delete")->only("destroy");
}
/**
* 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)
{
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
return Response::detect("external-links.index", [ "links" => $externalLink ]);
}
/**
* 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("external-links.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)
{
$requestBody = $request->validate([
"name" => "required|max:255",
"link" => "required|max:255"
]);
$externalLink = new ExternalLink($requestBody);
$saved = $externalLink->save();
if(!$saved){
return Response::detect("external-links.store");
}else{
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
return Response::detect("external-links.index", ['links' => $externalLink]);
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return Response::detect("external-links.show", [ "link" => $id]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$link = ExternalLink::find($id);
return Response::detect("external-links.edit", ["link" => $link]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$data = $request->all();
$link = ExternalLink::find($id);
$link->update($data);
$saved = $link->save();
if(!$saved){
return Response::detect("external-links.update", [ "link" => $link]);
}else{
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
return Response::detect("external-links.index", ['links' => $externalLink]);
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$link = ExternalLink::find($id);
$link->delete();
return redirect()->route("external-links.index");
}
}
@@ -57,7 +57,7 @@ class GuideController extends Controller
//Me no sure what to store mester big smoke :)
$requestGuide = $request->validate([
"name" => "required|max:255",
"guideArticles" => "required",
"guide_articles" => "required",
]);
$guide = new Guide($requestGuide);
@@ -105,7 +105,7 @@ class GuideController extends Controller
{
$data = $request->validate([
"name" => "required|max:255",
"guideArticles" => "required",
"guide_articles" => "required",
]);
$guidee = Guide::query()->where("id", "=", $guide->id)->first();
@@ -233,11 +233,32 @@ class UserController extends Controller
$user = User::query()->where('email', '=', $request->email)->first();
if($user == null){
return redirect()->back();
return redirect()->back()->with('errornosuchuser', '<p>Denne email findes ikke i systemet!</p>');
}
//Send email
//TODO: Implement mail.
$email = $user->email;
$pswd = "";
//Generate password
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$n = 6;
$randomString = '';
for ($i = 0; $i < $n; $i++) {
$index = rand(0, strlen($characters) - 1);
$randomString .= $characters[$index];
}
$pswd = $randomString;
$user->setPasswordAttribute($pswd);
$user->update();
$subject = "SDE Skolehjem reset password";
$msg = "Hej " . $user->name_first . " ". $user->name_last . ".\n\nDin adgangskode er nu: " . $pswd;
mail($email, $subject, $msg);
return redirect()->route('users.login');
}
@@ -67,15 +67,13 @@ class WashingReservationController extends Controller
$machineReservation = new WashingReservation($data);
$machineReservation->user_id = auth()->user()->id;
$machineReservation->save();
$saved = $machineReservation->save();
$allMachineReservations = WashingReservation::query()->where('time', '=', $request->time)->where('machine_id', '=', $request->machine_id)->get();
if (!$saved) {
return Response::detect("washing-reservations.store", [
"washing_reservation" => $machineReservation
]);
if (count($allMachineReservations) > 0) {
return redirect()->route("washing-reservations.create", ["washing_reservation" => $machineReservation])->with('ReservationExists', '<p class="text-center"><b>Der findes allerede en reservation til denne tid, men denne vaskemaskine!</b></p>');
} else {
$machineReservation->save();
$reservations = WashingReservation::query()->paginate($request->input("limit", 20));
return redirect()->route('washing-reservations.appindex', ["reservations" => $reservations]);
@@ -174,7 +172,7 @@ class WashingReservationController extends Controller
foreach ($reservations as $reservation){
array_push($times, $reservation->time);
}
//2020-07-28%
$output = json_encode(['date' => $date, 'washingmachines' => $machines, 'unavailable_times' => $times]);
return Response($output);
}