simplified with new change to federated sign in

pull/1/head
Chris Veilleux 2019-02-05 11:25:59 -06:00
parent 511d19c77b
commit f90bae288b
1 changed files with 5 additions and 49 deletions

View File

@ -1,11 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { MatSnackBar } from '@angular/material';
import { isArray } from 'util';
import { AppService } from '../app.service';
import { SocialLoginData } from '../app.service';
const noDelay = 0;
@Component({ @Component({
selector: 'sso-login', selector: 'sso-login',
@ -14,51 +8,13 @@ const noDelay = 0;
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
constructor( constructor() { }
private authService: AppService,
public loginSnackbar: MatSnackBar
) { }
ngOnInit() { ngOnInit() {
this.storeRedirectUrl(); localStorage.setItem(
'redirect',
decodeURIComponent(window.location.search).slice(10)
);
} }
storeRedirectUrl() {
const uriQuery = decodeURIComponent(window.location.search);
if (uriQuery.startsWith('?data')) {
this.parseUriQuery(uriQuery);
} else if (uriQuery.startsWith('?redirect')) {
localStorage.setItem(
'redirect',
decodeURIComponent(window.location.search).slice(10)
);
}
}
parseUriQuery (uriQuery: string) {
let socialLoginData: SocialLoginData = null;
const parsedQuery = JSON.parse(uriQuery.slice(6));
if (isArray(parsedQuery)) {
const firstItem = parsedQuery[0];
if (firstItem.key === 'duplicated.user.email') {
const socialLoginErrorMsg = 'An account exists for the email ' +
'address associated with the social network log in ' +
'attempt. To enable log in using a social network, log ' +
'in with your username and password and enable the ' +
'social network in your account preferences.';
this.loginSnackbar.open(
socialLoginErrorMsg,
null,
{duration: 30000}
);
}
} else {
socialLoginData = <SocialLoginData>parsedQuery;
this.authService.generateExternalLoginTokens(socialLoginData).subscribe(
(response) => {
this.authService.navigateToRedirectURI(noDelay);
}
);
}
}
} }