Forum

Thread tagged as: Question, Forum

Perch Members Add-On Help

Hi guys,

So I've finally figured out how to install the perch_members add-on but now when I visit the login page it says in the debug "User is logged in" even though I haven't entered any contact details.

When I start a browser in Private mode and login it works perfectly and allows me to access pages that it should but when not in Private mode does not allow me to access those pages even though it always says "User is logged in".

Any ideas?

I appreciate your help.

Conor

Conor Harkins

Conor Harkins 0 points

  • 4 years ago

Ok so...

For some reason my website was always logging me in - maybe this is a caching problem or similar.

I did however overcome this with the use of a logout button. This seemed to fix everything and I can now login and out with ease.

<?php 
include('../perch/runtime.php');
perch_member_log_out(); 
PerchUtil::redirect('index');
?>

I now have another question but since it still falls under the same title I hope it is ok to post here...

I have a Staff Portal section which, when logged out, redirects me to Login. Is there a way that I could remember which page a person was trying to get onto before being asked to login and then redirect them there when they successfully login?

Also, the login message at the top of my form will not go away... even when I am logged out.

<perch:member logged-in="true"> 

    <p>Hi <perch:member id="first_name" />, you are logged in</p>

<perch:else:member />

    <div class="form-contact">
        <perch:form id="login" method="post" app="perch_members">
            <fieldset>
                <legend>Log in</legend>

                <perch:error for="all" type="login">
                    <p class="error">Those details do not match our records.</p>
                </perch:error>
                <div class="row control-group">
                    <div class="form-group col-xs-12 controls">
                        <perch:label for="email">Email</perch:label>
                        <perch:input class="form-control"  type="email" id="email" required="true" label="Email" />
                        <perch:error for="email" type="required">Required</perch:error>
                        <perch:error for="email" type="format">Check format of address</perch:error>
                    </div>
                </div>
                <div class="row control-group">
                    <div class="form-group col-xs-12 controls">
                        <perch:label for="password">Password</perch:label>
                        <perch:input class="form-control"  type="password" id="password" required="true" label="Password" />
                        <perch:error for="password" type="required">Required</perch:error>
                    </div>
                </div>
            <div class="row">
                <div class="form-group col-xs-12">
                <perch:input class="button btn-lg" type="submit" id="submit" value="Log in" />
                <perch:input type="hidden" id="r" />
                <p>Forgotten your password? <a href="reset">Reset it now</a>.</p>
                </div>
            </div>

            </fieldset>

        </perch:form>

    </div>

</perch:member>

The answers in this thread could help you

https://stackoverflow.com/a/14523719

Hi,

Thanks for your reply. I tried this but it is way too advanced for me to figure out.

Thanks anyway.

Could someone help me redirect my users to a Staff Portal page on successful submission of the login form?

You could check if a member is logged in and redirect them accordingly. You need to put this before any other code on the page.

This will forward any logged in users to the staff portal page (you'll have to put in the real url) if they are logged in. Otherwise it will display the content on the page (e.g. the log in or register form).

<?php
    if (perch_member_logged_in()) {
        PerchSystem::redirect('/staff-portal-page-url/');
    }
?>

Or you can use the same Perch function to display one set of content or another depending on the member being logged in or not.

Awesome! It works! Thanks for your help. You wouldn't happen to know a simple way for me to solve my problem above? To redirect the user back to the page that sent them to the login form after submission?

I'm sure the method above works but is too complicated for me to follow.

You're welcome.

Wouldn't your users log in through a single log in page? So if they log in the page will refresh and then send them to the staff portal. If not they will be presented with the log in form. Then you don't need to worry about tracking where they are in the site. Nice and simple.

Otherwise, if you've got the log in in a global header for example, then I guess you could store the page url as a variable and then use that to redirect the user once they've logged in. But it's not something I've tried myself.

Yes, they do login through a simple form. I would, however, possibly end up with different areas of the website being restricted depending on the level of access.

For example a staff portal and a client portal would both redirect the user to the login page. However, on submission of the form it would then send them back to the page they came from. Staff will have access to the client area so may want to login to view that but this current method would then take them to the staff portal - if you know what I mean.

Sure. Just note that you're assuming that the user has come from a particular portal page which may be misleading – what if they came from an email or external link etc? You can never be too sure.

However, you could also use member tags to check against and then redirect them accordingly:

<?php if (perch_member_logged_in() && perch_member_has_tag('staff')) {
    PerchSystem::redirect('/staff-portal/');
} elseif (perch_member_logged_in() && perch_member_has_tag('client')) {
    PerchSystem::redirect('/client-portal/');
}
?>