56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { AuthService } from '../../services/auth/auth.service';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Component, OnInit, ElementRef, AfterViewInit, VERSION, Injectable } from '@angular/core';
|
|
import { Router, ActivatedRoute, Params } from "@angular/router";
|
|
import { SnackBarNotificationComponent } from "../../shared/components/notificaiton/snack-bar-notification.component";
|
|
import { MatPaginator, MatSort, MatSnackBar } from "@angular/material";
|
|
import { TranslateService } from "@ngx-translate/core";
|
|
declare const gapi: any;
|
|
|
|
declare const auth2 :any;
|
|
@Component({
|
|
selector: 'app-main-sign-in',
|
|
templateUrl: './main-sign-in.component.html',
|
|
styleUrls: ['./main-sign-in.component.css']
|
|
})
|
|
export class MainSignInComponent implements OnInit {
|
|
|
|
constructor(private element: ElementRef, private router : Router,private authService:AuthService,private route:ActivatedRoute,
|
|
public snackBar: MatSnackBar,public language: TranslateService) { }
|
|
|
|
ngOnInit() {
|
|
}
|
|
|
|
loginBtn() {
|
|
}
|
|
|
|
|
|
public googleSignIn() {
|
|
auth2.grantOfflineAccess().then((authResult)=>this.signInCallback(authResult))
|
|
}
|
|
|
|
signInCallback(authResult){
|
|
if (authResult['code']) {
|
|
this.authService.login({ticket:authResult['code'],service:"google"}).subscribe(
|
|
res => this.onLogInSuccess(res),
|
|
error => this.onLogInError(error)
|
|
)
|
|
}
|
|
}
|
|
|
|
public onLogInSuccess(logoutMessage: any) {
|
|
this.route.queryParams.subscribe((params: Params) => {
|
|
let redirectUrl = params['returnUrl'] ? params['returnUrl'] : '/';
|
|
this.router.navigate([redirectUrl]);
|
|
})
|
|
}
|
|
|
|
public onLogInError(errorMessage: string) {
|
|
console.log(errorMessage);
|
|
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
|
|
data: { message: 'GENERAL.SNACK-BAR.UNSUCCESSFUL-LOGIN', language: this.language },
|
|
duration: 3000,
|
|
extraClasses: ['snackbar-warning']
|
|
})
|
|
}
|
|
} |