no message
This commit is contained in:
parent
b8e040ee94
commit
3b1f37ef22
|
@ -1,91 +0,0 @@
|
||||||
import { Component, OnInit, ElementRef, AfterViewInit, VERSION, Injectable } from '@angular/core';
|
|
||||||
import { TokenService, TokenProvider } from '../../services/login/token.service';
|
|
||||||
import {Router} from '@angular/router';
|
|
||||||
|
|
||||||
declare const gapi: any;
|
|
||||||
|
|
||||||
declare var $ :any;
|
|
||||||
|
|
||||||
import '../../../assets/custom.js';
|
|
||||||
declare function simple_notifier(type: string, title: string, message:string): any;
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'googgle-sign-in',
|
|
||||||
templateUrl: './googgle-sign-in.component.html',
|
|
||||||
styleUrls: ['./googgle-sign-in.component.css']
|
|
||||||
})
|
|
||||||
export class GooggleSignInComponent implements OnInit, AfterViewInit, Injectable {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constructor(private element: ElementRef, private tokenService : TokenService, private router : Router) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
//this.googleInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
ngAfterViewInit() {
|
|
||||||
|
|
||||||
this.googleInit();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private clientId:string = '1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com';
|
|
||||||
|
|
||||||
private scope = [
|
|
||||||
'profile',
|
|
||||||
'email'
|
|
||||||
//,
|
|
||||||
//'https://www.googleapis.com/auth/plus.me',
|
|
||||||
//'https://www.googleapis.com/auth/contacts.readonly',
|
|
||||||
//'https://www.googleapis.com/auth/admin.directory.user.readonly'
|
|
||||||
].join(' ');
|
|
||||||
|
|
||||||
public auth2: any;
|
|
||||||
|
|
||||||
public googleInit() {
|
|
||||||
|
|
||||||
gapi.load('auth2', () => {
|
|
||||||
this.auth2 = gapi.auth2.init({
|
|
||||||
client_id: this.clientId,
|
|
||||||
cookiepolicy: 'single_host_origin',
|
|
||||||
scope: this.scope
|
|
||||||
});
|
|
||||||
|
|
||||||
//RE-Render the button (due to known issues of google-button with angular's lifecycle)
|
|
||||||
gapi.signin2.render('googleBtn', {
|
|
||||||
'onsuccess': console.log("SUCCESSFULLY RERENDERED THE BUTTON"),
|
|
||||||
'onfailure': console.log("FAILED TO RERENDER THE BUTTON")
|
|
||||||
});
|
|
||||||
|
|
||||||
var buttonElement = this.element.nativeElement.querySelector('#googleBtn');
|
|
||||||
this.attachSignin(buttonElement);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public attachSignin(element) {
|
|
||||||
this.auth2.attachClickHandler(element, {},
|
|
||||||
(googleUser) => {
|
|
||||||
//simple_notifier("success",null,"Successful login");
|
|
||||||
let profile = googleUser.getBasicProfile();
|
|
||||||
this.tokenService.login(googleUser.getAuthResponse().id_token, TokenProvider.google, profile.getName(), profile.getEmail());
|
|
||||||
},
|
|
||||||
function (error) {
|
|
||||||
//simple_notifier("danger",null,"Failed to login");
|
|
||||||
console.log(JSON.stringify(error, undefined, 2));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue