linked google and github login buttons to view calls

pull/6/head
Chris Veilleux 2018-10-01 17:09:15 -05:00
parent bbac842f21
commit c669ec49d8
3 changed files with 51 additions and 4 deletions

View File

@ -25,6 +25,11 @@ form {
margin-top: 30px;
text-align: center;
}
button:hover {
background-color: #fd8e4c;
color: #2c3e50;
}
}
.mat-body-2 {

View File

@ -1,13 +1,13 @@
<div class="social">
<button mat-button class="google-button">
<button mat-button class="google-button" (click)="authenticateGoogle()">
<img src="../../../assets/google-logo.svg">
Log in with Google
</button>
<button mat-button class="facebook-button">
<button mat-button class="facebook-button" (click)="authenticateFacebook()">
<fa-icon [icon]="facebookIcon"></fa-icon>
Continue with Facebook
</button>
<button mat-button class="github-button" id="githubButton">
<button mat-button class="github-button" (click)="authenticateGithub()">
<fa-icon [icon]="githubIcon"></fa-icon>
Log in with GitHub
</button>

View File

@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { faFacebook, faGithub } from '@fortawesome/free-brands-svg-icons';
import { AuthResponse, AuthService } from "../auth.service";
@Component({
selector: 'login-auth-social',
@ -10,8 +11,49 @@ import { faFacebook, faGithub } from '@fortawesome/free-brands-svg-icons';
export class AuthSocialComponent implements OnInit {
public facebookIcon = faFacebook;
public githubIcon = faGithub;
public authFailed: boolean;
constructor() {}
constructor(private authService: AuthService) {}
ngOnInit() { }
authenticateFacebook(): void {
this.authService.authenticateWithFacebook().subscribe(
(response) => {this.onAuthSuccess(response)},
(response) => {this.onAuthFailure(response)}
);
}
authenticateGithub(): void {
this.authService.authenticateWithGithub().subscribe(
(response) => {this.onAuthSuccess(response)},
(response) => {this.onAuthFailure(response)}
);
}
authenticateGoogle(): void {
this.authService.authenticateWithGoogle().subscribe(
(response) => {this.onAuthSuccess(response)},
(response) => {this.onAuthFailure(response)}
);
}
onAuthSuccess(authResponse: AuthResponse) {
this.authFailed = false;
let expirationDate = new Date(authResponse.expiration * 1000);
let domain = document.domain.replace('login.', '');
document.cookie = 'seleneToken=' + authResponse.seleneToken +
'; expires=' + expirationDate.toUTCString() +
'; domain=' + domain;
document.cookie = 'tartarusToken=' + authResponse.tartarusToken +
'; expires=' + expirationDate.toUTCString() +
'; domain=' + domain;
window.parent.postMessage('loggedIn', '*')
}
onAuthFailure(authorizeUserResponse) {
if (authorizeUserResponse.status === 401) {
this.authFailed = true;
}
}
}