Page 1 of 1

impersonate user

Posted: Mon May 08, 2017 2:18 am
by ghasembaghi

when an admin or parent user log in to his panel, in user list can see an option to impersonate child user.
when impersonate by a username, he can check privilege and user interface of child user, after impersonate, in header parent user can a message like this:
you loged in as 'David', to back to admin(parent) click here


Re: impersonate user

Posted: Mon May 08, 2017 2:06 pm
by andyrav

+1


Re: impersonate user

Posted: Thu May 11, 2017 8:52 pm
by wernerbooysen

Yes - please!


Re: impersonate user

Posted: Sun May 14, 2017 12:32 am
by Adam

This can be done quite easily already - we implemented it in some projects since v9.2

Just use jQuery to place a button somewhere sensible and reload the page with a 'switch' or 'switchback' query parameter.

In the page header, add a small section of code that copies and replaces / reverts the relevant $_SESSION[] values.

It works very well - doesn't even log out users, so it's a great for support / admin / management staff to quickly log in as a client user and see what they see :-)


Re: impersonate user

Posted: Sun May 14, 2017 3:46 pm
by andyrav

hi
could you post your code please?


Re: impersonate user

Posted: Mon May 15, 2017 2:52 pm
by Adam

Put something like this in the head:

// switch from admin/staff to a regular profile
if (CurrentUserLevel() != 1 && isset($_GET['SetProfile'])) {
	$_SESSION['_ROOT_PROFILE'] = array(
		'SysAdmin' => $_SESSION['YourProject_SysAdmin'],
		'Level' => $_SESSION['YourProject_status_UserLevel'],
		'ID' => $_SESSION['YourProject_status_UserName']
	);
	$_SESSION['YourProject_SysAdmin'] = 0;
	$_SESSION['YourProject_status_UserLevel'] = 0;
	unset($_SESSION['YourProject_status_UserLevelValue']);
	$_SESSION['YourProject_status_UserName'] = (int) $_GET['SetProfile'];
	$_SESSION['YourProject_status_UserProfile_UserName'] = (int) $_GET['SetProfile'];
	header("Location: your_default_page.php");
	exit;
}
// resume to admin/staff from a regular profile
else if (CurrentUserLevel() == 0 && isset($_GET['ResumeRootProfile']) && isset($_SESSION['_ROOT_PROFILE'])) {
	$_SESSION['YourProject_SysAdmin'] = $_SESSION['_ROOT_PROFILE']['SysAdmin'];	
	$_SESSION['YourProject_status_UserLevel'] = $_SESSION['_ROOT_PROFILE']['Level'];	
	$_SESSION['YourProject_status_UserName'] = $_SESSION['_ROOT_PROFILE']['ID'];
	$_SESSION['YourProject_status_UserProfile_UserName'] = $_SESSION['_ROOT_PROFILE']['ID'];
	unset($_SESSION['_ROOT_PROFILE']);
	header("Location: your_default_page.php");
	exit;
}

...and then put some jQuery in the footer to display a 'switch' / 'switch back' button.

The most sensible places for buttons would be in each row of the users List/Grid page and on the View page.

It's pretty simple to implement and really makes life easier for staff :)


Re: impersonate user

Posted: Tue Jun 27, 2017 8:55 pm
by horizon_iet

+1!


Re: impersonate user

Posted: Mon Jul 17, 2017 8:52 am
by keithh0427

+1