Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.googleLogin = function() {
- var frontendLocation = $location.host() + ':' + $location.port() + '/',
- frontendLocationRegExp = new RegExp(frontendLocation),
- deferred = $q.defer(),
- win = window.open(BackendAPI.createUrl("login/google-oauth2"), "", "width=800, height=800"),
- interval = window.setInterval(function() {
- try {
- if(frontendLocationRegExp.test(win.document.URL)) { //if in popup we have url from frontend host and port code below is executed
- win.close();
- var res = win.document.URL.split(frontendLocation),
- userData = JSON.parse(decodeURIComponent(res[1]).replace('#', '')); // after decodeURI we delete from string '#' chars
- deferred.resolve({
- name: userData.first_name,
- surname: userData.last_name,
- email: userData.email
- });
- clearInterval(interval);
- }
- } catch(e) {
- console.log(e);
- clearInterval(interval);
- deferred.reject();
- }
- }, 300);
- return deferred.promise;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement