IsAdmin() with dynamic user levels

I’m trying to check if user is admin in the function User_LoggingIn($usr, &$pwd) event.
I’m using dynamic user levels.
If site is in maintenance mode, and user is not an admin he should be redirected.
Currently all users are redirected when in maintenace mode, so it seems like if (!IsAdmin()) doesn’t work.
I have tried writing this in the positive too, but still all users get redirected.
What’s the correct way to check if a user is an admin when using dynamic user levels?

here’s my code:

// User Logging In event
function User_LoggingIn($usr, &$pwd) {
// Enter your code here
// To cancel, set return value to FALSE
$MaintStatus = ExecuteScalar(“SELECT Settings.Value FROM Settings WHERE Settings.Setting=‘Maintenance’”);

if($MaintStatus=‘1’){
if (!IsAdmin()){
$this->terminate(‘Pages/Maintenance.php’);
return FALSE;
}
return TRUE;
}
return TRUE;
}

global $Security

If($Security->IsAdmin()) {}

Looks like this does nothing.
I removed redirects and everythng, and just have the login page echoing all the vars.
IsAdmin() returns no value. Other vars are ok.

Just to confirm, I’m using dynamic user levels.

Can I query instead admin user level of -1? If so how?

User_LoggingIn is fired before validating the user, you should use User_LoggedIn (after login).

But if they’re logged in, they have access to the menus.
I guess its possible to create a redirect to logout.php if the user is not an admin?

You can, or an error page, it depends on your own design of your site.

philmills wrote:

I guess its possible to create a redirect to logout.php if the user is not an admin?

Try to put this code in “User_LoggedIn” server event:

If (!IsAdmin()) {
$this->terminate(“logout.php”);
}

Sorry to intrude, just wanted to tell that I also have the same problem.
I’ve also tested it with — if (CurrentUserLevel() == “1”) ---- and the problem is the same. It’s like it ignores the userlevel, redirecting every user.
Also using dynamic user levels.

I’m getting the same issue

csmgomes wrote:

I’ve also tested it with — if (CurrentUserLevel() == “1”) ---- and the problem is the same. It’s like it ignores the userlevel, redirecting every user. Also using dynamic user levels.

Are you sure you put in User_LoggedIn (not User_LoggingIn)? You may post your complete code for discussion.

This is my code (as the one posted by the post owner), except I’ve changed to logged in instead of loggin in, as suggested, and tried with the current user level to see if it would work:

// User Logged In event
function User_LoggedIn($usr) {
//echo “User Logged In”;
$MaintStatus = ExecuteScalar(“SELECT Settings.Value FROM Settings WHERE Settings.Setting=‘Maintenance’”);

if($MaintStatus=‘1’){
If (!IsAdmin()) {
$this->terminate(‘Maintenance.php’);
return FALSE;
}
return TRUE;
}
return TRUE;
}

if($MaintStatus==1){

This worked (without the ’ ’ and by adding the extra =). Thank you for your help!

worked for me too.
thanks!
Finally got my maintenance mode system working