diff --git a/projects/dotcms-js/src/lib/core/login.service.ts b/projects/dotcms-js/src/lib/core/login.service.ts index a4d7210632..3eade6c0cf 100644 --- a/projects/dotcms-js/src/lib/core/login.service.ts +++ b/projects/dotcms-js/src/lib/core/login.service.ts @@ -4,7 +4,6 @@ import { CoreWebService } from './core-web.service'; import { Injectable } from '@angular/core'; import { Observable, Subject, of } from 'rxjs'; -import { Router } from '@angular/router'; import { LoggerService } from './logger.service'; import { HttpCode } from './util/http-code'; import { pluck, tap, map } from 'rxjs/operators'; @@ -18,6 +17,8 @@ export interface DotLoginParams { backEndLogin: boolean; } +export const LOGOUT_URL = '/dotAdmin/logout'; + /** * This Service get the server configuration to display in the login component * and execute the login and forgot password routines @@ -33,7 +34,6 @@ export class LoginService { private urls: any; constructor( - private router: Router, private coreWebService: CoreWebService, private dotcmsEventsService: DotcmsEventsService, private loggerService: LoggerService @@ -59,7 +59,7 @@ export class LoginService { this.loggerService.debug('User Logged In Date: ', this.auth.user.loggedInDate); // if the destroyed event happens after the logged in date, so proceed! if (!this.auth.user.loggedInDate || this.isLogoutAfterLastLogin(date)) { - this.logOutUser().subscribe(() => {}); + this.logOutUser(); } }); } @@ -215,7 +215,9 @@ export class LoginService { this.setAuth(auth); this.coreWebService .subscribeToHttpError(HttpCode.UNAUTHORIZED) - .subscribe(() => this.logOutUser().subscribe(() => {})); + .subscribe(() => { + this.logOutUser(); + }); return response.entity; }) ); @@ -243,36 +245,6 @@ export class LoginService { ); } - /** - * Call the logout rest api - * @returns Observable<any> - */ - public logOutUser(): Observable<any> { - return this.coreWebService - .requestView({ - url: this.urls.logout - }) - .pipe( - map((_response) => { - const nullAuth = { - loginAsUser: null, - user: null, - isLoginAs: false - }; - - this.loggerService.debug('Processing the logOutUser'); - this.setAuth(nullAuth); - - // on logout close the websocket - this.dotcmsEventsService.destroy(); - - this.loggerService.debug('Navigating to Public Login'); - - this.router.navigate(['/public/login']); - }) - ); - } - /** * Executes the call to the recover passwrod rest api * @param email User email address @@ -321,8 +293,7 @@ export class LoginService { private isLogoutAfterLastLogin(date): boolean { return ( - this.auth.user && - this.auth.user.loggedInDate && + this.auth?.user?.loggedInDate && date && Number(date) > Number(this.auth.user.loggedInDate) ); @@ -344,16 +315,12 @@ export class LoginService { } /** - * Request and store the login as _auth list. + * Call the logout rest api + * @returns Observable<any> */ - // private loadLoginAsUsersList(includeNUsers: boolean, filter: string): Observable<any> { - // return this.coreWebService - // .requestView({ - // url: `${this.urls - // .loginAsUserList}?includeUsersCount=${includeNUsers}&filter=${filter}` - // }) - // .pluck('entity'); - // } + private logOutUser(): void { + window.location.href = LOGOUT_URL; + } } export interface User { diff --git a/src/app/api/services/dot-router/dot-router.service.ts b/src/app/api/services/dot-router/dot-router.service.ts index 8cd86b1c9a..db16c784db 100644 --- a/src/app/api/services/dot-router/dot-router.service.ts +++ b/src/app/api/services/dot-router/dot-router.service.ts @@ -5,6 +5,7 @@ import { PortletNav } from '@models/navigation'; import { Subject } from 'rxjs'; import { DotAppsSites } from '@shared/models/dot-apps/dot-apps.model'; import { NavigationExtras } from '@angular/router'; +import { LOGOUT_URL } from 'dotcms-js'; @Injectable() export class DotRouterService { @@ -116,7 +117,7 @@ export class DotRouterService { * @memberof DotRouterService */ doLogOut(): void { - window.location.href = '/dotAdmin/logout'; + window.location.href = LOGOUT_URL; } /** diff --git a/src/app/view/components/dot-toolbar/components/dot-my-account/dot-my-account.component.spec.ts b/src/app/view/components/dot-toolbar/components/dot-my-account/dot-my-account.component.spec.ts index ae04ac61a6..fb7a3f231b 100644 --- a/src/app/view/components/dot-toolbar/components/dot-my-account/dot-my-account.component.spec.ts +++ b/src/app/view/components/dot-toolbar/components/dot-my-account/dot-my-account.component.spec.ts @@ -246,7 +246,6 @@ describe('DotMyAccountComponent', () => { spyOn<any>(accountService, 'updateUser').and.returnValue( of({ entity: { reauthenticate: true } }) ); - spyOn(loginService, 'logOutUser').and.returnValue(of({})); spyOn(comp.close, 'emit'); const user = { diff --git a/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.html b/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.html index 9063b42d3d..3e7c5897ba 100644 --- a/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.html +++ b/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.html @@ -53,7 +53,7 @@ <h5 class="toolbar-user__user-name" id="dot-toolbar-user-name"> </li> <li class="user-menu__item"> <a - href="/dotAdmin/logout" + [href]="logoutUrl" *ngIf="!auth.loginAsUser" id="dot-toolbar-user-link-logout" [textContent]="'Logout' | dm" diff --git a/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.ts b/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.ts index 91f1a0f509..65b0e2db0a 100644 --- a/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.ts +++ b/src/app/view/components/dot-toolbar/components/dot-toolbar-user/dot-toolbar-user.component.ts @@ -1,7 +1,7 @@ import { Component, ViewChild, OnInit, Inject } from '@angular/core'; import { DotDropdownComponent } from '@components/_common/dot-dropdown-component/dot-dropdown.component'; import { IframeOverlayService } from '../../../_common/iframe/service/iframe-overlay.service'; -import { LoginService, Auth, LoggerService } from 'dotcms-js'; +import { LoginService, Auth, LoggerService, LOGOUT_URL } from 'dotcms-js'; import { LOCATION_TOKEN } from 'src/app/providers'; import { DotNavigationService } from '@components/dot-navigation/services/dot-navigation.service'; import { DotRouterService } from '@services/dot-router/dot-router.service'; @@ -18,6 +18,8 @@ export class DotToolbarUserComponent implements OnInit { showLoginAs = false; showMyAccount = false; + logoutUrl = LOGOUT_URL; + constructor( @Inject(LOCATION_TOKEN) private location: Location, private loggerService: LoggerService, diff --git a/src/app/view/components/login/dot-logout-container-component/dot-log-out-container.ts b/src/app/view/components/login/dot-logout-container-component/dot-log-out-container.ts index b4ddbf0c27..9ae50b7097 100644 --- a/src/app/view/components/login/dot-logout-container-component/dot-log-out-container.ts +++ b/src/app/view/components/login/dot-logout-container-component/dot-log-out-container.ts @@ -1,5 +1,5 @@ import { Component, ViewEncapsulation } from '@angular/core'; -import { LoginService } from 'dotcms-js'; +import { LoginService, LOGOUT_URL } from 'dotcms-js'; import { DotRouterService } from '../../../../api/services/dot-router/dot-router.service'; import { take } from 'rxjs/operators'; @@ -12,7 +12,7 @@ export class DotLogOutContainerComponent { constructor(loginService: LoginService, router: DotRouterService) { loginService.isLogin$.pipe(take(1)).subscribe((isLogin) => { if (isLogin) { - window.location.href = '/dotAdmin/logout'; + window.location.href = LOGOUT_URL; } else { router.goToLogin(); }