[CodeIgniter] jQuery Login
Ik ben bezig met het ontwerpen van een applicatie waarbij gebruikers inloggen via een een jQuery form:
Zoals je ziet wordt de data verzonden naar login/process bij een submit:
Zodra ik de form_validation weghaal in de controller krijg ik geen js foutmeldingen in FireBug (een plugin voor Firefox). Maar als ik die er wel in heb staan dan krijg ik een 500 Internal Server Error. Naar mijn weten heb ik niets aangepast nadat het werkte. En ja, de documentatie moet nog verbeterd worden! ;-)
Ik hoop dat jullie mij verder kunnen helpen!
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$('#login form').submit(function()
{
$.post('login/process', {username:$('#username').val(), userpass:$('#userpass').val(), rand:Math.random()}, function(status)
{
if(status == true)
{
$('#error').fadeTo(0, 0.1, function()
{
$('#login #submit').fadeOut(250);
$(this).html('U wordt doorgestuurd!').fadeTo(250, 1, function()
{
$('#container #login').fadeOut(500, function()
{
location.reload();
});
});
});
}
else
{
$('#error').fadeTo(1, 0.1, function()
{
$(this).html('Inloggegevens zijn onjuist!').fadeTo(250, 1);
});
}
});
return false;
});
{
$.post('login/process', {username:$('#username').val(), userpass:$('#userpass').val(), rand:Math.random()}, function(status)
{
if(status == true)
{
$('#error').fadeTo(0, 0.1, function()
{
$('#login #submit').fadeOut(250);
$(this).html('U wordt doorgestuurd!').fadeTo(250, 1, function()
{
$('#container #login').fadeOut(500, function()
{
location.reload();
});
});
});
}
else
{
$('#error').fadeTo(1, 0.1, function()
{
$(this).html('Inloggegevens zijn onjuist!').fadeTo(250, 1);
});
}
});
return false;
});
Zoals je ziet wordt de data verzonden naar login/process bij een submit:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
function process()
{
/** Set form validation rules **/
$this->form_validation->set_rules('username', 'userName', 'required|trim');
$this->form_validation->set_rules('userpass', 'userPass', 'required|trim');
/** Validate the form **/
if ($this->form_validation->run() == false)
{
/** Validate not valid **/
echo false;
/** Redirect to the login **/
redirect('login');
}
else
{
/** Read the form inputs **/
$userName = $this->input->post('username');
$userPass = $this->input->post('userpass');
/** Call the model with the form inputs **/
$userLogin = $this->login_model->userLogin($userName, $userPass);
/** Check if the user can be logged in **/
if ($userLogin == false)
{
/** User not logged in **/
echo false;
}
else
{
/** Check now if the account is enabled **/
if ($this->session->userdata('userActive') == 1 && $this->session->userdata('userID') > 0)
{
/** Log this into the database **/
$this->login_model->loginHistory();
/** Account is active **/
echo true;
}
else
{
/** User not logged in **/
echo false;
}
}
}
}
?>
function process()
{
/** Set form validation rules **/
$this->form_validation->set_rules('username', 'userName', 'required|trim');
$this->form_validation->set_rules('userpass', 'userPass', 'required|trim');
/** Validate the form **/
if ($this->form_validation->run() == false)
{
/** Validate not valid **/
echo false;
/** Redirect to the login **/
redirect('login');
}
else
{
/** Read the form inputs **/
$userName = $this->input->post('username');
$userPass = $this->input->post('userpass');
/** Call the model with the form inputs **/
$userLogin = $this->login_model->userLogin($userName, $userPass);
/** Check if the user can be logged in **/
if ($userLogin == false)
{
/** User not logged in **/
echo false;
}
else
{
/** Check now if the account is enabled **/
if ($this->session->userdata('userActive') == 1 && $this->session->userdata('userID') > 0)
{
/** Log this into the database **/
$this->login_model->loginHistory();
/** Account is active **/
echo true;
}
else
{
/** User not logged in **/
echo false;
}
}
}
}
?>
Zodra ik de form_validation weghaal in de controller krijg ik geen js foutmeldingen in FireBug (een plugin voor Firefox). Maar als ik die er wel in heb staan dan krijg ik een 500 Internal Server Error. Naar mijn weten heb ik niets aangepast nadat het werkte. En ja, de documentatie moet nog verbeterd worden! ;-)
Ik hoop dat jullie mij verder kunnen helpen!
Gesponsorde koppelingen:
Ik heb het inmiddels al opgelost. Ik heb het nu opgelost met jQuery en JSON.



