v0.11.2b - Made a support user account

This commit is contained in:
Neerholt 2020-09-07 08:28:49 +02:00
parent b62582e039
commit 84f5c51c48
6 changed files with 103 additions and 37 deletions

View File

@ -29,7 +29,7 @@ class RolesController extends Controller
*/
public function index(Request $request)
{
$roles = Role::query()->paginate($request->input("limit", 20));
$roles = Role::query()->where("id", "!=", 1)->paginate($request->input("limit", 20));
return Response::detect("roles.index", [ "roles" => $roles]);
}
@ -42,7 +42,6 @@ class RolesController extends Controller
public function create()
{
return Response::detect("roles.create");
}
/**
@ -105,6 +104,9 @@ class RolesController extends Controller
*/
public function edit($id)
{
if($id == 1)
return redirect()->route("roles.index");
$role = Role::find($id);
return Response::detect("roles.edit", ["role" => $role]);
}
@ -118,6 +120,9 @@ class RolesController extends Controller
*/
public function update(Request $request, $id)
{
if($id == 1)
return redirect()->route("roles.index");
$data = $request->validate([
"name" => "required|max:255",
"description" => "required|max:255"
@ -165,6 +170,9 @@ class RolesController extends Controller
*/
public function destroy($id)
{
if($id == 1)
return redirect()->route("roles.index");
$role = Role::find($id);
$role->delete();
return redirect()->route("roles.index");
@ -179,7 +187,7 @@ class RolesController extends Controller
"<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>";
$roles = DB::table('roles')->where('name', 'LIKE',$request->search.'%')->get();
$roles = DB::table('roles')->where("id", "!=", 1)->where('name', 'LIKE',$request->search.'%')->get();
if(count($roles) !== 0){
foreach ($roles as $key => $role){

View File

@ -42,7 +42,7 @@ class UserController extends Controller
public function index(Request $request)
{
//$users = User::query()->paginate($request->query("page", 20));
$users = User::query()->orderBy('id', 'asc')->paginate(20);
$users = User::query()->where("id", "!=", 1)->orderBy('id', 'asc')->paginate(20);
return Response::detect("users.index", [ "users" => $users ]);
}
@ -91,10 +91,16 @@ class UserController extends Controller
$user = new User($data);
if($request->file("resource")) {
$user->resource_id = ResourceController::store($request)->id;
}
$user->assignRole($roles);
$user->save();
return redirect()->route('users.index');
}
@ -124,6 +130,10 @@ class UserController extends Controller
$roles = Role::all();
$user = User::find($id);
if($id == 1)
return redirect()->route("users.index");
return Response::detect("users.edit", [
"user" => $user,
"roles" => $roles,
@ -139,6 +149,9 @@ class UserController extends Controller
*/
public function update(Request $request, $id)
{
if($id == 1)
return redirect()->route("users.index");
$user = User::find($id);
if($request->file("resource")) {
@ -191,6 +204,8 @@ class UserController extends Controller
*/
public function destroy($id)
{
if($id == 1)
return redirect()->route("users.index");
if(Auth::user()->hasPermissionTo("user.delete")) {
$user = User::find($id);
@ -421,6 +436,7 @@ class UserController extends Controller
"<th>Email</th>".
"<th>Tlf nr</th>".
"<th>Rolle(r)</th>".
'<th style="width: 1em;"><img class="w-100" src="'. asset('/images/icons/eye.svg') .'" alt="ShowImage"></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>";
@ -436,18 +452,18 @@ class UserController extends Controller
//filter search
if($request->isCheck === "navn")
$users = User::query()->where('name_first', 'LIKE',$request->search.'%')->get();
$users = User::query()->firstWhere("id", "!=", 1)->where('name_first', 'LIKE',$request->search.'%')->get();
elseif ($request->isCheck === "efternavn")
$users = User::query()->where('name_last', 'LIKE',$request->search.'%')->get();
$users = User::query()->firstWhere("id", "!=", 1)->where('name_last', 'LIKE',$request->search.'%')->get();
elseif ($request->isCheck === "email")
$users = User::query()->where('email', 'LIKE',$request->search.'%')->get();
$users = User::query()->firstWhere("id", "!=", 1)->where('email', 'LIKE',$request->search.'%')->get();
elseif ($request->isCheck === "telefon")
$users = User::query()->where('phone', 'LIKE',$request->search.'%')->get();
$users = User::query()->firstWhere("id", "!=", 1)->where('phone', 'LIKE',$request->search.'%')->get();
elseif ($request->isCheck === "telefon")
$users = User::query()->where('phone', 'LIKE',$request->search.'%')->get();
$users = User::query()->firstWhere("id", "!=", 1)->where('phone', 'LIKE',$request->search.'%')->get();
elseif ($request->isCheck) {
$roles = Role::query()->where('name', 'LIKE', $request->search . '%')->get();
$usersTEMP = User::all();
$usersTEMP = User::query()->where("id", "!=", 1)->get();
$users = [];
foreach ($usersTEMP as $user) {
@ -460,20 +476,22 @@ class UserController extends Controller
}
if($request->search == "")
$users = User::all();
$users = User::query()->where("id", "!=", 1)->get();
} else {
$usersTEMP = User::query()
->whereKeyNot(1)
->where('name_first', 'LIKE', $request->search . '%')
->orWhere('name_last', 'LIKE', $request->search . '%')
->orWhere('phone', 'LIKE', $request->search . '%')
->orWhere('email', 'LIKE', $request->search . '%')
->get();
->get()->except(1);
$roles = Role::query()->where('name', 'LIKE', $request->search . '%')->get();
$users = new Collection();
$allUsers = User::all();
$allUsers = User::query()->where("id", "!=", 1)->get();
//For hver user i systemet, check om han har en af de roller der matcher søgeordet
foreach ($allUsers as $user) {
@ -501,7 +519,7 @@ class UserController extends Controller
}
if($request->search == "")
$users = User::all();
$users = User::query()->where("id", "!=", 1)->get();
$unique = $users->flatten()->unique('phone');
@ -515,11 +533,14 @@ class UserController extends Controller
$roles = null;
$rolesString = null;
foreach (User::all() as $usr) {
foreach (User::query()->where("id", "!=", 1)->get() as $usr) {
if($usr->id == $user->id)
$roles = $usr->roles;
}
if(!is_a($roles, 'Illuminate\Database\Eloquent\Collection'))
dd([$roles, $user]);
for($i = 0; $i < count($roles); $i++) {
if(count($roles)-1 != $i) {
$rolesString .= $roles[$i]->name.",";
@ -533,8 +554,13 @@ class UserController extends Controller
'<td>' . $user->name_last . '</td>'.
'<td>' . $user->email . '</td>'.
'<td>' . $user->phone .'</td>'.
'<td>' . $rolesString .'</td>'.
'<td><a href="'. route("users.edit", [ "user" => $user->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td>' . $rolesString .'</td>';
if($user->resource_id !== null)
$output .= '<td style="overflow: visible"><a class="showUsers"><img src="'. asset('/images/icons/eye-dark.svg') .'"><img src="'. asset(\App\Resource::query()->where("id", "=", $user->resource_id)->first()->filename).'" class="showUserImages"></a></td>';
else
$output .= '<td style="overflow: visible"><a class="showUsers noImages"><img src="'.asset('/images/icons/eye-dark.svg').'"><img src="" class="showUserImages"></a></td>';
$output .= '<td><a href="'. route("users.edit", [ "user" => $user->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="' .route("users.destroy", [ "user" => $user->id ]). '" class="w-100 nostyle">'.
csrf_field().
method_field("delete").
@ -553,6 +579,7 @@ class UserController extends Controller
'<td></td>'.
'<td></td>'.
'<td></td>'.
'<td></td>'.
'</tr>';
}
return Response($output);

View File

@ -7127,11 +7127,11 @@ main {
html,
body {
background-color: #2c2f33;
background-color: #2F3136;
}
main {
background-color: #2c2f33;
background-color: #2F3136;
}
* {

View File

@ -1,9 +1,9 @@
html, body {
background-color: #2c2f33;
background-color: #2F3136;
}
main {
background-color: #2c2f33;
background-color: #2F3136;
}
* {

View File

@ -11,7 +11,7 @@
@section("content")
<h1 id="errormesseages" >Opret Bruger:</h1>
<form method="post" action="{{ route("users.store") }}" onsubmit="return checkInputs()">
<form method="post" action="{{ route("users.store") }}" onsubmit="return checkInputs()" enctype="multipart/form-data">
@csrf
<label for="name_first">Fornavn:</label>
<input type="text" name="name_first" id="name_first" placeholder="Fornavn" required>
@ -42,6 +42,8 @@
<option value="{{ $role->name }}">{{ $role->name }}</option>
@endforeach
</select>
<label for="fileuploade">Skift brugerens profile billede:</label>
<input id="fileuploade" type="file" name="resource" accept="image/*">
<input type="submit" class="btn btn-dark text-white" value="Opret">
</form>
@endsection

View File

@ -10,7 +10,7 @@
margin-bottom: 7px;
width: auto;
@if(request()->cookie("mode") == "dark")
background-color: rgba(0,0,0, 0.3);
background-color: #36393F;
@else
background-color: white;
@endif
@ -69,12 +69,27 @@
.information{
text-align: center;
@if(request()->cookie("mode") == "dark")
background-color: #202225;
@else
background-color: rgba(240,240,240,0.8);
@endif
border-bottom: 1px solid rgba(0, 0, 0, .1);
width: 100%;
height: 25px;
}
.information2{
text-align: center;
@if(request()->cookie("mode") == "dark")
background-color: #202225;
@else
background-color: rgba(240,240,240,0.8);
@endif
width: 100%;
height: 25px;
}
.card > .img > a > img, .card > .img > img {
width: 100%;
}
@ -125,20 +140,34 @@
<div class="title">{{ $new->subname }}</div>
@if($new->resource_id !== null)
<div class="header" style="background-size: cover; background-image: url('{{ asset(\App\Resource::query()->where("id", "=", $new->resource_id)->first()->filename) }}');"></div>
@endif
<div class="information">{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime(\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->date))->format('d/m/Y \k\l\. H:i') }} | {{\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->accountable}} </div>
<div class="container">
{!! \App\Helpers::closetags(substr($new->content, 0, 300) ) !!}
<div class="row" style="justify-content: space-between; margin-top: 16px; border-top: 1px solid rgba(0, 0, 0, .2);">
@if (count(\App\UserEvent::query()->where('event_id', '=', $new->arrangement_id)->where('user_id', '=', Auth::user()->id)->get()) > 0)
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="javascript:void(0);" onclick="ajaxCall({{ $new->arrangement_id }}, this)" >{{__('msg.afmeld')}}</a>
@else {{-- ^ If you're already participating in the event, then show a ´cancel´ button - v Else show a ´participate´ button --}}
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="javascript:void(0);" onclick="ajaxCall({{ $new->arrangement_id }}, this)" >{{__('msg.tilmeld')}}</a>
@endif
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="{{route("events.show", ["event" => $new->arrangement_id ])}}">{{__('msg.læsmere')}}</a>
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="{{route("events.accountsignups", ["event" => $new->arrangement_id ])}}">{{__('msg.sedeltagere')}}</a>
<div class="information">{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime(\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->date))->format('d/m/Y \k\l\. H:i') }} | {{\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->accountable}} </div>
<div class="container">
{!! \App\Helpers::closetags(substr($new->content, 0, 300) ) !!}
<div class="row" style="justify-content: space-between; padding-top: 12px; border-top: 1px solid rgba(0, 0, 0, .2);">
@if (count(\App\UserEvent::query()->where('event_id', '=', $new->arrangement_id)->where('user_id', '=', Auth::user()->id)->get()) > 0)
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="javascript:void(0);" onclick="ajaxCall({{ $new->arrangement_id }}, this)" >{{__('msg.afmeld')}}</a>
@else {{-- ^ If you're already participating in the event, then show a ´cancel´ button - v Else show a ´participate´ button --}}
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="javascript:void(0);" onclick="ajaxCall({{ $new->arrangement_id }}, this)" >{{__('msg.tilmeld')}}</a>
@endif
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="{{route("events.show", ["event" => $new->arrangement_id ])}}">{{__('msg.læsmere')}}</a>
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="{{route("events.accountsignups", ["event" => $new->arrangement_id ])}}">{{__('msg.sedeltagere')}}</a>
</div>
</div>
</div>
@else
<div class="container">
{!! \App\Helpers::closetags(substr($new->content, 0, 300) ) !!}
<div class="information2">{{ \Illuminate\Support\Facades\Date::createFromTimeStamp(strtotime(\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->date))->format('d/m/Y \k\l\. H:i') }} | {{\App\Event::query()->where('id', '=', $new->arrangement_id)->first()->accountable}} </div>
<div class="row" style="justify-content: space-between; padding-top: 12px; border-top: 1px solid rgba(0, 0, 0, .2);">
@if (count(\App\UserEvent::query()->where('event_id', '=', $new->arrangement_id)->where('user_id', '=', Auth::user()->id)->get()) > 0)
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="javascript:void(0);" onclick="ajaxCall({{ $new->arrangement_id }}, this)" >{{__('msg.afmeld')}}</a>
@else {{-- ^ If you're already participating in the event, then show a ´cancel´ button - v Else show a ´participate´ button --}}
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="javascript:void(0);" onclick="ajaxCall({{ $new->arrangement_id }}, this)" >{{__('msg.tilmeld')}}</a>
@endif
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="{{route("events.show", ["event" => $new->arrangement_id ])}}">{{__('msg.læsmere')}}</a>
<a style="margin: 0; padding: 0; font-weight: 700;" class="sde-blue text-center" href="{{route("events.accountsignups", ["event" => $new->arrangement_id ])}}">{{__('msg.sedeltagere')}}</a>
</div>
</div>
@endif
</div>
@else<!--Code that prints guides-->
<div class="card">
@ -151,7 +180,7 @@
<div class="container" style="margin-top: 8px;">
{!! \App\Helpers::closetags(substr($new->content, 0, 300) ) !!}
@if ($new->type == 'Guide') {{-- Else if's displaying guides, then show `Læs mere` --}}
<div class="row" style="justify-content: center; border-top: 1px solid rgba(0, 0, 0, .2);">
<div class="row" style="justify-content: center; padding-top: 12px; border-top: 1px solid rgba(0, 0, 0, .2);">
<a style="font-weight: 700;" href="{{route("guides.show", ["guide" => $new->arrangement_id])}}" class="sde-blue">{{__('msg.læsmere')}}</a>
</div>
@endif {{-- Else if it's a menu or news, then don't show a button at bottom --}}