Page 1 of 1

Switching between users on the fly

Posted: Mon May 15, 2017 3:07 pm
by Adam

Our support staff needed a way to quickly and easily log in as clients without needing to:

1) log out themselves
2) use a secondbrowser
3) obtain the client's credentials

...so we added a snippet of jQuery to the footer of the project that presented a "Log in as..." or "Resume as..." button on particular pages (in each row of the users' List/Grid page, and on the View page).

We then added a snippet of PHP to the header:

// 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;
}


Re: Switching between users on the fly

Posted: Fri Sep 20, 2019 9:51 am
by jaypolmx

Can this be used on any PHPMaker version?


Re: Switching between users on the fly

Posted: Sat Sep 21, 2019 4:08 am
by Adam

The principle should hold up, but I doubt the code will. However, it shouldn't take much effort to get it going.

Unfortunately, I haven't got to that point in the v2020 upgrade yet, so I can't tell you what works and what doesn't.

I'll post any updates once I get to that code, but feel free to experiment and share your findings.


Re: Switching between users on the fly

Posted: Sun Sep 22, 2019 6:27 am
by saleh

hello

Where do I put the code?


Re: Switching between users on the fly

Posted: Sun Sep 22, 2019 4:07 pm
by Adam

As explained in the notes, that sample code goes in the page header, but you'll still need to write some JS/jQuery to place the activation button somewhere logical for your purposes.