Joe Posted March 26, 2014 Posted March 26, 2014 (edited) With a login link I am either sent to the Admin > Pages view ({$config->urls->admin}) or to the edit view of the page the login link is on ({$config->urls->admin}page/edit/?id={$page->id}) after logging in.I would like to set up a login link that points to the home page instead (the public home page, but as a logged-in user). Possibly also a login link on other pages that sends you to the page itself rather than to its edit view. I havent´t been able to come up with of a way of setting up such a link yet. Does anyone know offhand?Thank you! Edited March 26, 2014 by Joe
adrian Posted March 26, 2014 Posted March 26, 2014 This is mostly stolen from Ryan: https://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/?p=15919 But it adds the functionality to redirect back to the page the user was on when they started the login: $requested_pid = (int) $input->get->pid; $t = $pages->get($requested_pid)->path; if($user->isLoggedin()){ if($requested_pid == ''){ $session->redirect('/'); } else{ $session->redirect($t); } } if($input->post->username && $input->post->pass) { $username = $sanitizer->username($input->post->username); $pass = $input->post->pass; $u = $users->get($username); if($u->id && $u->tmp_pass && $u->tmp_pass === $pass) { // user logging in with tmp_pass, so change it to be their real pass $u->of(false); $u->pass = $u->tmp_pass; $u->save(); $u->of(true); } $u = $session->login($username, $pass); if($u) { // user is logged in, get rid of tmp_pass $u->of(false); $tmp_pass = $u->tmp_pass; $u->tmp_pass = ''; $u->save(); // now redirect to the profile edit page if($tmp_pass == $pass){ $session->redirect('/profile/'); } else{ $session->redirect($t); } } } // present the login form $headline = $input->post->username ? "Login failed" : "Please login"; echo " <h2>$headline</h2> <form action='./?pid=".$requested_pid."' method='post'> <p> <label>Username <input type='text' name='username'></label> <label>Password <input type='password' name='pass'></label> </p> <input class='bluebutton' type='submit' name='login' value='Login'> </form><hr /><br /> <p><a href='/reset-pass/'>Forgot Password?</a></p> "; Keep in mind that this also includes "forgot password" functionality, but doesn't include all the code for that - take a look at that post of Ryan's to get the rest. 2
Joe Posted March 26, 2014 Author Posted March 26, 2014 Thanks a lot Adrian! I followed the link you gave, https://processwire....n-form/?p=15919, and there I saw a link to https://processwire.com/talk/topic/107-custom-login/?p=735 and that was pretty much exactly the solution!
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