Forum

Thread tagged as: Question, Forum

Members Login Error Messages

Hi,

I have a login form that redirects to my staff portal on successful submission of credentials. However, if the logged in user does not have the correct tag to access that page it still takes them there but does not actually display the page - it looks as though the page does not exist.

Is there any way to redirect the user to another page saying they do not have the correct privileges to access that section? Or display a message saying so?

Conor Harkins

Conor Harkins 0 points

  • 4 years ago

Yes. You could test for logged in and tag. If no tag then

PerchUtil::redirect('https://www.myFancyWebpage.com')

Thanks for that.

I have included this in my staff portal page although I still have the problem of my login page not showing now.

The login page automatically redirects users to staff portal on successful login. If the member does not have the correct tag it breaks both pages - the portal and the login page. It looks as if they do not exist.

Ok... so I've managed to get the page to work and it now displays the login page.

My next question is... can I at this point display an error message to say the current logged in user does not have the correct rights to access the requested page?

I have an error on the form for incorrect login information already but not this.

Thank you.

You would check if the user has the proper tag, and if not then display the error. Because I'm out on the road I'm not able to give you any code samples but basically you're going to do a PHP if statement based on whether or not the user has the tag

So would I have a hidden error message somewhere on the login page and link back to the login page/show the message if the user does not have the correct tag?

Yes. In your code you will use an if/else statement. Put the success code in the if, and your form or redirect in the else statement.

Ok. Sorted it.

For anyone else wondering about a similar problem this is what I did...

On the login page I have an if statement for members who are logged in. Within this if statement I test for the correct tag - staff. If this tag is found it will redirect to the staff portal. If the tag is not found it will kick you off the login page onto an login_error page. If you click on the portal or login page it will continue to kick you out until you logout and then back in with correct credentials. This prevents the user from accessing the login page even after being logged in.

I'm slowly getting to grips with Perch...

if (perch_member_logged_in()) {
    if ( perch_member_has_tag('staff')) {
        PerchSystem::redirect('staff_portal');
    } else {
        PerchSystem::redirect('login_error');
    }
}
?>