/** @file * @author Edouard DUPIN * @copyright 2018, Edouard DUPIN, all right reserved * @license PROPRIETARY (see license file) */ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Location } from '@angular/common'; import { AdminUserService, ApplicationService } from 'base/service'; import { UserService, isNullOrUndefined } from '@kangaroo-and-rabbit/kar-cw'; export function checkLoginValidity(value: string): boolean { let regexCheck = new RegExp('^[a-zA-Z0-9_\\.-]+$'); if (regexCheck.test(value)) { return true; } return false; } export function checkEmailValidity(value: string): boolean { let regexCheck = new RegExp('^[a-zA-Z0-9_\\.@-]+@[a-zA-Z0-9_\\.-]+\\.[a-zA-Z]+$'); if (regexCheck.test(value)) { return true; } return false; } export function checkPasswordValidity(value: string): boolean { let regexCheck = new RegExp('^[a-zA-Z0-9_\\.@ %:;,=}{\\?\\!\\*\\+\\(\\)\\[\\]\\|&#%~/\\\\\\<\\>-£€]+$'); if (regexCheck.test(value)) { return true; } return false; } @Component({ selector: 'app-sign-out', templateUrl: './sign-out.html', styleUrls: ['./sign-out.less'], }) export class SignOutScene implements OnInit { private ssoApplicationId: string | undefined; private ssoReturnData: string | undefined; private ssoApplicationReturnUrl: string | undefined; constructor( private router: Router, private route: ActivatedRoute, private locate: Location, private userService: UserService, private applicationService: ApplicationService, private adminUserService: AdminUserService ) { } ngOnInit() { const ssoApplicationId = this.route.snapshot.paramMap.get('applicationId'); if (ssoApplicationId == null) { this.ssoApplicationId = undefined; } else { this.ssoApplicationId = ssoApplicationId; } const ssoReturnData = this.route.snapshot.paramMap.get('dataReturn'); if (ssoReturnData == null) { this.ssoReturnData = undefined; } else { this.ssoReturnData = ssoReturnData; } /* console.error(`MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM`); console.error(`get parameter update: ${this.ssoApplicationId}`); console.error(`get parameter update: ${this.ssoReturnData}`); console.error(`MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM`); */ this.logout(); } logout(): void { let self = this; if (isNullOrUndefined(self.ssoApplicationId)) { this.userService.removeSession(); this.router.navigate(['home']); } else { this.applicationService .getApplicationReturn(this.ssoApplicationId) .then((url: string) => { self.transferToApplicationThatRequiredTheSSO2(url); }) .catch((error: any) => { // TODO: self.error = `Can not retreive the application interface`; this.userService.removeSession(); this.router.navigate(['home']); }); } } private transferToApplicationThatRequiredTheSSO2(url: string): void { // TODO: redirect sso caller after getting an application specific token ... if (url.slice(-1) === '/') { url = url.slice(0, -1); } this.userService.removeSession(); window.location.href = `${url}/${this.ssoReturnData}/false/__LOGOUT__`; } }