Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class LoginHelper{
  2.    
  3.     /**
  4.     *
  5.     *   Function that logs a user into the FMO system
  6.     *   Accepts a success and failure function to handle when a login request has been done.
  7.     */
  8.     login(email, password, success, failure){
  9.         // Encode the params
  10.         var params = 'email=' + email + '&password=' + password;
  11.  
  12.         // if there is a device id also pass that
  13.         if(window.localStorage.getItem('deviceToken') !== null){
  14.             params += '&deviceToken=' + window.localStorage.getItem('deviceToken') + '&deviceType=' + encodeURIComponent(device.platform) + '&deviceUUID=' + encodeURIComponent(device.uuid) + '&deviceOSVersion=' + encodeURIComponent(device.version);
  15.         }
  16.        
  17.         // Do Ajax request to check the users details
  18.         var ajax = new XMLHttpRequest();   
  19.    
  20.         // Get the Menu. This is Where the products get built into the page
  21.         ajax.onreadystatechange=function(){
  22.             if (ajax.readyState==4 && ajax.status==200){
  23.                 var user = JSON.parse(ajax.responseText);
  24.                 console.log(user);
  25.                 if(user == false){
  26.                     failure('Shit Went South');
  27.                 }
  28.  
  29.                 success(user);
  30.             }
  31.         }
  32.        
  33.         // Prepare the post login
  34.         ajax.open("POST", apiUrl + 'user/login', true);
  35.         //Send the proper header information along with the request
  36.         ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  37.         ajax.send(params); 
  38.     },
  39.  
  40.     forgotPassword(email){
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement