Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Login
- * These functions will handle the login process through AJAX
- */
- $('#form-login').submit(function(event)
- {
- // Values
- var login = $.trim($('#login').val()),
- pass = $.trim($('#pass').val());
- // Check inputs
- if (login.length === 0)
- {
- // Display message
- displayError('Please fill in your login');
- return false;
- }
- else if (pass.length === 0)
- {
- // Remove empty login message if displayed
- formWrapper.clearMessages('Please fill in your login');
- // Display message
- displayError('Please fill in your password');
- return false;
- }
- else
- {
- // Remove previous messages
- formWrapper.clearMessages();
- // Show progress
- displayLoading('Checking credentials...');
- // Stop normal behavior
- event.preventDefault();
- //This is where you may do your AJAX call, for instance:
- $.ajax({
- type: "GET",
- url: "functions/ajax.php",
- data: {
- func: "login",
- username: login,
- password: pass
- },
- error: function() {
- formWrapper.clearMessages();
- displayError('Error while contacting server, please try again');
- },
- success: function(data) {
- if(data == "logged") {
- setTimeout(function() {
- document.location.href = 'dashboard.php'
- }, 2000);
- } else if(data == "failed") {
- formWrapper.clearMessages();
- displayError('Invalid user/password, please try again');
- } else if(data == "banned") {
- formWrapper.clearMessages();
- displayError('Account suspended, contact support!');
- } else if(data == "inactive") {
- formWrapper.clearMessages();
- displayError('Account inactive, check Your email!');
- }
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement