Harmster Posted April 8, 2014 Posted April 8, 2014 Hey I'm trying to log a user in with a cookie. cookie stuff works fine as far as I can tell but logging the user in without a password gives me a bucket of problems. $u = $users->get($user_id); set_remember_me($u->name, $wire); echo "<br />Username retrieved from: ".$u->name; $users->setCurrentUser($u); $session->_user_id = $u->id; echo "<br />After setting current user: ".$user->name $remember->trash(); It echoes the following: Username retrieved from: HarmsterAfter setting current user: guest What am i doing wrong, or what is the correct way to do this?
adrian Posted April 8, 2014 Posted April 8, 2014 Does this code from Nik help? https://processwire.com/talk/topic/1901-possibility-to-login-user-through-api-without-knowing-password/#entry21465
Soma Posted April 8, 2014 Posted April 8, 2014 $user isn't updated since you're in a template and $user was set before you execute this code. $users->setCurrentUser($u); echo "<br />After setting current user: " . wire("user")->name So the new current user would only be available via wire("user") or $users->getCurrentUser(), that will get the new current user. 2
Pete Posted April 8, 2014 Posted April 8, 2014 $user isn't updated since you're in a template and $user was set before you execute this code. $users->setCurrentUser($u); echo "<br />After setting current user: " . wire("user")->name So the new current user would only be available via wire("user") or $users->getCurrentUser(), that will get the new current user. So would this make sense then Soma? // $user is initially the user at time of page load // ... some code $users->setCurrentUser($u); $user = $users->getCurrentUser(); // ... carry on using $user as normal Unless maybe you could do $user = $users->setCurrentUser($u) but I don't know as I've not tested any of this - just thinking out loud. 2
Harmster Posted April 9, 2014 Author Posted April 9, 2014 So would this make sense then Soma? // $user is initially the user at time of page load // ... some code $users->setCurrentUser($u); $user = $users->getCurrentUser(); // ... carry on using $user as normal Unless maybe you could do $user = $users->setCurrentUser($u) but I don't know as I've not tested any of this - just thinking out loud. EDIT: Didnt read... Sorry :S And it does work 3
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now