I am trying to create an ajax login script but have hit a wall. I hav built one before but now using the cakephp framwework.
I’m not really sure ho to go about this. At the moment I have a login function in the controller,
public function login()
{
if($this->request->is('post')) {
if($this->Auth->login()) {
$this->Session->setFlash('Login Passed');
} else {
$this->Session->setFlash('Login Failed');
}
}
}
Do i then use ajax to send values to this from the form? These lines are from my old (non-cakephp) system,
xmlhttp.open("POST","http://www.site.com/login/",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("AttemptLogin=true&AccountEmail="+ userMail +"&AccountPassword=" + userPass);
Should i modify them in any way? Also, how do i handle any validations and login attempts with errorsetc.
Sorry about the question being quite open ended and long but i don’t know where to go,I have looked for tutorials but can’t find any.
Many Thanks
Chris
You can use javascript helper from cake and have one template that converts
the response to the json format, in the controller just include the helper:
So yo can set you function like:
And the javascript i recommend jQuery