54 lines
954 B
PHP
54 lines
954 B
PHP
<?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');
|
|
}
|
|
} |