54 lines
1.6 KiB
TypeScript

/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license PROPRIETARY (see license file)
*/
import { Component, OnInit } from '@angular/core';
import { ApplicationService } from 'app/service';
import { GetApplicationSmallResponse, SpecificTokenResponse } from 'app/service/application';
import { UserService } from 'common/service';
@Component({
selector: 'app-home',
templateUrl: './home.html',
styleUrls: ['./home.less'],
})
export class HomeScene implements OnInit {
error = '';
dataList: GetApplicationSmallResponse[];
constructor(private applicationService: ApplicationService, private userService: UserService) {}
ngOnInit() {
let self = this;
this.applicationService
.getApplicationsSmall()
.then((data: GetApplicationSmallResponse[]) => {
self.dataList = data;
})
.catch(error => {
console.log(`fail to keep data : ${error}`);
});
}
onClick(_event: any, data: GetApplicationSmallResponse): void {
//window.location.href = data.redirect;
let self = this;
this.applicationService
.getApplicationSpecificToken(data.name)
.then((result: SpecificTokenResponse) => {
self.transferToApplicationThatRequiredTheSSO2(result.url, result.jwt);
})
.catch((error: any) => {
console.error(`Can not retreive the application interface: ${error}`);
});
}
private transferToApplicationThatRequiredTheSSO2(url: string, token: string): void {
if (url.slice(-1) === '/') {
url = url.slice(0, -1);
}
let ssoApplicationReturnUrl = `${url}/aG9tZQ/${this.userService.getRememberMe()}/`;
window.location.href = ssoApplicationReturnUrl + token;
}
}