Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect url feature #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Controllers/ImpersonateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Session;
use Lab404\Impersonate\Services\ImpersonateManager;

class ImpersonateController extends Controller
Expand Down Expand Up @@ -51,7 +52,8 @@ public function take(Request $request, $id, $guardName = null)

if ($userToImpersonate->canBeImpersonated()) {
if ($this->manager->take($request->user(), $userToImpersonate, $guardName)) {
$takeRedirect = $this->manager->getTakeRedirectTo();
// Check if Session imp_back_url exist and redirect to that url or use the url from config file
$takeRedirect = (Session::get('imp_back_url')) ? Session::get('imp_back_url') : $this->manager->getTakeRedirectTo();
if ($takeRedirect !== 'back') {
return redirect()->to($takeRedirect);
}
Expand All @@ -72,7 +74,10 @@ public function leave()

$this->manager->leave();

$leaveRedirect = $this->manager->getLeaveRedirectTo();
$leaveRedirect = (Session::get('imp_back_url')) ? Session::get('imp_back_url') : $this->manager->getLeaveRedirectTo();

Session::forget('imp_back_url'); // Will clean session for next use

if ($leaveRedirect !== 'back') {
return redirect()->to($leaveRedirect);
}
Expand Down