Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
9ef7e8e626 | ||
|
c9cd560b36 |
@@ -6,16 +6,19 @@
|
||||
<!-- CSRF Token -->
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
|
||||
{{--
|
||||
<!-- Included in adminlte -->
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
|
||||
--}}
|
||||
|
||||
<!-- Font Awesome Icons -->
|
||||
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.15.3/css/all.css">
|
||||
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.15.4/css/all.css">
|
||||
{{--
|
||||
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.15.3/css/v4-shims.css">
|
||||
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.15.4/css/v4-shims.css">
|
||||
--}}
|
||||
|
||||
<!-- Theme style -->
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/admin-lte@3.1.0/dist/css/adminlte.min.css">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/admin-lte@3.2.0/dist/css/adminlte.min.css">
|
||||
|
||||
<!-- Google Font: Source Sans Pro -->
|
||||
<link href="https://fonts.googleapis.com/css2?family={{ str_replace(' ','+',config('app.font') ?: 'IBM Plex Sans') }}:wght@300&display=swap" rel="stylesheet">
|
||||
|
@@ -2,9 +2,9 @@
|
||||
<!-- Bootstrap & Jquery App -->
|
||||
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
|
||||
<!-- AdminLTE -->
|
||||
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/admin-lte@3.1.0/dist/js/adminlte.min.js"></script>
|
||||
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/admin-lte@3.2.0/dist/js/adminlte.min.js"></script>
|
||||
|
||||
<!-- Additional Utilities -->
|
||||
<script src="{{ asset('plugin/bootstrap3-typeahead/js/bootstrap3-typeahead.min.js') }}"></script>
|
||||
|
@@ -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');
|
||||
}
|
||||
}
|
62
src/Controllers/SwitchUserController.php
Normal file
62
src/Controllers/SwitchUserController.php
Normal 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);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user