Elgg  Version master
logout_as.php
Go to the documentation of this file.
1 <?php
7 
9 
10 $user_guid = (int) $session->get('login_as_original_user_guid');
11 
13 if (!$user instanceof \ElggUser || !$user->isAdmin()) {
14  return elgg_error_response(elgg_echo('action:user:login_as:unknown'));
15 }
16 
17 $persistent = (bool) $session->get('login_as_original_persistent');
18 
19 try {
21 
22  $session->remove('login_as_original_user_guid');
23  $session->remove('login_as_original_persistent');
24 
25  return elgg_ok_response('', elgg_echo('action:user:login_as:success', [$user->getDisplayName()]));
26 } catch (LoginException $e) {
27  return elgg_error_response(elgg_echo('action:user:login_as:error', [$user->getDisplayName()]));
28 }
$user
Definition: logout_as.php:12
Generic parent class for login exceptions.
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
$session
Definition: logout_as.php:8
elgg_get_session()
Gets Elgg&#39;s session object.
Definition: sessions.php:15
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
$user_guid
Definition: logout_as.php:10
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
elgg_login(\ElggUser $user, bool $persistent=false)
Log in a user.
Definition: sessions.php:81
if(!$user instanceof\ElggUser||!$user->isAdmin()) $persistent
Definition: logout_as.php:17
Login as the specified user.