import { Injectable } from '@angular/core'; import { Http, Headers } from '@angular/http'; import { Router } from '@angular/router'; import { Location } from '@angular/common'; import { CoreRemoteRestURL } from '../utils/core-remote-rest-urls'; @Injectable() export class LoginService { private loggedIn = false; constructor(private http: Http, private router: Router, private location: Location) { } login(): boolean { $.ajaxSetup({ xhrFields: { withCredentials: true }, crossDomain: true }); let bool = false; $.ajax(CoreRemoteRestURL.LOGIN_AUTHUNTICATION_URL, { type: "GET", async: false, dataType: 'text', success: (data, status, response) => { bool = true; if ($('#core_login_popup').is(':visible')) { $('#core_login_popup').modal('hide'); window.location.reload(); } }, error: (response, status, error) => { $('#core_login_popup').modal({ show: true, backdrop: 'static', keyboard: false }); let frame = document.getElementById('login_frame'); frame.onload = () => { this.login(); } } }); return this.trueOrFalse(bool); } trueOrFalse(bool): boolean { return bool; } }