Compare commits

...

10 Commits

Author SHA1 Message Date
Deon George
c9cd560b36 Rename AdminController to SwitchUserController with some optimisations 2022-06-28 21:52:05 +10:00
Deon George
b3471f31a0 Fix singleOrFail() args are optional 2022-02-02 12:05:03 +11:00
Deon George
71712d445f Fix when blade call has no arguments 2021-12-20 14:35:58 +11:00
Deon George
ef210651aa Switch Asset::add() to @themecss for metronic theme 2021-12-20 12:51:19 +11:00
Deon George
cbfd13ffce Minor changes to architect theme 2021-12-05 16:24:56 +11:00
Deon George
d9896fbe93 Asset::add cannot be used with {{}} 2021-12-01 17:07:08 +11:00
Deon George
d376c79fad Add more libraries 2021-11-24 16:23:01 +11:00
Deon George
ab86ddc386 Fix #e3e43b87 should use Asset::add instead of @asset 2021-11-24 16:22:43 +11:00
Deon George
e3e43b87f4 Change metronic to use @asset instead of @css 2021-11-23 17:30:20 +11:00
Deon George
0507dc83d8 Optimise calling dependant javascript in views 2021-11-23 14:25:51 +11:00
14 changed files with 569 additions and 113 deletions

View File

@@ -10,7 +10,6 @@
}
],
"require": {
"igaster/laravel-theme": "^2.0.17",
"creativeorange/gravatar": "^1.0",
"orchestra/asset": "^6.0"
},
@@ -27,7 +26,10 @@
"extra": {
"laravel": {
"providers": [
"Leenooks\\Providers\\LeenooksServiceProvider"
"Orchestra\\Asset\\AssetServiceProvider",
"Collective\\Html\\HtmlServiceProvider",
"Leenooks\\Providers\\LeenooksServiceProvider",
"Leenooks\\Providers\\CustomBladeServiceProvider"
]
}
},

View File

@@ -0,0 +1,114 @@
@extends('architect::layouts.auth')
@section('htmlheader_title')
Log in
@endsection
@section('content')
<!-- /.login-logo -->
<div class="app-container app-theme-white body-tabs-shadow">
<div class="app-container">
<div class="h-100 bg-animation">
<div class="d-flex h-100 justify-content-center align-items-center">
<div class="mx-auto app-login-box col-md-8">
@if(file_exists('login-note.html'))
<div class="mx-auto card text-white card-body bg-primary w-50">
<h5 class="text-white card-title"><i class="icon fa-2x fas fa-info pr-3"></i><span class="font-size-xlg">NOTE</span></h5>
<span class="w-100 pb-0">
{!! file_get_contents('login-note.html') !!}
</span>
</div>
@endif
<div class="modal-dialog w-100 mx-auto">
<div class="modal-content">
<form class="needs-validation" novalidate method="post">
{{ csrf_field() }}
<div class="modal-body">
<div class="h5 modal-title text-center">
<h4 class="mt-2">
<div class="app-logo mx-auto mb-3"><img class="w-75" src="{{ url('img/logo-h-lg.png') }}"></div>
<small>@lang('Sign in to <strong>:server</strong>',['server'=>'Foo'])</small>
</h4>
</div>
<div class="form-row">
<div class="col-md-12 mt-3">
<label class="mb-1">Email</label>
<input name="email" id="user" placeholder="" type="email" class="form-control" required="">
<div class="invalid-feedback">
@lang('Please enter your email')
</div>
</div>
<div class="col-md-12 mt-2">
<label class="mb-1">@lang('Password')</label>
<input name="password" id="password" placeholder="" type="password" class="form-control" required>
<div class="invalid-feedback">
@lang('Please enter your password')
</div>
</div>
</div>
</div>
<div class="modal-footer">
@if (count($errors) > 0)
<div class="alert alert-danger w-100">
<strong>Whoops!</strong> Something went wrong?<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="float-right">
<button class="btn btn-primary btn-lg">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('page-scripts')
<style>
label {
text-transform: uppercase;
letter-spacing: 0.05em;
font-size: 85%;
font-weight: bold;
}
table.table tr:last-child {
border-bottom: 1px solid #e9ecef;
}
</style>
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
'use strict';
window.addEventListener('load',function () {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function (form) {
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
@append

View File

@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<!DOCTYPE html>
<html>
@section('htmlheader')
@include('architect::layouts.partials.htmlheader')
@show
@@ -8,16 +8,17 @@
<div class="app-container app-theme-white body-tabs-shadow fixed-sidebar">
@include('architect::layouts.partials.topmenu')
{{--
@include('architect::layouts.partials.controlsidebar')
--}}
@includeIf('architect::layouts.partials.controlsidebar')
<div class="app-main">
@include('architect::layouts.partials.sidebarmenu')
<div class="app-main__outer">
<div class="app-main__inner">
<div class="main-content">
@if (trim($__env->yieldContent('page_title')))
@include('architect::layouts.partials.contentheader')
@endif
<!-- Main content -->
<div class="row">
@@ -27,6 +28,7 @@
</div>
</div>
</div>
</div>
@include('architect::layouts.partials.contentfooter')
</div>

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
@section('htmlheader')
@include('architect::layouts.partials.htmlheader')
@show
<body class="hold-transition login-page">
<div id="app">
@yield('content')
</div>
@section('scripts')
@include('architect::auth.partials.scripts')
{{-- Scripts --}}
{!! Asset::scripts() !!}
@yield('page-scripts')
@show
</body>
</html>

View File

@@ -5,7 +5,7 @@
<ul class="nav">
{{--
<li class="nav-item">
<a href="javascript:void(0);" class="nav-link">Footer Link 1</a>
<a href="javascript:void(0);" class="nav-link">Footer Link</a>
</li>
--}}
</ul>
@@ -18,7 +18,7 @@
<div class="badge badge-success mr-1 ml-0">
<small>NEW</small>
</div>
Footer Link 4
Footer Link
</a>
</li>
--}}

View File

@@ -1,26 +1,30 @@
<div class="app-page-title">
<div class="page-title-wrapper">
<div class="page-title-heading">
<div class="page-title-icon">
<i class="@yield('page_icon','pe-7s-car')"></i>
@if (trim($__env->yieldContent('page_icon')))
<div class="page-title-icon f32">
<i class="@yield('page_icon','')"></i>
</div>
@endif
<div>
@yield('page_title','Page Title')
<div class="page-title-subheading">
@yield('page_subtitle','Page Sub Title')
@yield('page_subtitle','')
</div>
</div>
</div>
@isset($page_actions)
<div class="page-title-actions">
{{--
<button type="button" data-toggle="tooltip" title="Example Tooltip" data-placement="bottom" class="btn-shadow mr-3 btn btn-dark">
<i class="fas fa-star"></i>
<i class="fa fa-star"></i>
</button>
--}}
<div class="d-inline-block dropdown">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn-shadow dropdown-toggle btn btn-info">
<span class="btn-icon-wrapper pr-2 opacity-7">
<i class="fas fa-business-time fa-w-20"></i>
<i class="fa fa-business-time fa-w-20"></i>
</span>
Item Menu
</button>
@@ -40,5 +44,6 @@
</div>
</div>
</div>
@endif
</div>
</div>

View File

@@ -43,7 +43,7 @@
{{--
<li class="nav-item">
<a href="javascript:void(0);" class="nav-link">
<i class="nav-link-icon fas fa-database"></i> Statistics
<i class="nav-link-icon fas fa-database"></i> Link
</a>
</li>
--}}

View File

@@ -14,10 +14,10 @@
--}}
<!-- Theme style -->
@css('css/components.css')
@css('css/style.css')
@css('css/style-responsive.css')
@css('css/themes/blue.css')
@themecss('/css/components.css','components-css')
@themecss('/css/style.css','style-css')
@themecss('/css/style-responsive.css','style-responsive-css')
@themecss('/css/themes/blue.css','theme-blue-css')
<!-- Google Font: Source Sans Pro -->
<link href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700|PT+Sans+Narrow|Source+Sans+Pro:200,300,400,600,700,900&amp;subset=all" rel="stylesheet" type="text/css">
@@ -32,7 +32,7 @@
<link rel="shortcut icon" href="{{ object_get($site,'favicon','favicon.ico') }}" />
<!-- Custom CSS -->
@css('css/custom.css')
@php(Asset::add('custom-css','/css/custom.css'))
<!-- STYLESHEETS -->
{!! Asset::styles() !!}

View File

@@ -1,54 +0,0 @@
<?php
namespace Leenooks\Controllers;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use Redirect;
use Session;
use App\Models\User;
class AdminController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function switch_authorised($id)
{
return (method_exists(Auth::user(),'isAdmin') && Auth::user()->isAdmin($id)) ? TRUE : FALSE;
}
public function switch_session()
{
return ! Session::get('orig_user');
}
public function user_switch_start($id)
{
if ($this->switch_session() AND $this->switch_authorised($id))
{
$uo = User::find($id);
if (! $uo)
abort(404,'User not found');
Session::put('orig_user',Auth::id());
Auth::login($uo);
}
return Redirect::to('/home');
}
public function user_switch_stop()
{
if ($id = Session::pull('orig_user')) {
$uo = User::find($id);
Auth::login($uo);
}
return Redirect::to('/home');
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Leenooks\Controllers;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Support\Facades\Auth;
use Redirect;
use Session;
use App\Models\User;
class SwitchUserController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Determine if the user is authorised to switch to another user
*
* @param User $user
* @return bool
*/
public function switch_authorised(User $user): bool
{
return (method_exists(Auth::user(),'isAdmin') && Auth::user()->isAdmin($user)) ? TRUE : FALSE;
}
/**
* Switch to a different user
*
* @param User $user
* @return mixed
*/
public function switch_start(User $user)
{
if ($user->switched)
abort(403,'User already switched');
if ($this->switch_authorised($user)) {
Session::put('orig_user',Auth::user());
Auth::login($user);
}
return Redirect::to('/home');
}
/**
* Return back from the switch users
*
* @return mixed
*/
public function switch_stop()
{
if ($user = Session::pull('orig_user'))
Auth::login($user);
return Redirect::to(RouteServiceProvider::HOME);
}
}

View File

@@ -0,0 +1,291 @@
<?php
namespace Leenooks\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Orchestra\Support\Facades\Asset;
class CustomBladeServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
Blade::directive('css',function(string $expression,array $args=[]) {
return $this->resolve('css',$expression);
});
Blade::directive('js',function($expression,string $options=NULL) {
return $this->resolve('js',$expression);
});
}
private function resolve(string $content,string $expression): string
{
if (str_contains($expression,',')) {
[$type,$arguments] = explode(',',$expression,2);
$arguments = explode('|',$arguments);
} else {
$type = $expression;
$arguments = [];
}
$return = collect();
$urls = collect();
switch ($type) {
case 'datatables':
switch ($content) {
case 'css':
// Base
$urls->put($type,'https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css');
foreach ($arguments as $option) {
$key = $type.':'.$option;
switch ($option) {
case 'bootstrap4':
$urls->put($key,'/plugin/dataTables/dataTables.bootstrap4.css');
break;
case 'buttons':
$urls->put($key,'https://cdn.datatables.net/buttons/1.6.5/css/buttons.dataTables.min.css');
break;
case 'fixedheader':
$urls->put($key,'https://cdn.datatables.net/fixedheader/3.1.7/css/fixedHeader.dataTables.min.css');
break;
case 'rowgroup':
$urls->put($key,'https://cdn.datatables.net/rowgroup/1.1.2/css/rowGroup.dataTables.min.css');
break;
case 'responsive':
$urls->put($key,'http://cdn.datatables.net/responsive/2.2.6/css/responsive.dataTables.min.css');
break;
case 'searchpanes':
$urls->put($key,'https://cdn.datatables.net/searchpanes/1.2.1/css/searchPanes.dataTables.min.css');
break;
case 'searchpanes-left':
$urls->put('searchpanes:searchpanes-left','/plugin/dataTables/leftSearchPanes.css');
break;
case 'select':
$urls->put($key,'https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
}
}
break;
case 'js':
// Base
$urls->put($type,'https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js');
foreach ($arguments as $option) {
$key = $type.':'.$option;
switch ($option) {
case 'bootstrap4':
$urls->put($key,'/plugin/dataTables/dataTables.bootstrap4.js');
break;
case 'buttons':
$urls->put($key,'https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js');
$urls->put($key.'html5','https://cdn.datatables.net/buttons/1.6.5/js/buttons.html5.min.js');
$urls->put($key.'jszip','https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.min.js');
break;
case 'fixedheader':
$urls->put($key,'https://cdn.datatables.net/fixedheader/3.1.7/js/dataTables.fixedHeader.min.js');
break;
case 'responsive':
$urls->put($key,'https://cdn.datatables.net/responsive/2.2.6/js/dataTables.responsive.min.js');
break;
case 'rowgroup':
$urls->put($key,'https://cdn.datatables.net/rowgroup/1.1.2/js/dataTables.rowGroup.min.js');
break;
case 'searchpanes':
$urls->put($key,'https://cdn.datatables.net/searchpanes/1.2.1/js/dataTables.searchPanes.min.js');
break;
case 'select':
$urls->put($key,'https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
}
}
}
break;
case 'datepick':
switch ($content) {
case 'css':
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css');
break;
case 'js':
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js');
}
break;
case 'highcharts':
switch ($content) {
case 'js':
// Base
$urls->put($type,'https://code.highcharts.com/highcharts.js');
foreach ($arguments as $option) {
$key = $type.':'.$option;
switch ($option) {
case '3d':
$urls->put($key,'https://code.highcharts.com/highcharts-3d.js');
$urls->put($key.'mouseover','/plugin/highcharts/3dmouseover.js');
break;
case 'data':
$urls->put($key,'https://code.highcharts.com/modules/data.js');
break;
case 'defaults':
$urls->put($key,'/plugin/highcharts/defaults.js');
break;
case 'drilldown':
$urls->put($key,'https://code.highcharts.com/modules/drilldown.js');
break;
case 'heatmap':
$urls->put($key,'https://code.highcharts.com/modules/heatmap.js');
break;
case 'export':
$urls->put($key,'https://code.highcharts.com/modules/exporting.js');
$urls->put($key.'data','https://code.highcharts.com/modules/export-data.js');
break;
case 'theme-dark':
$urls->put($key,'https://code.highcharts.com/themes/dark-unica.js');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
}
}
}
break;
case 'highcharts-stock':
switch ($content) {
case 'js':
// Base
$urls->put($type,'https://code.highcharts.com/stock/highstock.js');
foreach ($arguments as $option) {
$key = $type.':'.$option;
switch ($option) {
case 'data':
$urls->put($key,'https://code.highcharts.com/stock/modules/data.js');
break;
case 'export':
$urls->put($key,'https://code.highcharts.com/stock/modules/exporting.js');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
}
}
}
break;
case 'select2':
switch ($content) {
case 'css':
// Base
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css');
break;
case 'js':
// Base
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js');
foreach ($arguments as $option) {
$key = $type.':'.$option;
switch ($option) {
case 'autofocus':
$urls->put($key,'plugin/select2/fix-autofocus.js');
break;
default:
throw new \Exception(sprintf('Unknown [%s] option: [%s:%s]',$type,$content,$option));
}
}
}
break;
case 'simplemde':
switch ($content) {
case 'css':
// Base
$urls->put($type,'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css');
break;
case 'js':
// Base
$urls->put($type,'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js');
}
break;
case 'summernote':
switch ($content) {
case 'css':
// Base
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.css');
break;
case 'js':
// Base
$urls->put($type,'https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.js');
}
break;
default:
throw new \Exception(sprintf('Unknown Expression: [%s]',$expression));
}
if ($urls->count())
return $urls->map(function($item,$key) {
$dependancy='';
if (str_contains($key,':'))
[$dependancy,$key] = explode(':',$key);
return "<?php Asset::add('$key','$item','$dependancy'); ?>";
})->join('');
}
}

View File

@@ -32,8 +32,8 @@ trait SingleOrFail
return NULL;
});
// When a query should return 1 object, or NULL if it doesnt
Builder::macro('singleOrNew',function ($args) {
// When a query should return 1 object, or setup to create a new object
Builder::macro('singleOrNew',function (array $args=[]) {
$result = $this->where($args)->get();
if ($result->count() == 1)

View File

@@ -7,14 +7,27 @@ namespace Leenooks\Traits;
use Session;
use App\Models\User;
trait UserSwitch
{
/**
* Return if this is a switched user
*
* @return mixed
*/
public function getSwitchedAttribute()
{
return Session::get('orig_user');
}
public function isAdmin($id)
/**
* If the user record has an admin attribute, we'll return that
*
* @param User|null $user
* @return false|mixed
*/
public function isAdmin(User $user=NULL)
{
return isset($this->admin) ? $this->admin : FALSE;
}