Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ac867a2526 | ||
|
b0fcdaa375 | ||
|
55d369df47 | ||
|
c5413d5b50 | ||
|
8bafc735c4 | ||
|
1bfd5609a5 | ||
|
602fc14760 | ||
|
eb6ebd635e |
@@ -10,13 +10,18 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
|
"igaster/laravel-theme": "2.0.6",
|
||||||
|
"orchestra/asset": "^3.6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Leenooks\\": "src"
|
"Leenooks\\": "src"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"src/helpers.php"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"laravel": {
|
"laravel": {
|
||||||
|
6
readme.md
Normal file
6
readme.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
* User Switch
|
||||||
|
Add the following routes
|
||||||
|
```
|
||||||
|
Route::get( 'admin/switch/start/{id}', 'UserController@user_switch_start' );
|
||||||
|
Route::get( 'admin/switch/stop', 'UserController@user_switch_stop' );
|
||||||
|
```
|
@@ -136,4 +136,5 @@ return [
|
|||||||
'loggedin' => 'Logged in!',
|
'loggedin' => 'Logged in!',
|
||||||
'entering' => 'Entering...',
|
'entering' => 'Entering...',
|
||||||
'registered' => 'User Registered!',
|
'registered' => 'User Registered!',
|
||||||
|
'switchoff' => 'Switch Back',
|
||||||
];
|
];
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
<div id="app" v-cloak>
|
<div id="app" v-cloak>
|
||||||
<div class="register-box">
|
<div class="register-box">
|
||||||
<div class="register-logo">
|
<div class="register-logo">
|
||||||
<a href="{{ url('/home') }}"><b>Pipeline</b>Management</a>
|
<a href="{{ url('/home') }}">{!! config('app.name_html_long') !!}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (count($errors) > 0)
|
@if (count($errors) > 0)
|
||||||
|
@@ -36,6 +36,9 @@
|
|||||||
@include('adminlte::layouts.partials.scripts')
|
@include('adminlte::layouts.partials.scripts')
|
||||||
{{-- Scripts --}}
|
{{-- Scripts --}}
|
||||||
{!! Asset::scripts() !!}
|
{!! Asset::scripts() !!}
|
||||||
|
|
||||||
|
@yield('page-scripts')
|
||||||
@show
|
@show
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@@ -1,6 +1,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{{ config('app.name') }} - @yield('htmlheader_title', 'Your title here') </title>
|
<title>{{ config('app.name') }} - @yield('htmlheader_title', 'Your title here')</title>
|
||||||
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
|
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
|
||||||
<!-- CSRF Token -->
|
<!-- CSRF Token -->
|
||||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
@@ -29,13 +29,7 @@
|
|||||||
echo json_encode($trans);
|
echo json_encode($trans);
|
||||||
@endphp
|
@endphp
|
||||||
</script>
|
</script>
|
||||||
<script src="https://code.highcharts.com/highcharts.js"></script>
|
|
||||||
<style>
|
|
||||||
#favourite.selected {
|
|
||||||
color: orange;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<!-- STYLESHEETS -->
|
<!-- STYLESHEETS -->
|
||||||
{!! Asset::styles() !!}
|
{!! Asset::styles() !!}
|
||||||
</head>
|
</head>
|
||||||
|
@@ -42,7 +42,10 @@
|
|||||||
</li>
|
</li>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<li class="dropdown user user-menu" id="user_menu">
|
<!-- Top Menu Items -->
|
||||||
|
@include('adminlte::layouts.partials.topmenu')
|
||||||
|
|
||||||
|
<li class="dropdown user user-menu @if($user->switched()) bg-red @endif" id="user_menu">
|
||||||
<!-- Menu Toggle Button -->
|
<!-- Menu Toggle Button -->
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||||
<!-- The user image in the navbar-->
|
<!-- The user image in the navbar-->
|
||||||
@@ -66,16 +69,22 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<a href="{{ url('/logout') }}" class="btn btn-default btn-flat" id="logout"
|
@if ($user->switched())
|
||||||
onclick="event.preventDefault();
|
<a href="{{ url('/admin/switch/stop') }}" class="btn btn-default btn-flat" id="switch">
|
||||||
document.getElementById('logout-form').submit();">
|
{{ trans('adminlte_lang::message.switchoff') }}
|
||||||
{{ trans('adminlte_lang::message.signout') }}
|
</a>
|
||||||
</a>
|
@else
|
||||||
|
<a href="{{ url('/logout') }}" class="btn btn-default btn-flat" id="logout"
|
||||||
|
onclick="event.preventDefault();
|
||||||
|
document.getElementById('logout-form').submit();">
|
||||||
|
{{ trans('adminlte_lang::message.signout') }}
|
||||||
|
</a>
|
||||||
|
|
||||||
<form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
|
<form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
|
||||||
{{ csrf_field() }}
|
{{ csrf_field() }}
|
||||||
<input type="submit" value="logout" style="display: none;">
|
<input type="submit" value="logout" style="display: none;">
|
||||||
</form>
|
</form>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -2,12 +2,21 @@
|
|||||||
|
|
||||||
<!-- JQuery and bootstrap are required by Laravel 5.3 in resources/assets/js/bootstrap.js-->
|
<!-- JQuery and bootstrap are required by Laravel 5.3 in resources/assets/js/bootstrap.js-->
|
||||||
<!-- Laravel App -->
|
<!-- Laravel App -->
|
||||||
<script src="{{ url (mix('/js/app.js')) }}" type="text/javascript"></script>
|
<script src="{{ url(mix('/js/app.js')) }}" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<!-- Our our CSRF token to each interaction -->
|
||||||
|
{{-- @todo Test that we are validating this, also axios should be doing this for us? --}}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$.ajaxSetup({
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
@yield('page-scripts')
|
|
||||||
<!-- Optionally, you can add Slimscroll and FastClick plugins.
|
<!-- Optionally, you can add Slimscroll and FastClick plugins.
|
||||||
Both of these plugins are recommended to enhance the
|
Both of these plugins are recommended to enhance the
|
||||||
user experience. Slimscroll is required when using the
|
user experience. Slimscroll is required when using the
|
||||||
fixed layout. -->
|
fixed layout. -->
|
||||||
<script src="{{ url('/plugins/jquery.slimscroll.min.js') }}" type="text/javascript"></script>
|
@js('/site/js/jquery.slimscroll.min.js','jq.slimscroll');
|
||||||
<script src="{{ url('/plugins/fastclick/fastclick.min.js') }}" type="text/javascript"></script>
|
@js('/site/js/fastclick.min.js','jq.fastclick');
|
||||||
|
@@ -37,7 +37,7 @@
|
|||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
@section('page-scripts')
|
@section('page-scripts')
|
||||||
<script src="{{ url('/plugins/bootstrap3-typeahead.min.js') }}"></script>
|
@js('/site/js/bootstrap3-typeahead.min.js','bs-typeahead')
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
66
src/Commands/ScheduleList.php
Normal file
66
src/Commands/ScheduleList.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Leenooks\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
|
|
||||||
|
class ScheduleList extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'schedule:list';
|
||||||
|
|
||||||
|
protected $description = 'List when scheduled commands are executed.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Schedule
|
||||||
|
*/
|
||||||
|
protected $schedule;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ScheduleList constructor.
|
||||||
|
*
|
||||||
|
* @param Schedule $schedule
|
||||||
|
*/
|
||||||
|
public function __construct(Schedule $schedule)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->schedule = $schedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$events = array_map(function ($event) {
|
||||||
|
return [
|
||||||
|
'cron' => $event->expression,
|
||||||
|
'command' => static::fixupCommand($event->command),
|
||||||
|
];
|
||||||
|
}, $this->schedule->events());
|
||||||
|
|
||||||
|
$this->table(
|
||||||
|
['Cron', 'Command'],
|
||||||
|
$events
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If it's an artisan command, strip off the PHP
|
||||||
|
*
|
||||||
|
* @param $command
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function fixupCommand($command)
|
||||||
|
{
|
||||||
|
$parts = explode(' ', $command);
|
||||||
|
if (count($parts) > 2 && $parts[1] === "'artisan'") {
|
||||||
|
array_shift($parts);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(' ', $parts);
|
||||||
|
}
|
||||||
|
}
|
57
src/Controllers/AdminController.php
Normal file
57
src/Controllers/AdminController.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Leenooks\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Redirect;
|
||||||
|
use Session;
|
||||||
|
|
||||||
|
use App\User;
|
||||||
|
|
||||||
|
class AdminController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function switch_authorised()
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function switch_session()
|
||||||
|
{
|
||||||
|
return ! Session::get('orig_user');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Change the background color (or something) so we know we are switched
|
||||||
|
*/
|
||||||
|
public function user_switch_start($id)
|
||||||
|
{
|
||||||
|
if ($this->switch_session() AND $this->switch_authorised())
|
||||||
|
{
|
||||||
|
$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');
|
||||||
|
}
|
||||||
|
}
|
16
src/Traits/UserSwitch.php
Normal file
16
src/Traits/UserSwitch.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if users have been switched
|
||||||
|
*/
|
||||||
|
namespace Leenooks\Traits;
|
||||||
|
|
||||||
|
use Session;
|
||||||
|
|
||||||
|
trait UserSwitch
|
||||||
|
{
|
||||||
|
public function switched()
|
||||||
|
{
|
||||||
|
return Session::get('orig_user');
|
||||||
|
}
|
||||||
|
}
|
15
src/helpers.php
Normal file
15
src/helpers.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// is_json helper
|
||||||
|
if (! function_exists('is_json')) {
|
||||||
|
function is_json($string) {
|
||||||
|
try {
|
||||||
|
json_decode($string);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (json_last_error() == JSON_ERROR_NONE);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user