Hey PW people!
I made a custom login form which sends a request to an AJAX page that should log me in, I'll post the scripts in a second. But I'd get a weird error of some sort.
This is what I do
I log in on my login form (/user/login)
It logs me in, session is created and everything
I go to the homepage -> i log out -> i go back to the login page and i login again, this is where i can't login i get a message "Incorrect password and username"(my custom message which is returned at a NULL return which means it fails right?!
So these are my scripts
Login.php:
<?php
if(!$user->isLoggedin())
{
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#login").click(function(){
$("#ajax").html("Laden...");
$.ajax({
url: '/site/ajax/ajaxResponder.php',
type: 'post',
dataType: 'JSON',
data: {
'action': 'login',
'username': $("#username").val(),
'password': $("#password").val()
},
success:function(data){
alert(data.pass);
if(data.status)
{
window.location = "/";
}
$("#ajax").html(data.message);
}
});
return false;
});
});
</script>
<?php
?>
<form action ="" method="post">
<label for="username">Gebruikersnaam:</label>
<input type="text" name="username" id="username" />
<label for="password">Wachtwoord:</label>
<input type="password" name="password" id="password" />
<input type="submit" value="Login" id="login"/>
</form>
<div id="ajax"></div>
<?php
}
else
{
echo 'Je bent ingelogt.<br /><a href="/user/logout">Log uit</a>';
}
?>
This is ajaxResponder (the part that matters, the case in a switch $_POST['action'])(/site/ajax/ajaxResponder.php)
case 'login':
$pass = $_POST['password'];
$user = $_POST['username'];
$r = wire('session')->login($user, $pass);
if($r)
{
$re['message'] = 'U bent ingelogd';
$re['status'] = true;
}
else
{
$re['message'] = 'Uw gebruikersnaam of wachtwoord is onjuist';
$re['status'] = false;
}
echo json_encode($re);
break;
So what can I do to fix this problem?
Kind regards,
Harm.