SUPPORT-8830 fix logout
This commit is contained in:
parent
2747452b88
commit
f77c95b1cd
2 changed files with 34 additions and 17 deletions
|
|
@ -1,10 +1,9 @@
|
|||
<form #logoutForm method="post" [action]="formAction" hidden style="display: none">
|
||||
<input type="hidden" name="_csrf" [value]="csrfValue"/>
|
||||
</form>
|
||||
<button class="user-info" ngbDropdownToggle *ngIf="getIsAuth()">{{getUserFullname()}}</button>
|
||||
<div ngbDropdownMenu *ngIf="getIsAuth()">
|
||||
<a routerLink="/mydata" class="data">Мои данные</a>
|
||||
<form ngbDropdownItem method="post" action="/esia/logout">
|
||||
<button class="exit" type="submit">Выйти</button>
|
||||
</form>
|
||||
<button ngbDropdownItem class="exit" (click)="logoutForm.submit()">Выйти</button>
|
||||
</div>
|
||||
<form method="post" action="/esia/logout">
|
||||
<button class="exit" type="submit">Выйти</button>
|
||||
</form>
|
||||
<button class="exit" *ngIf="!getIsAuth()" (click)="logoutForm.submit()">Выйти</button>
|
||||
|
|
|
|||
|
|
@ -1,21 +1,45 @@
|
|||
import {ChangeDetectorRef, Component, OnInit} from "@angular/core";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {ChangeDetectorRef, Component, DoCheck, OnInit} from "@angular/core";
|
||||
import {HttpClient, HttpXsrfTokenExtractor} from "@angular/common/http";
|
||||
import {CookieService} from "ngx-cookie";
|
||||
import {AppConfigService} from "@webbpm/base-package";
|
||||
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
selector: "[log-out]",
|
||||
templateUrl: "../../../../../src/resources/template/app/component/log_out.html"
|
||||
})
|
||||
export class LogOutComponent implements OnInit{
|
||||
export class LogOutComponent implements OnInit, DoCheck{
|
||||
private static readonly BACKEND_URL: string = "backend.url";
|
||||
private static readonly BACKEND_CONTEXT: string = "backend.context";
|
||||
private static readonly LOGOUT_URL_POSTFIX: string = "/esia/logout";
|
||||
|
||||
private userFullname: string;
|
||||
csrfValue: any;
|
||||
formAction: any;
|
||||
|
||||
constructor(private httpClient: HttpClient,
|
||||
private cookieService: CookieService, private cd: ChangeDetectorRef) {
|
||||
private cookieService: CookieService,
|
||||
private appConfigService: AppConfigService,
|
||||
private tokenExtractor: HttpXsrfTokenExtractor,
|
||||
private cd: ChangeDetectorRef) {
|
||||
let backendUrl = this.appConfigService.getParamValue(LogOutComponent.BACKEND_URL);
|
||||
let backendContext = this.appConfigService.getParamValue(
|
||||
LogOutComponent.BACKEND_CONTEXT);
|
||||
|
||||
if (backendUrl) {
|
||||
this.formAction = `${backendUrl}${LogOutComponent.LOGOUT_URL_POSTFIX}`;
|
||||
}
|
||||
else if (backendContext) {
|
||||
this.formAction = `/${backendContext}${LogOutComponent.LOGOUT_URL_POSTFIX}`;
|
||||
}
|
||||
}
|
||||
|
||||
ngDoCheck(): void {
|
||||
this.csrfValue = this.tokenExtractor.getToken();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.csrfValue = this.tokenExtractor.getToken();
|
||||
let isAuth = this.getIsAuth();
|
||||
if (isAuth) {
|
||||
Promise.all([
|
||||
|
|
@ -27,12 +51,6 @@ export class LogOutComponent implements OnInit{
|
|||
}
|
||||
}
|
||||
|
||||
logout(): Promise<any> {
|
||||
return this.httpClient.post<string>('esia/logout', {}, { responseType: 'text' as 'json' }).toPromise().then(url => {
|
||||
window.open(url, "_self");
|
||||
});
|
||||
}
|
||||
|
||||
public getUserFullname(): string {
|
||||
return this.userFullname;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue