Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. JS:
  2.  
  3. $('.btn_measurements_login').click(function() {
  4.  
  5. var email = $('.login_email').val();
  6. var password = $('.login_password').val();
  7.  
  8. // Try to log the user in...
  9. $.ajax({
  10. type: "POST",
  11. url: "/Users/ajaxLogin",
  12. data: {email: email, password: password},
  13. success: function(html){
  14. if(html == 'true') {
  15. alert('logged in...');
  16. } else {
  17. alert('fail...');
  18. }
  19. },
  20. beforeSend:function() {
  21. $('.login_error').html("<img src='/img/loading.gif' class='loading'>").show();
  22. }
  23. });
  24. });
  25.  
  26. PHP:
  27.  
  28. public function ajaxLogin() {
  29. $this->layout = 'ajax';
  30.  
  31. $tmp['User']['email'] = $this->request->data['email'];
  32. $tmp['User']['password'] = $this->request->data['password'];
  33.  
  34. $this->log(print_r($tmp, TRUE), 'l');
  35.  
  36. if ($this->Auth->login($tmp)) {
  37. $this->log("UID: " . $this->Auth->user('id'), 'l');
  38. $this->log("Logged in...", 'l');
  39. echo 'true';
  40. } else {
  41. $this->log("Failed...", 'l');
  42. echo 'false';
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement