Programmatically log in a user
Permalink
How can I programmatically log in a user - using code. I have their User and UserInfo object, their groups are set up I now just need to log them in.
I have tried using User::loginByUserID($userID) documented here,http://www.concrete5.org/documentation/developers/permissions/users... it does not work with or without a redirect after it.
How can this be done?
I have tried using User::loginByUserID($userID) documented here,http://www.concrete5.org/documentation/developers/permissions/users... it does not work with or without a redirect after it.
How can this be done?
In the register controller it turns out you need to call $u->logout() before I did that log in code.
With the call to logout it worked!
With the call to logout it worked!
Hmm, doesn't seem to be working for me. What exactly did you do?
Thanks!
Thanks!
If you pass the second param to getByID() as true, that will log in the user.
User::getByUserID($uID, true);
Very good. Thanks!
Where would I need to add this to make this work?
Thank you :)
Thank you :)
Erm, I am not sure. That entirely depends upon the context of your web site.
But technically, it could go anywhere.
But technically, it could go anywhere.
Sorry, I am a code n00b :)
So, I have set up custom registration pages (multilingual site), using jbs "register pro" add-on, which is just overriding the core registration function/controller etc.
So within the package files, the code is very similar to the core registration controller.
What I want to achieve is:
User registers to site -> User is added to group. Now the user shall be redirected to another page where he can choose some other options (purchase products etc.)..
All the steps are set up, but the user needs to log in to arrive at the last step, so that the purchase can be connected to the user data. I would like to jump over that and just have it as a flowing process.
From this thread, it seems like I just need to put some lines of code into two places... well :-)
Thanks for the reply!
So, I have set up custom registration pages (multilingual site), using jbs "register pro" add-on, which is just overriding the core registration function/controller etc.
So within the package files, the code is very similar to the core registration controller.
What I want to achieve is:
User registers to site -> User is added to group. Now the user shall be redirected to another page where he can choose some other options (purchase products etc.)..
All the steps are set up, but the user needs to log in to arrive at the last step, so that the purchase can be connected to the user data. I would like to jump over that and just have it as a flowing process.
From this thread, it seems like I just need to put some lines of code into two places... well :-)
Thanks for the reply!
It sounds like you're most of the way there to be honest!
Yes you just need to take the code from above and insert it into the register controller, once the user has been created.
Yes you just need to take the code from above and insert it into the register controller, once the user has been created.
Make sure you aren't doing
As this is going to log in the current user not the other user.
Best Wishes,
Mike
http://mkly.io