login enhancements (#343)

This commit is contained in:
Denys Vuika 2018-05-03 12:11:32 +01:00 committed by Cilibiu Bogdan
parent 753f0bfb46
commit fa14bffc1c
4 changed files with 15 additions and 44 deletions

View File

@ -2,7 +2,8 @@
"ecmHost": "http://{hostname}{:port}", "ecmHost": "http://{hostname}{:port}",
"application": { "application": {
"name": "Alfresco Example Content Application", "name": "Alfresco Example Content Application",
"logo": "assets/images/alfresco-logo-white.svg" "logo": "assets/images/alfresco-logo-white.svg",
"copyright": "© 2017 - 2018 Alfresco Software, Inc. All rights reserved."
}, },
"headerColor": "#2196F3", "headerColor": "#2196F3",
"languagePicker": false, "languagePicker": false,

View File

@ -1,7 +1,7 @@
<adf-login <adf-login
copyrightText="&#169; 2017 - 2018 Alfresco Software, Inc. All rights reserved." [copyrightText]="'application.copyright' | appConfig"
providers="ECM" providers="ECM"
successRoute="/personal-files"
[showRememberMe]="false" [showRememberMe]="false"
[showLoginActions]="false" [showLoginActions]="false">
(success)="onLoginSuccess($event)">
</adf-login> </adf-login>

View File

@ -29,7 +29,7 @@ import { Router } from '@angular/router';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { TestBed, async } from '@angular/core/testing'; import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { import {
AuthenticationService, UserPreferencesService, TranslationService, AuthenticationService, UserPreferencesService, TranslationService,
TranslationMock, AppConfigService, StorageService, AlfrescoApiService, TranslationMock, AppConfigService, StorageService, AlfrescoApiService,
@ -37,14 +37,14 @@ import {
} from '@alfresco/adf-core'; } from '@alfresco/adf-core';
import { LoginComponent } from './login.component'; import { LoginComponent } from './login.component';
import { AppConfigPipe } from '../../common/pipes/app-config.pipe';
describe('LoginComponent', () => { describe('LoginComponent', () => {
let component; let fixture: ComponentFixture<LoginComponent>;
let fixture; let router: Router;
let router; let userPreference: UserPreferencesService;
let userPreference; let auth: AuthenticationService;
let auth; let location: Location;
let location;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@ -54,7 +54,8 @@ describe('LoginComponent', () => {
RouterTestingModule RouterTestingModule
], ],
declarations: [ declarations: [
LoginComponent LoginComponent,
AppConfigPipe
], ],
providers: [ providers: [
{ provide: TranslationService, useClass: TranslationMock }, { provide: TranslationService, useClass: TranslationMock },
@ -71,7 +72,6 @@ describe('LoginComponent', () => {
}); });
fixture = TestBed.createComponent(LoginComponent); fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
router = TestBed.get(Router); router = TestBed.get(Router);
location = TestBed.get(Location); location = TestBed.get(Location);
@ -101,23 +101,4 @@ describe('LoginComponent', () => {
expect(location.forward).toHaveBeenCalled(); expect(location.forward).toHaveBeenCalled();
}); });
}); });
describe('onLoginSuccess()', () => {
beforeEach(() => {
spyOn(auth, 'isEcmLoggedIn').and.returnValue(false);
fixture.detectChanges();
});
it('should redirect on success', () => {
component.onLoginSuccess();
expect(router.navigateByUrl).toHaveBeenCalledWith('/personal-files');
});
it('should set user preference store prefix', () => {
component.onLoginSuccess({ username: 'bogus' });
expect(userPreference.setStoragePrefix).toHaveBeenCalledWith('bogus');
});
});
}); });

View File

@ -25,18 +25,15 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { Router } from '@angular/router'; import { AuthenticationService } from '@alfresco/adf-core';
import { AuthenticationService, UserPreferencesService } from '@alfresco/adf-core';
@Component({ @Component({
templateUrl: './login.component.html' templateUrl: './login.component.html'
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
constructor( constructor(
private router: Router,
private location: Location, private location: Location,
private auth: AuthenticationService, private auth: AuthenticationService,
private userPreferences: UserPreferencesService
) {} ) {}
ngOnInit() { ngOnInit() {
@ -44,12 +41,4 @@ export class LoginComponent implements OnInit {
this.location.forward(); this.location.forward();
} }
} }
onLoginSuccess(data) {
if (data && data.username) {
this.userPreferences.setStoragePrefix(data.username);
}
this.router.navigateByUrl('/personal-files');
}
} }