Guest User

Untitled

a guest
Jan 13th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. Codeigniter Ajax Login issue
  2. $(document).keypress(function (e) {
  3. if (e.which == 13) {
  4. var login = $("#login").val();
  5. var pass = $("#pass").val();
  6.  
  7. $('#login-block').removeBlockMessages().blockMessage('Please wait, cheking login...', {
  8. type: 'loading'
  9. });
  10. $.post("<?php echo base_url(); ?>index.php/login/validate_credentials/", {
  11. username: login,
  12. password: pass
  13. }, function (data) {
  14. if (data.error) {
  15. $('#login-block').removeBlockMessages().blockMessage(data.message, {
  16. type: 'error'
  17. });
  18. } else {
  19. document.location.href = data.redirect;
  20. }
  21. }, "json");
  22. }
  23. });
  24.  
  25. function validate() {
  26.  
  27. // CHECK LOGIN DETAILS
  28. $this->db-> select('first_name,last_name,usertype,id,products,mac');
  29. $this->db-> where('username', $this->input->post('username'));
  30. $this->db-> where('password', md5($this->input->post('password')));
  31. $query = $this->db->get('membership');
  32.  
  33. if ($query->num_rows() > 0) {
  34. $data = array('usertype' => $row->usertype, 'userid' => $row->id, 'first_name' => $row->first_name, 'last_name' => $row->last_name, 'products' => $row->products, 'mac' = > $row->mac);
  35. return $data;
  36. }
  37. }
  38.  
  39. if(data.error){
  40. $('#login-block').html('<p>'+data.message+'</p>);
  41. } else {
  42. document.location.href = data.redirect;
  43. }
  44.  
  45. if($query->num_rows()==1)
  46. {
  47. $data2 = array(
  48. 'error' => false,
  49. 'redirect' => base_url().'index.php/site/home/'
  50. );
  51.  
  52. $.getJSON('<?php echo base_url(); ?>index.php/login/validate_credentials/',{username: login, password: pass}, function(data) {
  53. if(data.error){
  54. $('#login-block').removeBlockMessages().blockMessage(data.message, {type: 'error'});
  55. } else {
  56. document.location.href = data.redirect;
  57. }
  58. });
Add Comment
Please, Sign In to add comment