public function EarlyIpLoginMiddleware::handle in IP Login 4.x
File
- src/StackMiddleware/EarlyIpLoginMiddleware.php, line 53
Class
- EarlyIpLoginMiddleware
- Provides a HTTP middleware to implement IP based login.
Namespace
Drupal\ip_login\StackMiddleware
Code
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
if ($request->cookies
->get('ipLoginAttempted', NULL)) {
return $this->httpKernel
->handle($request, $type, $catch);
}
$uid = NULL;
if ($type === self::MASTER_REQUEST && PHP_SAPI !== 'cli') {
$this->container
->get('request_stack')
->push($request);
$session = $this->container
->get($this->sessionServiceName);
$session
->start();
$uid = $session
->get('uid');
$this->container
->get('request_stack')
->pop();
}
if ($uid || PHP_SAPI === 'cli') {
return $this->httpKernel
->handle($request, $type, $catch);
}
if ($matched_uid = IpLoginController::checkIpLoginExists($request)) {
$can_login_as_another_user = $request->cookies
->get('ipLoginAsDifferentUser', NULL);
if ($can_login_as_another_user === NULL) {
$request->attributes
->set('ip_login_uid', $matched_uid);
}
elseif ($can_login_as_another_user == FALSE) {
$request->attributes
->set('ip_login_uid', $matched_uid);
}
elseif ($can_login_as_another_user == TRUE) {
}
else {
$request->attributes
->set('ip_login_uid', $matched_uid);
}
}
$response = $this->httpKernel
->handle($request, $type, $catch);
if (empty($matched_uid)) {
$response->headers
->setCookie(new Cookie('ipLoginAttempted', 1));
}
return $response;
}