Advertisement
Guest User

Working

a guest
Apr 30th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1.             /*
  2.              * Login
  3.              * These functions will handle the login process through AJAX
  4.              */
  5.             $('#form-login').submit(function(event)
  6.             {
  7.                 // Values
  8.                 var login = $.trim($('#login').val()),
  9.                     pass = $.trim($('#pass').val());
  10.  
  11.                 // Check inputs
  12.                 if (login.length === 0)
  13.                 {
  14.                     // Display message
  15.                     displayError('Please fill in your login');
  16.                     return false;
  17.                 }
  18.                 else if (pass.length === 0)
  19.                 {
  20.                     // Remove empty login message if displayed
  21.                     formWrapper.clearMessages('Please fill in your login');
  22.  
  23.                     // Display message
  24.                     displayError('Please fill in your password');
  25.                     return false;
  26.                 }
  27.                 else
  28.                 {
  29.                     // Remove previous messages
  30.                     formWrapper.clearMessages();
  31.  
  32.                     // Show progress
  33.                     displayLoading('Checking credentials...');
  34.  
  35.                     // Stop normal behavior
  36.                     event.preventDefault();
  37.  
  38.                    
  39.                      //This is where you may do your AJAX call, for instance:
  40.                      $.ajax({
  41.                             type: "GET",
  42.                             url: "functions/ajax.php",
  43.                             data: {
  44.                                 func:   "login",
  45.                                 username: login,
  46.                                 password: pass
  47.                             },
  48.    
  49.                             error: function() {
  50.                                 formWrapper.clearMessages();
  51.                                 displayError('Error while contacting server, please try again');
  52.                             },
  53.                             success: function(data) {
  54.                            
  55.                                 if(data == "logged") {
  56.                                 setTimeout(function() {
  57.                                 document.location.href = 'dashboard.php'
  58.                                                       }, 2000);
  59.                                 } else if(data == "failed") {
  60.                                     formWrapper.clearMessages();
  61.                                     displayError('Invalid user/password, please try again');
  62.                                 } else if(data == "banned") {
  63.                                     formWrapper.clearMessages();
  64.                                     displayError('Account suspended, contact support!');
  65.                                 } else if(data == "inactive") {
  66.                                     formWrapper.clearMessages();
  67.                                     displayError('Account inactive, check Your email!');
  68.                                 }
  69.                             }
  70.                     });
  71.                 }
  72.             });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement