This topic is locked
[SOLVED]

User-Selectable Landing Page

3/27/2024 5:04:32 PM
PHPRunner General questions
D
druck281 author

I have several different Dashboards built for different roles within the organization. I am working toward each user getting the appropriate dashboard as the landing page when they login. The URL is stored in the user table in a field called 'LandingPage'. I have the following in the AfterSuccessfulLogin event but I am still ending up on the Landing Page that is designated in the Misc Settings menu rather than being redirected to the correct page.

Assuming I can get this to work, I want to expand the idea even more and give the users a button in the Dropdown with the Username at the top that would allow them to designate their landing page by simply clicking the button that would capture the current URL and set it to the 'LandingPage' filed in the database. I am confident I can make that button work but I don't know how to place it with the Username dropdown on every page without manually entering it on every page.

Thanks!

//Set the Username in the top right of the menu
$str = "Welcome, ".$data["FirstName"];
Security::setDisplayName($str);

$un=Security::getUserName();
$sql = "SELECT idpsn_Person FROM Psn_Person WHERE Username = '".$un."'";
$_SESSION["UsID"] = DB::DBLookup("SELECT idpsn_Person FROM psn_Person WHERE Username = '".$un."'");

//Logging - Login
$auditData=array();
$auditData["amd_action"]="Login Success";
$auditData["amd_user"]=$username;
$auditData["amd_method"]=NULL;
audit_Authentication($auditData);

//Take user to their selected Landing page
$userData=Security::currentUserData();
$url=$userData["LandingPage"];

header("Location: ".$url);
admin 3/27/2024

To make sure that your redirect works you also need to issue the following command after header() call:
exit();

In regards to where to place a dropdown with a landing page selection - I believe that that best place for this is user profile page.

D
druck281 author 3/27/2024

Not sure if it was just the exit(); call but the code below works now. I cleaned up a couple other things so maybe it is a combination. I also found that sometimes testing on localhost does not give you good results. Maybe something is getting stuck in cache but once I cleaned up the code and uploaded to my sandbox account, it was working.

Anyway, here is the working code from my AfterSuccessfulLogin event. Thanks Sergy!

//Set the Username in the top right of the menu
$str = "Welcome, ".$data["FirstName"];
Security::setDisplayName($str);

//Logging - Login
$auditData=array();
$auditData["amd_action"]="Login Success";
$auditData["amd_user"]=$username;
$auditData["amd_method"]=NULL;
audit_Authentication($auditData);

//Take user to their selected Landing page
$userData=Security::currentUserData();
$url=$userData["LandingPage"];
header("Location: ".$url);
exit();
M
MikeT 3/28/2024

I recently did the same, but the redirect in AfterSuccessfulLogin didn't play well with the 2factor setup. i.e. when the user is shown the 2factor setup screen then the redirect like that doesn't work, at least in my experiments.

I then used the default menu page as the global landing page and redirected from an event there (having stored the user's landing page url in a session var after succesful login).

Do you use 2factor auth?

D
druck281 author 4/8/2024

@MikeT - I don't use 2FA but that is a good thought. Is that working for you? I am actually looking to rework this anyway since I found that my solution only works on login. Many of my users have gotten used to clicking the Project Logo to return to the landing page but my code does not change that so they still get the default application landing page rather than their custom dashboard.

D
druck281 author 4/8/2024