Jump to content

$user->isLoggedin() internal server error


benbyf
 Share

Recommended Posts

HELLO!

I'm using $user->isLoggedin() three times on one template (in the head.inc, template-page.php and foot.inc). I'm using a custom login in my template file:

// If they aren't logged in, then show the login form
if(!$user->isLoggedin()){

	// check for login before outputting markup
	if($input->post->user && $input->post->pass) {

		$user = $sanitizer->username($input->post->user);
		$pass = $input->post->pass;

		if($session->login($user, $pass)) {
			// login successful
			$session->redirect($homepage->url);
		} else {
			// login error
			$session->login_error = 'Login Failed. Please try again, or use the forgot password link below.';
		}
	}
	if($input->post->user && $input->post->pass) {
		$login = "<p class='error'>" . $session->login_error . "</p>";
	}
	$login .= "<form action='./' method='post'><div class='login'>
			<input type='text' id='user' name='user' placeholder='Enter your SP Company Code' />
			<input class='hidden' type='password' name='pass' value='' />
			<p><input type='submit' class='btn' name='submit' value='Login' /></p>
		</div></form>";

} // end !logged in

Using the correct logins works and everything is cool, but putting the wrong passwords in creates a Internal server error on both the head.inc and foot.inc $user->isLoggedin() functions.

I'm probably doing something absurdly stupid here, any ideas?

thanks

Link to comment
Share on other sites

if($session->login($user, $pass)) {
            // login successful
            $session->redirect($homepage->url);
        } else {
            // login error
            $session->login_error = 'Login Failed. Please try again, or use the forgot password link below.';
        }

may be is causing an error

put them in a try catch block

try {
if($session->login($user, $pass)) {
			// login successful
			$session->redirect($homepage->url);
		} else {
			// login error
			
$session->login_error = 'Login Failed. Please try again, or use the forgot password link below.';
		}

} catch (Exception $e) {
   wire('log')->save('debug', $e->getMessage());
}
  • Like 1
Link to comment
Share on other sites

This kind of error is usually because your code is overwriting the PW $user object. Try making your own user and password variable something like $u and $p, then there is no chance of that happening.

  • Like 9
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...