mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
[ACA-969] Login - redirect when user is authenticated (#131)
This commit is contained in:
parent
9d1a3930e9
commit
aff0408db6
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { Location } from '@angular/common';
|
||||||
import { TestBed, async } from '@angular/core/testing';
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
import { CoreModule, AuthenticationService, UserPreferencesService } from '@alfresco/adf-core';
|
import { CoreModule, AuthenticationService, UserPreferencesService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ describe('LoginComponent', () => {
|
|||||||
let router;
|
let router;
|
||||||
let userPreference;
|
let userPreference;
|
||||||
let auth;
|
let auth;
|
||||||
|
let location;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -45,6 +47,9 @@ describe('LoginComponent', () => {
|
|||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
LoginComponent
|
LoginComponent
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
Location
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,6 +57,7 @@ describe('LoginComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
router = TestBed.get(Router);
|
router = TestBed.get(Router);
|
||||||
|
location = TestBed.get(Location);
|
||||||
auth = TestBed.get(AuthenticationService);
|
auth = TestBed.get(AuthenticationService);
|
||||||
userPreference = TestBed.get(UserPreferencesService);
|
userPreference = TestBed.get(UserPreferencesService);
|
||||||
}));
|
}));
|
||||||
@ -60,6 +66,7 @@ describe('LoginComponent', () => {
|
|||||||
spyOn(userPreference, 'setStoragePrefix');
|
spyOn(userPreference, 'setStoragePrefix');
|
||||||
spyOn(router, 'navigateByUrl');
|
spyOn(router, 'navigateByUrl');
|
||||||
spyOn(auth, 'getRedirectUrl').and.returnValue('/some-url');
|
spyOn(auth, 'getRedirectUrl').and.returnValue('/some-url');
|
||||||
|
spyOn(location, 'forward');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('OnInit()', () => {
|
describe('OnInit()', () => {
|
||||||
@ -67,14 +74,14 @@ describe('LoginComponent', () => {
|
|||||||
spyOn(auth, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(auth, 'isEcmLoggedIn').and.returnValue(false);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(router.navigateByUrl).not.toHaveBeenCalled();
|
expect(location.forward).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect when user is logged in', () => {
|
it('should redirect when user is logged in', () => {
|
||||||
spyOn(auth, 'isEcmLoggedIn').and.returnValue(true);
|
spyOn(auth, 'isEcmLoggedIn').and.returnValue(true);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/some-url');
|
expect(location.forward).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { Location } from '@angular/common';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { AuthenticationService, UserPreferencesService } from '@alfresco/adf-core';
|
import { AuthenticationService, UserPreferencesService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
@ -33,13 +34,14 @@ import { AuthenticationService, UserPreferencesService } from '@alfresco/adf-cor
|
|||||||
export class LoginComponent implements OnInit {
|
export class LoginComponent implements OnInit {
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
|
private location: Location,
|
||||||
private auth: AuthenticationService,
|
private auth: AuthenticationService,
|
||||||
private userPreferences: UserPreferencesService
|
private userPreferences: UserPreferencesService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.auth.isEcmLoggedIn()) {
|
if (this.auth.isEcmLoggedIn()) {
|
||||||
this.router.navigateByUrl(this.auth.getRedirectUrl() || '');
|
this.location.forward();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user