Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. this.googleLogin = function() {
  2. var frontendLocation = $location.host() + ':' + $location.port() + '/',
  3. frontendLocationRegExp = new RegExp(frontendLocation),
  4. deferred = $q.defer(),
  5. win = window.open(BackendAPI.createUrl("login/google-oauth2"), "", "width=800, height=800"),
  6. interval = window.setInterval(function() {
  7. try {
  8. if(frontendLocationRegExp.test(win.document.URL)) { //if in popup we have url from frontend host and port code below is executed
  9. win.close();
  10. var res = win.document.URL.split(frontendLocation),
  11. userData = JSON.parse(decodeURIComponent(res[1]).replace('#', '')); // after decodeURI we delete from string '#' chars
  12. deferred.resolve({
  13. name: userData.first_name,
  14. surname: userData.last_name,
  15. email: userData.email
  16. });
  17. clearInterval(interval);
  18. }
  19. } catch(e) {
  20. console.log(e);
  21. clearInterval(interval);
  22. deferred.reject();
  23. }
  24. }, 300);
  25. return deferred.promise;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement