Guest User

Untitled

a guest
Jan 26th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             var loginXHR = $.ajax({
  2.                 type: 'POST',
  3.                 url: controllerConfig.apiURL('user/login?_format=json'),
  4.                 data: JSON.stringify({ name: loginModel.formData.email, pass: loginModel.formData.password }),
  5.                 dataType: 'json',
  6.                 contentType: 'application/json; charset=utf-8',
  7.                 success: function(data) {
  8.                     console.log('login callback');
  9.                     $.clearAuthCookies();
  10.                     $.cookie('X-CSRF-Token', data.csrf_token, loginModel.useSessionCookie ? null : 365);
  11.                     $.cookie('Authorization', 'Basic ' + $.toBase64(loginModel.formData.email + ':' + loginModel.formData.password), loginModel.useSessionCookie ? null : 365);
  12.                 }
  13.             });
  14.  
  15.             var userXHR = $.ajax({
  16.                 type: 'POST',
  17.                 url: controllerConfig.apiURL('apptitude/user?_format=json'),
  18.                 data: '',
  19.                 dataType: 'json',
  20.                 contentType: 'application/json; charset=utf-8',
  21.                 success: function(data) {
  22.                     var ddo = new DrupalDataObject(data);
  23.                     console.log('user callback');
  24.                     controllerConfig.userInfo.firstname = ddo.field('field_firstname');
  25.                     controllerConfig.userInfo.lastname = ddo.field('field_lastname');
  26.                     controllerConfig.userInfo.avatar = ddo.field('user_picture');
  27.                 }
  28.             });
  29.  
  30.             $.when(loginXHR)
  31.                 .then(userXHR)
  32.                 .then(function() {
  33.                     console.log(arguments);
  34.                     loginModel.firstname = controllerConfig.userInfo.firstname;
  35.                     $.renderView(views['login'], loginModel);
  36.                     loginModel.showSubPage('.js-subpage-success');
  37.                 })
  38.                 .always(function() { $.spinner.stop(); })
  39.                 .fail(function() { $.say(L('auth_loginFailed')); });
Advertisement
Add Comment
Please, Sign In to add comment