Forums / All Other Contributions/Addons / Is a Permanent Login (Auto-Login) Possible?

Is a Permanent Login (Auto-Login) Possible?

Views: 54,687

Results 201 to 219 of 219
22 Oct 2023, 5:49 PM
#201
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Is a Permanent Login (Auto-Login) Possible?

Might I suggest "Keep Cart" (https://www.zen-cart.com/downloads.php?do=file&id=992) instead? That's a lot less cookie-weight and I've actually been keeping it updated!

22 Oct 2023, 5:54 PM
#202
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Well, I'm actually using both... keep cart to save un logged in carts, and remember me to automatically log back in if you have an account.

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

22 Oct 2023, 6:04 PM
#203
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Re: Is a Permanent Login (Auto-Login) Possible?

gothstone:

Well, I'm actually using both... keep cart to save un logged in carts, and remember me to automatically log back in if you have an account.
I'll take a look at the "Remember Me" implementation, but note that I'm not a big fan of its use with One-Page Checkout (if you're also using that).

22 Oct 2023, 6:08 PM
#204
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Lol, of corse I am. I use a LOT of your plugins.

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

7 Nov 2023, 3:52 PM
#205
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Please consider the following scenario for a customer who has activated auto-login. They go to the store and select a product and checkout, so the checkout_success page is displayed. They close the browser or move to another site. After the zc session expires, they come back to the checkout_success page through browser history or other means. They are auto-logged in and the checkout success page is displayed. Is auto-login configured to deal with this scenario correctly? What if the customer goes back to an earlier stage of checkout?

In my case, I have an observer triggered by NOTIFY_HEADER_END_CHECKOUT_SUCCESS that gets executed when the customer comes back and the page is displayed again. The observer fails because some data is missing. So I don't need or want the observer to execute when this scenario is encountered, since the observer did its thing when the customer first checked out successfully. Five different customers have triggered this error in the last two months so it's a problem I need to fix.

Unfortunately, I can't figure out a way to detect this scenario in the observer. Any ideas would be appreciated!

What worries me in addition, is what happens if the customer comes back to other pages in the store and whether the core and custom code will work.

If auto-login is not chosen by the customer, and the scenario is followed, the "Whoops, the session has expired" page is displayed, so I feel fairly certain nothing incorrect will occur for those customers.

Thank you for any advice/help you can provide.

Dave
zc157c, php 8

7 Nov 2023, 4:58 PM
#206
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,969
Plugin Contributions:
8

Re: Is a Permanent Login (Auto-Login) Possible?

Dave224:

....
In my case, I have an observer triggered by NOTIFY_HEADER_END_CHECKOUT_SUCCESS that gets executed when the customer comes back and the page is displayed again. The observer fails because some data is missing. So I don't need or want the observer to execute when this scenario is encountered, since the observer did its thing when the customer first checked out successfully. Five different customers have triggered this error in the last two months so it's a problem I need to fix.

Unfortunately, I can't figure out a way to detect this scenario in the observer. Any ideas would be appreciated!

...

Thank you for any advice/help you can provide.

i would suggest posting your error message as well as the code for your observer.

with that information, i would think someone can give better advice as to how to resolve the error condition.

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

7 Nov 2023, 5:46 PM
#207
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

carlwhat:

i would suggest posting your error message as well as the code for your observer.

with that information, i would think someone can give better advice as to how to resolve the error condition.

best.

I'm looking for a general solution that would detect the scenario regardless of the page returned to, and not re-execute any damaging code. I've already tested for the missing data (a custom session variable) in the observer and bypassed primary observer logic, so there are no myDEBUG messages. There is an email sent to me when the missing session data is detected with debug data. So I'm not sure what good the observer code will do.

What I was thinking of was a test on the "came from page", or a test on the current date-time relative to the order date_purchased date-time. In the case of returning to the checkout_success page, the "came from page" must be the order_confirmation page, otherwise the scenario was encountered. The time test would see if the time difference was less than say 20 minutes or else the scenario was encountered. But those are just preliminary thoughts, and I'm not sure how to get the "came from page" or even if it's possible.

Info on the observer...the observer automatically sets the order status and sends the order status update email for certain types of orders based on a custom session variable $_SESSION['order_case'] that's set elsewhere. It also tailors some text in the order status update email based on what was ordered. The idea was to relieve the admins from setting status and sending emails when they could be sent automatically at order time. The observer is too large to include as attachment to this site.

Dave

7 Nov 2023, 5:59 PM
#208
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Another possible idea would be to redirect to the home page or login page on auto-login, regardless of what page was requested by the browser. This could potentially avoid all negative impacts of coming back to the site on a "bad" page. This would need to be a change (I believe) to the auto-login add-on.
Dave

8 Nov 2023, 12:52 PM
#209
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Since manual login success loads the home page, I've decided to load the home page on auto-login too, even if the customer entered the store with a bookmark, browser history item, or restored a previous (browser) session. I inserted the following line after the update to the customers_info table in function checkRememberCustomer in file includes/classes/observers/class.remember_me_observer.php.

if (isset($_GET['main_page']) && $_GET['main_page'] !== 'index') $_GET['main_page'] = 'index'; // edit to force home page to load on auto-login

I have tested the code with and without products in the cart and all appears to work properly.
Dave

29 Jul 2024, 6:05 PM
#210
gothstone avatar

gothstone

Zen Follower

Join Date:
Jun 2005
Posts:
330
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

note for php 8.3:
to fix a ton of "--> PHP Deprecated: Creation of dynamic property remember_me_observer::$XXXXXX"
errors I added the following to /includes/classes/observers/class.remember_me_observer.php at about line 23:

	public $enabled,
	$checkbox_default,
	$debug,
	$logfilename,
	$customer_remembered,
	$customerIsLoggedIn,
	$path,
	$domain;

I won't swear it's right, but it does seem to work (in zen 2.0.1 even) and made the errors stop.

2 + 2 = 5 for extremely large values of 2

Pez Collectors Store •••••••• My Plugins List

4 Nov 2024, 5:35 PM
#211
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Re: Is a Permanent Login (Auto-Login) Possible?

v2.1.0 of "Remember Me" is now available for download: https://www.zen-cart.com/downloads.php?do=file&id=332

This release contains changes associated with these GitHub issues:

#20: Offer "Remember Me" on OPC's guest-to-account conversion.
#23: Redirect to home-page after customer's remembered.
#24: Correct PHP deprecations.
#25: Add $_SESSION['customer_email_address'] when a customer's remembered.
#26: Drop support for Zen Cart versions prior to 1.5.8 and PHP versions prior to 7.4.
#27: Don't remember admin 'Place Order' logins.

29 Jan 2025, 4:25 PM
#212
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

The checkbox is not displayed (or not visible) with version 2.1.0 Remember Me, zen cart v1.5.8a, ZCA_bootstrap_template v3.7.5, and OPC v2.5.4 in every expected location. The Remember Me? label is displayed as expected. There are no error logs. I can not find any CSS that would hide the checkbox. An image from returning customer login is attached, as well as the page source html for the form (edited to remove domain and security token, and formatted (indented) for ease in understanding. Any suggestions would be appreciated.
Thank you!
Dave

29 Jan 2025, 4:32 PM
#213
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

The html file in the previous post is not readable for some reason. The file is reproduced below:

<form name="loginForm" action="https://my_domain/index.php?main_page=login&action=process" method="post" id="loginForm">
	<input type="hidden" name="securityToken" value="blah-blah">                    
	<div class="opc-label">
		<label for="login-email-address">Email Address:</label>
	</div>
	<input class="form-control" type="email" name="email_address" value="" size="18" id="login-email-address" autofocus placeholder="*" required>
	<div class="opc-label">
		<label for="login-password">Password:</label>
	</div>
	<input class="form-control" type="password" name="password" size="18" id="login-password" autocomplete="off" placeholder="*" required>
	<br>
	<input class="custom-control-input" type="checkbox" name="permLogin" value="1" checked="checked" id="permLogin">
		<label class="checkboxLabel" for="permLogin" title="Tick this box to be automatically logged in on your next visit. Note: This will place create a cookie in your current browser that can only be read by this website.">Remember me?</label>
	<div id="opc-pwf">
		<a href="https://costore-158a.local/index.php?main_page=password_forgotten">Forgot your password?</a>
	</div>
	<div class="text-right">
		<button type="submit" class="btn button_login">Sign In</button>
	</div>
</form>

Dave

29 Jan 2025, 5:59 PM
#215
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

lat9:

Yep, checkbox type inputs require some special HTML; see this W3Schools link for additional information: https://www.w3schools.com/bootstrap4/bootstrap_forms_inputs.asp

Got it! I changed function create_checkbox starting on line 210 in class.remember_me_observer.php from:

    public function create_checkbox()
    {
        if (!$this->enabled) {
            return '';
        }
        $return_value =
            '<br>' .
            zen_draw_checkbox_field ('permLogin', '1', $this->checkbox_default, 'id="permLogin"') .
            '<label class="checkboxLabel" for="permLogin" title="' . TEXT_REMEMBER_ME_ALT . '">' . TEXT_REMEMBER_ME . '</label>';

        return $return_value;
    }

to:

    public function create_checkbox()
    {
        if (!$this->enabled) {
            return '';
        }
        $return_value =
            '<div class ="custom-control custom-checkbox pt-2 pb-2">' .
            zen_draw_checkbox_field ('permLogin', '1', $this->checkbox_default, 'id="permLogin"') .
            '<label class="custom-control-label" for="permLogin" title="' . TEXT_REMEMBER_ME_ALT . '">' . TEXT_REMEMBER_ME . '</label>' .
            '</div>';

        return $return_value;
    }

The pt-2 and pb-2 are for spacing.

Dave

29 Jan 2025, 7:25 PM
#216
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Re: Is a Permanent Login (Auto-Login) Possible?

Dave224:

Got it! I changed function create_checkbox starting on line 210 in class.remember_me_observer.php from:

public function create_checkbox()
{
    if (!$this->enabled) {
        return '';
    }
    $return_value =
        '<br>' .
        zen_draw_checkbox_field ('permLogin', '1', $this->checkbox_default, 'id="permLogin"') .
        '<label class="checkboxLabel" for="permLogin" title="' . TEXT_REMEMBER_ME_ALT . '">' . TEXT_REMEMBER_ME . '</label>';

    return $return_value;
}
> to:
> ```php
    public function create_checkbox()
    {
        if (!$this->enabled) {
            return '';
        }
        $return_value =
            '<div class ="custom-control custom-checkbox pt-2 pb-2">' .
            zen_draw_checkbox_field ('permLogin', '1', $this->checkbox_default, 'id="permLogin"') .
            '<label class="custom-control-label" for="permLogin" title="' . TEXT_REMEMBER_ME_ALT . '">' . TEXT_REMEMBER_ME . '</label>' .
            '</div>';

        return $return_value;
    }

The pt-2 and pb-2 are for spacing.

Dave
Sweet! I'll steal that for the next release, using the current return-value unless a bootstrap template is active in which case I'll use yours.

Thanks for the update.

30 Jan 2025, 5:33 PM
#217
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

I'm having trouble with Remember Me restoring products in the cart when the customer comes back to the site. I'm not sure what the customer should see. For example, a customer enters their email address, password and clicks Remember Me to log in. Then a product gets added to the cart. For whatever reason, the site is left (without logging out). After the session has expired, the customer comes back to the site. The home page is displayed and the customer is logged in. I would expect the shopping cart link to be displayed in the header, and on clicking it, the product previously left in the cart would appear. But there is no way to get to the shopping cart page except by adding another product. But when doing so, only the just added product is present.

After leaving the site again, I checked the customer's basket in the database, and both products are present. The cookie expiration time is set for 400 days.

What am I missing or forgetting?

Thank you.

Dave

zc 1.5.8a, latest versions of Remember Me, Bootstrap template, and OPC.

31 Jan 2025, 5:36 PM
#218
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

In trying to debug restoration of cart contents, I set PERMANENT_LOGIN_DEBUG to true in class.remember_me_observer.php and added a trigger_error statement to log $this->customer_remembered in function __construct() after $this->customer_remembered is initialized to false. I also added trigger_error statements to log the same variable in function checkRememberCustomer just after $this->customer_remembered is set to true, and also at the start of function restoreRememberedCart() before any tests. I suspected a potential timing issue.

The remember me debug log showed that cartIdSet was true in the cookie when returning to the site with a product placed in the cart previously before leaving the site. It was recorded first. Next, an error log showed that $this->customer_remembered was false in function __construct(), and true in function checkRememberCustomer. Finally, a third error log was recorded about 0.3 seconds later showing that $this->customer_remembered was set back to false in function __construct(), and false in function restoreRememberedCart.

So although the processing in function checkRememberCustomer correctly set $this->customer_remembered to true, subsequent processing reinitialized it to false, preventing function restoreRememberCart from restoring the cart.

I hope this helps figuring out what needs to be fixed.

Dave

12 Feb 2025, 8:32 PM
#219
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,110
Plugin Contributions:
56

Re: Is a Permanent Login (Auto-Login) Possible?

v2.1.1 of "Remember Me" is now available for download: https://www.zen-cart.com/downloads.php?do=file&id=332

This release contains changes associated with these GitHub issues:

#31: Use now-current PHP hash instead of md5 for various string hashes.
#28: Remember me? checkbox not visible when using Bootstrap template.
#32: A remembered customer's cart isn't also remembered.
#33: Correct interoperation with square_webPay (and other) payment modules when a customer is 'remembered'.
#34: Use zc158+ language-file array-format.