Forum

Thread tagged as: Question, Configuration, Members

How to Define {returnURL} for Members Password Reset?

In Perch Settings/Members/Login page path, the value is something like > /members/login.php?r={returnURL}

How do I define > {returnURL}?

I'm looking at redirecting members to a specific page after login from the "login" link in password reset email. Reset can happen at different sections of the site, so will be good to define returnURL.

Tried setting $returnURL in reset.php that calls perch_member_form('reset_password.html') but it doesn't work. Tried specifying value of 'r' in login_form.html template and it doesn't work.

reset.php:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); 
perch_layout('sub.header');
perch_layout('global.nav');

if((perch_get('r'))) {
    $returnURL = perch_get('r');
    PerchSystem::set_var('returnURL', $returnURL);
}

    perch_member_form('reset_password.html');
?>
</div>
<?php
    PerchUtil::output_debug();
    perch_get_javascript();
    perch_layout('global.footer');
?>

Here's my login_form.html template:

<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>
                <perch:label for="email">Email</perch:label>
                <perch:input 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>
                <perch:label for="password">Password</perch:label>
                <perch:input type="password" id="password" required="true" label="Password" />
                <perch:error for="password" type="required">Required</perch:error>
            </div>
            <div>
                <perch:input type="submit" id="submit" value="Log in" />
                <perch:input type="hidden" id="r" value="<perch:members id="perch_page_path" />" />

                <p><a href="/members/reset?r=<perch:members id="perch_page_path" />">Forgot password</a></p>
            </div>

        </fieldset>

    </perch:form>
Yan Ping Tay

Yan Ping Tay 0 points

  • 3 years ago
Simon Clay

Simon Clay 127 points

Hi,

I'm not sure if I've understood the requirement correctly, but do you get the desired affect if you add and action with <perch:forms id="returnURL" /> to your opening form tag? eg.

<perch:form id="login" method="post" app="perch_members" action="<perch:forms id="returnURL" />">

Thanks for the response! Sorry let me explain better.

For members who requested for password reset, this is the intended outcome:

  1. On any page that displays more info specific to members, click on 'Forgot password' link

  2. Receive email with new password

  3. Click on 'log back in' link in email (which is currently /members/login/?r= )

  4. Login and get redirected to 'r' value

Problem is current 'r' value is blank. I presume it's taken from member settings page login path: /members/login.php?r={returnURL}

Snippet from email template emails/reset_password.html:

<p>You can <a href="https://<perch:email id="http_host" /><perch:email id="login_page" />">log back in</a> and try it out.</p>
Drew McLellan

Drew McLellan 2638 points
Perch Support

The {returnURL} gets automatically replaced with the path of the current page. The idea begin it can bounce you to the login page and then back to where you started.

Exactly what I need! Except that it's currently blank in the login URL /members/login.php?r=

Reset is currently called from reset.php. So it should at least carry value of reset.php, did I get it right?

How can I make it work?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It shouldn't be blank. Can you show us what you're doing?

Sure (Thanks for the response!). There are 2 sections for members to access - /clubttm and /merchandise (for checkout purposes). - At merchandise checkout, members not logged in should be prompted to login with option to reset password if they forgot login details. - After receiving email with new password, members can click on login link to do so, and be redirected to /merchandise/checkout to finish the checkout process. - The above step should apply to login tasks for accessing /clubttm area as well

Here's my /merchandise/checkout.php:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');

if(perch_member_logged_in()) {

    if(!perch_shop_addresses_set())
        PerchSystem::redirect('/merchandise/addresses');
}

perch_layout('sub.header');
perch_get_css();
perch_layout('global.nav');
if (perch_member_logged_in()) {
    perch_layout('clubttm.header');
}
?>

<div class="main-content-spacing">
    <h1>Checkout</h1>
<?php

if(perch_get('login')){
    perch_members_login_form();
}
else {

    if(perch_member_logged_in()) {
        if(perch_shop_addresses_set()) {
            if (!perch_shop_cart_has_property('confirmation') || perch_shop_get_cart_property('confirmation') == 'false') {

                // Show the cart with a non-interactive template
                perch_shop_cart([
                    'template'=>'cart/cart_static.html'
                ]);
                // Show the order addresses
                perch_shop_order_addresses();
                // Display confirmation page
                perch_shop_form('checkout/confirm.html');            
            }
            else {
                perch_shop_set_cart_property('confirmation', 'false');
                $return_url = 'https://ttmda-perch.macky/merchandise/success';
                $cancel_url = 'https://ttmda-perch.macky/merchandise/';

                perch_shop_checkout('paypal-express', [
                'return_url' => $return_url,
                'cancel_url' => $cancel_url,
                ]);

            }
        }
        else{
            echo 'address is not set';
        }
    }
    else {
        echo "<h3>Club TTM Members</h3>";
        perch_members_login_form();
        // New customer sign up form
        perch_shop_registration_form([
            'template' => 'checkout/customer_create_passwordless.html'
        ]);
    }
}
?>

</div>
<?php
PerchUtil::output_debug();
perch_get_javascript();
perch_layout('global.footer');

?>

Here's my template login_form.html:

<perch:member logged-in="true">
<div class="main-content-spacing main-top">
    Hi <perch:member id="first_name" />! <a href="/clubttm/profile">Profile</a> <a href="/clubttm/logout">Logout</a>
</div>
<perch:else:member />
<div class="main-content-spacing">
    <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>
                <perch:label for="email">Email</perch:label>
                <perch:input 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>
                <perch:label for="password">Password</perch:label>
                <perch:input type="password" id="password" required="true" label="Password" />
                <perch:error for="password" type="required">Required</perch:error>
            </div>
            <div>
                <perch:input type="submit" id="submit" value="Log in" />
                <perch:input type="hidden" id="r" />

                <p><a href="/clubttm/reset">Forgot password</a></p>
            </div>

        </fieldset>

    </perch:form>
</div>
</perch:member>
<perch:showall />

<perch:showall /> for the above template at /merchandise/checkout:

ID  Value
perch_page_path /merchandise/checkout.php
perch_namespace perch:members

Here's my /clubttm/reset.php:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); 
perch_layout('sub.header');
perch_layout('global.nav');

?>

<div class="main-content-spacing">
    <h1>Password Reset</h1>
<?php 
    perch_member_form('reset_password.html');
?>
</div>
<?php
    PerchUtil::output_debug();
    perch_get_javascript();
    perch_layout('global.footer');
?>

Here's my template reset_password.html:

<perch:form id="reset" method="post" app="perch_members">

    <p>Enter your email address and we'll send you a new password.</p>

    <div>
        <perch:label for="email">Email</perch:label>
        <perch:input type="email" id="email" required="true" label="Email" placeholder="you@company.com" helper="PerchMembers_Members::check_email_exists" />
        <perch:error for="email" type="required">Please add your email address</perch:error>
        <perch:error for="email" type="helper"><p>We don't have an account with that email address.</p></perch:error>
    </div>

    <div>
        <perch:input type="submit" value="Reset" />
    </div>

    <perch:success>
        <p>A new password has been emailed to you.</p>
        <p><a href="/clubttm/login">Login</a></p>
    </perch:success>
</perch:form>
<perch:showall />

<perch:showall /> for the above template at /clubttm/reset:

ID  Value
perch_page_path /clubttm/reset.php
email   
status  
expires 
auth_id 
id  
perch_namespace perch:forms

Debug after submit Reset:

Debug Message - Perch 3.0.13
[1] SELECT * FROM perch2_pages WHERE pagePath='/clubttm/reset.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=167
[1] SELECT * FROM perch2_shop_cart WHERE cartID=167
[37] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[11] SELECT COUNT(*) FROM perch2_members WHERE memberEmail='samsara.niyama@gmail.com'
[1] SELECT * FROM perch2_members WHERE memberEmail='samsara.niyama@gmail.com' LIMIT 1
UPDATE perch2_members SET memberPassword='$P$BN27yyfmheX60VQgduLtyDwm.LSE561' WHERE memberID='3'
No ids to log.
Using email template: /Applications/MAMP/htdocs/ttmda-perch/perch/templates/members/emails/reset_password.html (html)
Building message with Perch template
[1] Using template: /templates/members/emails/reset_password.html
Sent email: "Yan Ping, here's your new password" to samsara.niyama@gmail.com
------------------------------ here mem ------------------------------
[6] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
[0] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/clubttm/reset.php' LIMIT 1
[6] Using template: /templates/navigation/item.html
Using template: /templates/members/forms/reset_password.html

Login URL from reset password email: https://ttmda-perch.macky/clubttm/login?r=