Hi,
I want to redirect each user (after successful login) based on his/her user level ID.
I added the follwing code to the “login page /Page_Redirecting” server event but it NOT works:
// دریافت سطح دسترسی کاربر
$userLevel = CurrentUserLevel();
$profile = Profile()->loadFromSession();
$SupportStaff = $profile ? $profile->get("SupportStaff") : null;
// تعیین مسیر هدایت
switch (true) {
case ($userLevel === -1):
$url = "/appointmentslist?cmd=resetall";
break;
case ($userLevel === 1):
$url = "/doctorpanel";
break;
case ($userLevel === 4):
$url = "/receptionpanel";
break;
case ($SupportStaff === 'Y'):
$url = "/clinicpanel"; // اصلاح نام مسیر (در صورت تایپی بودن)
break;
default:
$url = "/home";
break;
}
You load profile from session, but did you save to session before? If not, Profile() is fine.
You get “SupportStaff” from profile, but did you set it before? If not, you cannot. If “SupportStaff” is only a field from the users table, you may simply use CurrentUserInfo("SupportStaff").
You should check if the user is logged in first (e.g. by IsLoggedIn(), otherwise you code will always redirect to “/home” if the user is not logged in yet.