Advertisement
Lauda

Untitled

May 15th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function register(user) {
  2.  
  3.     data = {
  4.         action: 'register',
  5.         username: $('input[name="username"]').val(),
  6.         password: $('input[name="password"]').val(),
  7.         firstname: $('input[name="firstname"]').val(),
  8.         lastname: $('input[name="lastname"]').val(),
  9.         email: $('input[name="email"]').val(),
  10.         phonenumber: $('input[name="phonenumber"]').val()
  11.     };
  12.  
  13.     if (user === 'buyer') {
  14.         data.address = $('input[name="address"]').val();
  15.     }
  16.  
  17.     $.ajax({
  18.         type: "POST",
  19.         url: user,
  20.         data: data,
  21.         success: function (response) {
  22.             console.log(response);
  23.             registrationCallback(JSON.parse(response));
  24.         }
  25.     });
  26. }
  27.  
  28. function login(user) {
  29.  
  30.     data = {
  31.         action: 'login',
  32.         username: $('input[name="username"]').val(),
  33.         password: $('input[name="password"]').val()
  34.     };
  35.  
  36.     $.ajax({
  37.         type: "POST",
  38.         url: user,
  39.         data: data,
  40.         success: function (response) {
  41.             loginCallback(JSON.parse(response));
  42.         }
  43.     });
  44. }
  45.  
  46. function loginCallback(response) {
  47.  
  48.     if (response.code === '200') {
  49.         window.location = '/ECoupon/' + response.data.url;
  50.     } else {
  51.         errorMessage(response.errors);
  52.     }
  53. }
  54.  
  55. function registrationCallback(response) {
  56.     if (response.code == '201') {
  57.        
  58.         if (response.data.type === 'seller') {
  59.             return;
  60.         }
  61.        
  62.         window.location = '/ECoupon/' + response.data.url;
  63.     } else {
  64.         errorMessage(reponse.errors);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement