Elgg  Version 4.3
logout_as.php
Go to the documentation of this file.
1 <?php
7 
9 
10 $user_guid = $session->get('login_as_original_user_guid');
12 
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:11
get_user($guid)
Get a user object from a GUID.
Definition: users.php:20
Generic parent class for login exceptions.
$session
Definition: logout_as.php:8
elgg_get_session()
Gets Elgg&#39;s session object.
Definition: sessions.php:15
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$user_guid
Definition: logout_as.php:10
elgg_login(\ElggUser $user, bool $persistent=false)
Log in a user.
Definition: sessions.php:81
elgg_error_response($message= '', $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
elgg_ok_response($content= '', $message= '', $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
if(!$user instanceof\ElggUser||!$user->isAdmin()) $persistent
Definition: logout_as.php:17
Login as the specified user.