Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. var _registerExternal = function (registerExternalData) {
  2.  
  3. var deferred = $q.defer();
  4.  
  5. FB.api('/me', { fields: 'first_name,last_name,email' }, function (resp) {
  6. var data = {
  7. provider: 'Facebook',
  8. externalAccessToken: registerExternalData.externalAccessToken,
  9. email: resp.email,
  10. firstName: resp.first_name,
  11. lastName: resp.last_name
  12. };
  13. $http.post(serviceBase + 'auth/register/external', data).success(function (response) {
  14.  
  15. localStorageService.set('authorizationData', { token: response.access_token, userName: response.userName, userId: response.user_id, roles: response.roles + ',User', refreshToken: "", useRefreshTokens: false });
  16.  
  17. _authentication.isAuth = true;
  18. _authentication.userName = response.userName;
  19. _authentication.userId = response.user_id;
  20. _authentication.roles = response.roles + ',User';
  21. _authentication.useRefreshTokens = true;
  22.  
  23. deferred.resolve(response);
  24.  
  25. }).error(function (err, status) {
  26. _logOut();
  27. deferred.reject(err);
  28. });
  29. });
  30.  
  31. return deferred.promise;
  32. };
  33.  
  34. //i po-nadolu e tova:
  35.  
  36.  
  37. FB.Event.subscribe('auth.authResponseChange', function (res) {
  38. if (res.status === 'connected') {
  39. /*
  40. The user is already logged,
  41. is possible retrieve his personal info
  42. */
  43. _obtainAccessToken({ provider: 'Facebook', externalAccessToken: res.authResponse.accessToken });
  44.  
  45. /*
  46. This is also the point where you should create a
  47. session for the current user.
  48. For this purpose you can use the data inside the
  49. res.authResponse object.
  50. */
  51. }
  52. else {
  53. /*
  54. The user is not logged to the app, or into Facebook:
  55. destroy the session on the server.
  56. */
  57. }
  58. });
  59.  
  60. FB.Event.subscribe('auth.statusChange', function (res) {
  61. console.log("respn");
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement