- Posts: 49
- Thank you received: 1
Force a logout out at end of a purchase?
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.4.34
I have a purchase process setup where the user is assigned to a group after the purchase. This group will give them access to multiple things on the site that others will not have.
The process works great, and they are added to that group at the end of the payment. However, the user had to register at the beginning of the process, and that "forces" them to be logged in. So, I believe we have a disconnect here, where they still only have the permissions from the original login applied to the current session. In order to gain access to what the new group provides, the user has to log out.
Can I force a logout at the end of the purchase or some kind of reload so they will then have their new permissions when the payment is complete?
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
You can display log out button on thank you page or even automatically submit it with javascript, but I think it will be not difficult to write a plugin to refresh user object when order is finished.
You can grab the code for log out button in modules\mod_login\tmpl\default_logout.php.
Please Log in or Create an account to join the conversation.
webcandy wrote: What I would do is edit the after_end checkout view. If you want to just display a link the user can click, that's easy...just put a link to the logout page in your code. For me I have a quick logout plug in and use that link. And say click here to compete purchase or something. But if you need to force them to logout you might need the page to redirect to your logout page. There is code out there to do this. There may be an easier way but that's how I'd do it.
This is a good idea, I was hoping that hikashop might have a solution, but this might be my only option with the time the client has made available to me.
korzo wrote: I hadn't time to test it, but I think your assumption is right. If Hikashop doesn't handle user group change, user have to log out/log in to have new user group applied.
You can display log out button on thank you page or even automatically submit it with javascript, but I think it will be not difficult to write a plugin to refresh user object when order is finished.
You can grab the code for log out button in modules\mod_login\tmpl\default_logout.php.
This plugin sounds like what I would love to try and write, but I have less that a week to go live. I need to learn the commands for refreshing a user object to see if I can add it.
The logout might be the only workable option I have right now...... Hikashop- can you weigh in on this? I can provide screen shots of all steps to show everything if needed.
Please Log in or Create an account to join the conversation.
The issue is that the user session confirming the order is another one than the one placing the order.
The order is placed by the user purchasing, but the order is confirmed by the payment gateway server.
So when HikaShop is sure that the payment has been paid, it cannot just call the logout function of the Joomla library as the current user is not the one that needs to be logged out.
What you can do is to configure the "session handler" of the joomla configuration to "database". That way, the users session will be handled by a table of the database and the user group after purchase plugin will be able to delete the user session of the user of the order when the order is confirmed by the payment plugin receiving the payment notification from the payment gateway.
Note that this also requires that you turn on the "force logout" option of the user group after purchase plugin via the Joomla plugins manager.
Please Log in or Create an account to join the conversation.
Plugin settings:
Registration of new user to complete purchase, email has been sent to new uer:
Email received, and followed link back to site to complete process:
Arrived at payment step, not complete yet:
Payment not complete, checking new user group level (expect to only see "registered")
Confirmed.
Credit card entered and payment process complete:
User group has been updated:
.......continued on next post......
Please Log in or Create an account to join the conversation.
not there....
At this point I can move through the website without a forced logout, and I still do not have any additional permissions.
Check user to see if there is a confirmed login:
No...
Log out and log back in to see if the menu entry exists then:
Yes (I know it went to two rows, will not stay like that live...)
Check to make sure menu is setup right:
We already knew that user could see the menu after a re-login, just wanted you to be able to compare that stuff side by side.
Any ideas?
Please Log in or Create an account to join the conversation.
I don't see why it doesn't work, but here are two alternative solutions you can try.
In both, you'll have to edit the file "after_end" of the view "checkout" via the menu Display>Views of HikaShop and add custom code at the end of it.
1. You can try to add that code:
2. You can try to add that code:
Please Log in or Create an account to join the conversation.
The second suggestion does work, but I end up with something showing that is shown to be in the shopping cart, but after a click on any link on the site, it disappears. Do you have any suggestions on how to get this to stop happening?
This is the screen I see after the purchase is complete:
That is not the purchase I made. It is the first item listed in the store though.
Like one of the previous users mentioned, can I modify this screen to show a message as to why they are being logged out? I might as well just tell them that this is being done on purpose so they do not immediately think something is wrong.
If there is any way I could get some help making the software work the way that you expected it to, I would really appreciate it. I have to have this process running by Dec. 1st, and will choose the force logout option if I have to. That is not my client's first choice...
Please Log in or Create an account to join the conversation.
If you want to do more you have to edit the after_end view...but that language code is already in the after_end view so doing a language override should get you what you need.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
is it feasible to clear the cart on your creation status? There may be a better way to do this and I'm sure nicolas who is infinitely more competent will weigh in. But I'm thinking it's the delay between whatever payment system you're using sending the "payment confirmed" update.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
1. Does the page redirect anywhere when the user is auto logged out?
2. Does manually refreshing the page work to get rid of the phantom item in the cart?
Please Log in or Create an account to join the conversation.
I will test it now.
Please Log in or Create an account to join the conversation.
<? php
header( "Location: www.domain.com/redirectpage.php " );
exit;
?>
in your after_end view. After you call the logout command nicolas gave. Let me know if that works...the code may have to be tweaked slightly.
Please Log in or Create an account to join the conversation.
EDIT: I never answered your question about the refresh. YES it does get rid of the phantom cart.
Sorry about that.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
www.domain.com/www.domain.com
Anyway, I removed that and ran it again. I am hoping that nicolas is in there, because I was not required to reply to an email sent to me, and I never changed that.
I did go an change the cat configuration for the redirect. previously I had it at(no quotes)
Couple of interesting things though:
1) Refresh drops the phantom cart from the header, but I stay on the order complete site that has the new thank you message. Here is a pic to see it with the phantom cart. Check out the value in it. I just made a purchase for $297. Before it told me I had $20 in the phantom cart. I think I will go drop the site cache just in case.
Here is the code that is in the checkout>after_end file
Check out how the php is still initialized, if you plan on adding something at the end.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.