import {controller, directive, factory} from '../../infrastructure/Dectorators/Components'; import {Mod} from '../auth.mod'; export interface IAuthenticationService { authenticate(username: string, password: string): ng.IPromise; logout(): void; } export interface IAuthData { error: string; } @factory(Mod, 'authenticationService', ['$http', '$q', '$cookies', 'api', '$state']) export class AuthenticationService implements IAuthenticationService { constructor(private $http: ng.IHttpService, private $q: ng.IQService, private $cookies: ng.cookies.ICookiesService, private api: any, private $state: ng.ui.IStateService) { } authenticate(username: string, password: string): ng.IPromise { var data = { Username: username, Password: password, ActiveDirectoryUsername: '' }; return this.$http.post(this.api.authentication, data).then((response: ng.IHttpPromiseCallbackArg) => { if (response.data) { return response.data; } }, (error: any) => { return { error: 'Unable to connect to Chroma' }; }); } isLoggedOut(): Boolean { if (this.$cookies['ASP.NET_SessionId'] != null) { return false; } return true; }; logout(): void { delete this.$cookies['ASP.NET_SessionId']; this.$state.go('login'); }; updateApi(_newBase:string): void { let newBase = _newBase; let validPrefix = /^(ftp|http|https):\/\/[^ "]+$/.test(newBase); if (!validPrefix) { newBase = 'http://' + newBase; } newBase = newBase.replace(/\/?$/, ''); this.api.endpoint = newBase + '/api/'; this.api.flightList = newBase + '/api/flights'; this.api.authentication = newBase + '/api/auth'; this.api.detail = newBase + '/api/detail/'; this.api.imageSource = newBase + '/api/GetOperatorImage'; this.api.setSite = newBase + '/api/setSite'; this.api.getWindows = newBase + '/api/getWindows'; this.api.transactions = newBase + '/api/transactions'; this.api.cancelTransaction = newBase + '/api/cancelTransaction'; this.api.confirmTransaction = newBase + '/api/confirmTransaction'; this.api.createTransaction = newBase + '/api/createTransaction'; this.api.getTransactionCodes = newBase + '/api/getTransactionCodes'; this.api.getTransactionsAccess = newBase + '/api/getUserAccessRightsForTransaction'; this.api.getTransactionConfig = newBase + '/api/getTransactionConfig'; this.api.signalrHubs = newBase + '/signalr/hubs'; this.api.prmList = newBase + '/api/prmList'; }; }