mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-578] Remember me functionality (#1962)
* Remember me functionality * Happy pack to ng2-components' package.json * Build fix
This commit is contained in:
committed by
Eugenio Romano
parent
75778ab968
commit
fb4af7f846
@@ -29,6 +29,7 @@ import {
|
|||||||
AlfrescoContentService,
|
AlfrescoContentService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
CookieService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoTranslateLoader,
|
AlfrescoTranslateLoader,
|
||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
@@ -69,6 +70,7 @@ export const ALFRESCO_CORE_PROVIDERS: any[] = [
|
|||||||
AlfrescoContentService,
|
AlfrescoContentService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
CookieService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoTranslateLoader,
|
AlfrescoTranslateLoader,
|
||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
|
@@ -0,0 +1,27 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class CookieServiceMock {
|
||||||
|
|
||||||
|
getItem(key: string): string | null {
|
||||||
|
return this[key] && this[key].data || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
setItem(key: string, data: string, expiration: Date | null, path: string | null): void {
|
||||||
|
this[key] = {data, expiration, path};
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,8 @@ import { AlfrescoSettingsService } from './alfresco-settings.service';
|
|||||||
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
|
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
|
||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
|
import { CookieService } from './cookie.service';
|
||||||
|
import { CookieServiceMock } from './../assets/cookie.service.mock';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
@@ -29,6 +31,7 @@ describe('AlfrescoAuthenticationService', () => {
|
|||||||
let authService: AlfrescoAuthenticationService;
|
let authService: AlfrescoAuthenticationService;
|
||||||
let settingsService: AlfrescoSettingsService;
|
let settingsService: AlfrescoSettingsService;
|
||||||
let storage: StorageService;
|
let storage: StorageService;
|
||||||
|
let cookie: CookieService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
injector = ReflectiveInjector.resolveAndCreate([
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
@@ -36,11 +39,13 @@ describe('AlfrescoAuthenticationService', () => {
|
|||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService
|
LogService
|
||||||
]);
|
]);
|
||||||
|
|
||||||
authService = injector.get(AlfrescoAuthenticationService);
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
settingsService = injector.get(AlfrescoSettingsService);
|
settingsService = injector.get(AlfrescoSettingsService);
|
||||||
|
cookie = injector.get(CookieService);
|
||||||
storage = injector.get(StorageService);
|
storage = injector.get(StorageService);
|
||||||
storage.clear();
|
storage.clear();
|
||||||
|
|
||||||
@@ -51,6 +56,64 @@ describe('AlfrescoAuthenticationService', () => {
|
|||||||
jasmine.Ajax.uninstall();
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('remembe me', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
settingsService.setProviders('ECM');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should save the remember me cookie as a session cookie after successful login', (done) => {
|
||||||
|
authService.login('fake-username', 'fake-password', false).subscribe(() => {
|
||||||
|
expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined();
|
||||||
|
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).toBeNull();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 201,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should save the remember me cookie as a persistent cookie after successful login', (done) => {
|
||||||
|
authService.login('fake-username', 'fake-password', true).subscribe(() => {
|
||||||
|
expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined();
|
||||||
|
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).not.toBeNull();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 201,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not save the remember me cookie after failed login', (done) => {
|
||||||
|
authService.login('fake-username', 'fake-password').subscribe(
|
||||||
|
(res) => {},
|
||||||
|
(err: any) => {
|
||||||
|
expect(cookie['ALFRESCO_REMEMBER_ME']).toBeUndefined();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 403,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify({
|
||||||
|
'error': {
|
||||||
|
'errorKey': 'Login failed',
|
||||||
|
'statusCode': 403,
|
||||||
|
'briefSummary': '05150009 Login failed',
|
||||||
|
'stackTrace': 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||||
|
'descriptionURL': 'https://api-explorer.alfresco.com'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when the setting is ECM', () => {
|
describe('when the setting is ECM', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -19,23 +19,29 @@ import { Injectable } from '@angular/core';
|
|||||||
import { Observable, Subject } from 'rxjs/Rx';
|
import { Observable, Subject } from 'rxjs/Rx';
|
||||||
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
import { AlfrescoSettingsService } from './alfresco-settings.service';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
|
import { CookieService } from './cookie.service';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
|
|
||||||
|
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
|
||||||
|
const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30 ;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlfrescoAuthenticationService {
|
export class AlfrescoAuthenticationService {
|
||||||
|
|
||||||
onLogin: Subject<any> = new Subject<any>();
|
onLogin: Subject<any> = new Subject<any>();
|
||||||
onLogout: Subject<any> = new Subject<any>();
|
onLogout: Subject<any> = new Subject<any>();
|
||||||
|
|
||||||
constructor(private settingsService: AlfrescoSettingsService,
|
constructor(
|
||||||
public alfrescoApi: AlfrescoApiService,
|
private settingsService: AlfrescoSettingsService,
|
||||||
private storage: StorageService,
|
public alfrescoApi: AlfrescoApiService,
|
||||||
private logService: LogService) {
|
private storage: StorageService,
|
||||||
|
private cookie: CookieService,
|
||||||
|
private logService: LogService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method return tru if the user is logged in
|
* The method return true if the user is logged in
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isLoggedIn(): boolean {
|
isLoggedIn(): boolean {
|
||||||
@@ -48,17 +54,43 @@ export class AlfrescoAuthenticationService {
|
|||||||
* @param password
|
* @param password
|
||||||
* @returns {Observable<R>|Observable<T>}
|
* @returns {Observable<R>|Observable<T>}
|
||||||
*/
|
*/
|
||||||
login(username: string, password: string): Observable<{ type: string, ticket: any }> {
|
login(username: string, password: string, rememberMe: boolean = false): Observable<{ type: string, ticket: any }> {
|
||||||
this.removeTicket();
|
this.removeTicket();
|
||||||
return Observable.fromPromise(this.callApiLogin(username, password))
|
return Observable.fromPromise(this.callApiLogin(username, password))
|
||||||
.map((response: any) => {
|
.map((response: any) => {
|
||||||
|
this.saveRememberMeCookie(rememberMe);
|
||||||
this.saveTickets();
|
this.saveTickets();
|
||||||
this.onLogin.next(response);
|
this.onLogin.next(response);
|
||||||
return {type: this.settingsService.getProviders(), ticket: response};
|
return { type: this.settingsService.getProviders(), ticket: response };
|
||||||
})
|
})
|
||||||
.catch(err => this.handleError(err));
|
.catch(err => this.handleError(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method save the "remember me" cookie as a long life cookie or a session cookie
|
||||||
|
* depending on the given paramter
|
||||||
|
*/
|
||||||
|
private saveRememberMeCookie(rememberMe: boolean): void {
|
||||||
|
let expiration = null;
|
||||||
|
|
||||||
|
if (rememberMe) {
|
||||||
|
expiration = new Date();
|
||||||
|
const time = expiration.getTime();
|
||||||
|
const expireTime = time + REMEMBER_ME_UNTIL;
|
||||||
|
expiration.setTime(expireTime);
|
||||||
|
}
|
||||||
|
this.cookie.setItem(REMEMBER_ME_COOKIE_KEY, '1', expiration, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method retrieve whether the "remember me" cookie was set or not
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
private isRememberMeSet(): boolean {
|
||||||
|
return (this.cookie.getItem(REMEMBER_ME_COOKIE_KEY) === null) ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the alfresco Api with user and password end call the login method
|
* Initialize the alfresco Api with user and password end call the login method
|
||||||
* @param username
|
* @param username
|
||||||
@@ -130,7 +162,7 @@ export class AlfrescoAuthenticationService {
|
|||||||
/**
|
/**
|
||||||
* The method save the ECM and BPM ticket in the Storage
|
* The method save the ECM and BPM ticket in the Storage
|
||||||
*/
|
*/
|
||||||
saveTickets() {
|
saveTickets(): void {
|
||||||
this.saveTicketEcm();
|
this.saveTicketEcm();
|
||||||
this.saveTicketBpm();
|
this.saveTicketBpm();
|
||||||
}
|
}
|
||||||
@@ -155,16 +187,20 @@ export class AlfrescoAuthenticationService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The method return true if user is logged in on ecm provider
|
* The method return true if user is logged in on ecm provider
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isEcmLoggedIn() {
|
isEcmLoggedIn(): boolean {
|
||||||
return this.alfrescoApi.getInstance().ecmAuth && !!this.alfrescoApi.getInstance().ecmAuth.isLoggedIn();
|
return this.isRememberMeSet() && this.alfrescoApi.getInstance().ecmAuth && !!this.alfrescoApi.getInstance().ecmAuth.isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method return true if user is logged in on bpm provider
|
* The method return true if user is logged in on bpm provider
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isBpmLoggedIn() {
|
isBpmLoggedIn(): boolean {
|
||||||
return this.alfrescoApi.getInstance().bpmAuth && !!this.alfrescoApi.getInstance().bpmAuth.isLoggedIn();
|
return this.isRememberMeSet() && this.alfrescoApi.getInstance().bpmAuth && !!this.alfrescoApi.getInstance().bpmAuth.isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -21,6 +21,8 @@ import { AlfrescoAuthenticationService } from './alfresco-authentication.service
|
|||||||
import { AlfrescoContentService } from './alfresco-content.service';
|
import { AlfrescoContentService } from './alfresco-content.service';
|
||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
|
import { CookieService } from './cookie.service';
|
||||||
|
import { CookieServiceMock } from './../assets/cookie.service.mock';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
@@ -42,6 +44,7 @@ describe('AlfrescoContentService', () => {
|
|||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService
|
LogService
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -20,6 +20,8 @@ import { AlfrescoAuthenticationService } from './alfresco-authentication.service
|
|||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
|
import { CookieService } from './cookie.service';
|
||||||
|
import { CookieServiceMock } from './../assets/cookie.service.mock';
|
||||||
import { AuthGuardBpm } from './auth-guard-bpm.service';
|
import { AuthGuardBpm } from './auth-guard-bpm.service';
|
||||||
import { Router} from '@angular/router';
|
import { Router} from '@angular/router';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
@@ -34,6 +36,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService],
|
LogService],
|
||||||
imports: [RouterTestingModule]
|
imports: [RouterTestingModule]
|
||||||
});
|
});
|
||||||
|
@@ -19,6 +19,8 @@ import { AlfrescoSettingsService } from './alfresco-settings.service';
|
|||||||
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
|
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
|
||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
|
import { CookieService } from './cookie.service';
|
||||||
|
import { CookieServiceMock } from './../assets/cookie.service.mock';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
import { AuthGuardEcm } from './auth-guard-ecm.service';
|
import { AuthGuardEcm } from './auth-guard-ecm.service';
|
||||||
import { Router} from '@angular/router';
|
import { Router} from '@angular/router';
|
||||||
@@ -34,6 +36,7 @@ describe('AuthGuardService ECM', () => {
|
|||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService],
|
LogService],
|
||||||
imports: [RouterTestingModule]
|
imports: [RouterTestingModule]
|
||||||
});
|
});
|
||||||
|
@@ -19,6 +19,8 @@ import { AlfrescoSettingsService } from './alfresco-settings.service';
|
|||||||
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
|
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
|
||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
import { StorageService } from './storage.service';
|
import { StorageService } from './storage.service';
|
||||||
|
import { CookieService } from './cookie.service';
|
||||||
|
import { CookieServiceMock } from './../assets/cookie.service.mock';
|
||||||
import { LogService } from './log.service';
|
import { LogService } from './log.service';
|
||||||
import { AuthGuard } from './auth-guard.service';
|
import { AuthGuard } from './auth-guard.service';
|
||||||
import { Router} from '@angular/router';
|
import { Router} from '@angular/router';
|
||||||
@@ -34,6 +36,7 @@ describe('AuthGuardService', () => {
|
|||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService],
|
LogService],
|
||||||
imports: [RouterTestingModule]
|
imports: [RouterTestingModule]
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,48 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CookieService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve cookie by key.
|
||||||
|
*
|
||||||
|
* @returns {string | null}
|
||||||
|
*/
|
||||||
|
getItem(key: string): string | null {
|
||||||
|
const regexp = new RegExp('(?:' + key + '|;\s*' + key + ')=(.*?)(?:;|$)', 'g');
|
||||||
|
const result = regexp.exec(document.cookie);
|
||||||
|
return (result === null) ? null : result[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a cookie.
|
||||||
|
* @param key
|
||||||
|
* @param data
|
||||||
|
* @param expiration
|
||||||
|
* @param path
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
setItem(key: string, data: string, expiration: Date | null, path: string | null): void {
|
||||||
|
document.cookie = `${key}=${data}` +
|
||||||
|
(expiration ? ';expires=' + expiration.toUTCString() : '') +
|
||||||
|
(path ? `;path=${path}` : ';path=/');
|
||||||
|
}
|
||||||
|
}
|
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
export * from './content.service';
|
export * from './content.service';
|
||||||
export * from './storage.service';
|
export * from './storage.service';
|
||||||
|
export * from './cookie.service';
|
||||||
export * from './alfresco-api.service';
|
export * from './alfresco-api.service';
|
||||||
export * from './alfresco-settings.service';
|
export * from './alfresco-settings.service';
|
||||||
export * from './alfresco-content.service';
|
export * from './alfresco-content.service';
|
||||||
|
@@ -15,8 +15,18 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiService, StorageService, AlfrescoContentService, LogService, LogServiceMock } from 'ng2-alfresco-core';
|
import {
|
||||||
|
AlfrescoSettingsService,
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoApiService,
|
||||||
|
StorageService,
|
||||||
|
CookieService,
|
||||||
|
AlfrescoContentService,
|
||||||
|
LogService,
|
||||||
|
LogServiceMock
|
||||||
|
} from 'ng2-alfresco-core';
|
||||||
import { FileNode } from '../assets/document-library.model.mock';
|
import { FileNode } from '../assets/document-library.model.mock';
|
||||||
|
import { CookieServiceMock } from '../../../ng2-alfresco-core/src/assets/cookie.service.mock';
|
||||||
import { ReflectiveInjector } from '@angular/core';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
import { DocumentListService } from './document-list.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
|
|
||||||
@@ -100,6 +110,7 @@ describe('DocumentListService', () => {
|
|||||||
AlfrescoContentService,
|
AlfrescoContentService,
|
||||||
DocumentListService,
|
DocumentListService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
{ provide: LogService, useClass: LogServiceMock }
|
{ provide: LogService, useClass: LogServiceMock }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -82,7 +82,7 @@
|
|||||||
|
|
||||||
</button>
|
</button>
|
||||||
<div *ngIf="showRememberMe" class="adf-login__remember-me" id ="login-remember">
|
<div *ngIf="showRememberMe" class="adf-login__remember-me" id ="login-remember">
|
||||||
<md-checkbox class="rememberme-cb" checked="true">{{ 'LOGIN.LABEL.REMEMBER' | translate }}</md-checkbox>
|
<md-checkbox class="rememberme-cb" [checked]="rememberMe" (change)="rememberMe = !rememberMe">{{ 'LOGIN.LABEL.REMEMBER' | translate }}</md-checkbox>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border mdl-card__link">
|
<div class="mdl-card__actions mdl-card--border mdl-card__link">
|
||||||
|
@@ -22,7 +22,7 @@ import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
|||||||
import { AlfrescoLoginComponent } from './alfresco-login.component';
|
import { AlfrescoLoginComponent } from './alfresco-login.component';
|
||||||
import { AuthenticationMock } from './../assets/authentication.service.mock';
|
import { AuthenticationMock } from './../assets/authentication.service.mock';
|
||||||
import { TranslationMock } from './../assets/translation.service.mock';
|
import { TranslationMock } from './../assets/translation.service.mock';
|
||||||
import { MdInputModule } from '@angular/material';
|
import { MdInputModule, MdCheckboxModule } from '@angular/material';
|
||||||
|
|
||||||
describe('AlfrescoLogin', () => {
|
describe('AlfrescoLogin', () => {
|
||||||
let component: AlfrescoLoginComponent;
|
let component: AlfrescoLoginComponent;
|
||||||
@@ -39,6 +39,7 @@ describe('AlfrescoLogin', () => {
|
|||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
MdInputModule,
|
MdInputModule,
|
||||||
|
MdCheckboxModule,
|
||||||
CoreModule.forRoot()
|
CoreModule.forRoot()
|
||||||
],
|
],
|
||||||
declarations: [AlfrescoLoginComponent],
|
declarations: [AlfrescoLoginComponent],
|
||||||
@@ -64,24 +65,24 @@ describe('AlfrescoLogin', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function loginWithCredentials(username, password) {
|
||||||
|
component.providers = 'ECM';
|
||||||
|
usernameInput.value = username;
|
||||||
|
passwordInput.value = password;
|
||||||
|
|
||||||
|
usernameInput.dispatchEvent(new Event('input'));
|
||||||
|
passwordInput.dispatchEvent(new Event('input'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
element.querySelector('button').click();
|
||||||
|
fixture.detectChanges();
|
||||||
|
}
|
||||||
|
|
||||||
describe('Login button', () => {
|
describe('Login button', () => {
|
||||||
|
|
||||||
const getLoginButton = () => element.querySelector('#login-button');
|
const getLoginButton = () => element.querySelector('#login-button');
|
||||||
const getLoginButtonText = () => element.querySelector('#login-button span.login-button-label').innerText;
|
const getLoginButtonText = () => element.querySelector('#login-button span.login-button-label').innerText;
|
||||||
|
|
||||||
function loginWithCredentials(username, password) {
|
|
||||||
component.providers = 'ECM';
|
|
||||||
usernameInput.value = username;
|
|
||||||
passwordInput.value = password;
|
|
||||||
|
|
||||||
usernameInput.dispatchEvent(new Event('input'));
|
|
||||||
passwordInput.dispatchEvent(new Event('input'));
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
element.querySelector('button').click();
|
|
||||||
fixture.detectChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
it('should be rendered with the proper key by default', () => {
|
it('should be rendered with the proper key by default', () => {
|
||||||
expect(getLoginButton()).not.toBeNull();
|
expect(getLoginButton()).not.toBeNull();
|
||||||
expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.LOGIN');
|
expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.LOGIN');
|
||||||
@@ -110,6 +111,35 @@ describe('AlfrescoLogin', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Remember me', () => {
|
||||||
|
|
||||||
|
it('should be checked by default', () => {
|
||||||
|
expect(element.querySelector('.rememberme-cb input[type="checkbox"]').checked).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the component\'s rememberMe property properly', () => {
|
||||||
|
element.querySelector('.rememberme-cb').dispatchEvent(new Event('change'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.rememberMe).toBe(false);
|
||||||
|
|
||||||
|
element.querySelector('.rememberme-cb').dispatchEvent(new Event('change'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.rememberMe).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be taken into consideration during login attempt', () => {
|
||||||
|
const authService = TestBed.get(AlfrescoAuthenticationService);
|
||||||
|
spyOn(authService, 'login').and.returnValue({ subscribe: () => { } });
|
||||||
|
component.rememberMe = false;
|
||||||
|
|
||||||
|
loginWithCredentials('fake-username', 'fake-password');
|
||||||
|
|
||||||
|
expect(authService.login).toHaveBeenCalledWith('fake-username', 'fake-password', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should render Login form with all the keys to be translated', () => {
|
it('should render Login form with all the keys to be translated', () => {
|
||||||
expect(element.querySelector('[for="username"]')).toBeDefined();
|
expect(element.querySelector('[for="username"]')).toBeDefined();
|
||||||
expect(element.querySelector('[for="username"]').innerText).toEqual('LOGIN.LABEL.USERNAME');
|
expect(element.querySelector('[for="username"]').innerText).toEqual('LOGIN.LABEL.USERNAME');
|
||||||
|
@@ -81,6 +81,7 @@ export class AlfrescoLoginComponent implements OnInit {
|
|||||||
success: boolean = false;
|
success: boolean = false;
|
||||||
actualLoginStep: any = LoginSteps.Landing;
|
actualLoginStep: any = LoginSteps.Landing;
|
||||||
LoginSteps: any = LoginSteps;
|
LoginSteps: any = LoginSteps;
|
||||||
|
rememberMe: boolean = true;
|
||||||
formError: { [id: string]: string };
|
formError: { [id: string]: string };
|
||||||
minLength: number = 2;
|
minLength: number = 2;
|
||||||
footerTemplate: TemplateRef<any>;
|
footerTemplate: TemplateRef<any>;
|
||||||
@@ -172,7 +173,7 @@ export class AlfrescoLoginComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
private performLogin(values: any) {
|
private performLogin(values: any) {
|
||||||
this.actualLoginStep = LoginSteps.Checking;
|
this.actualLoginStep = LoginSteps.Checking;
|
||||||
this.authService.login(values.username, values.password)
|
this.authService.login(values.username, values.password, this.rememberMe)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(token: any) => {
|
(token: any) => {
|
||||||
this.actualLoginStep = LoginSteps.Welcome;
|
this.actualLoginStep = LoginSteps.Welcome;
|
||||||
|
@@ -29,8 +29,10 @@ import {
|
|||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
CookieService,
|
||||||
LogService
|
LogService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
|
import { CookieServiceMock } from './../../../ng2-alfresco-core/src/assets/cookie.service.mock';
|
||||||
import { DocumentListModule } from 'ng2-alfresco-documentlist';
|
import { DocumentListModule } from 'ng2-alfresco-documentlist';
|
||||||
|
|
||||||
describe('AlfrescoSearchComponent', () => {
|
describe('AlfrescoSearchComponent', () => {
|
||||||
@@ -148,6 +150,7 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService,
|
LogService,
|
||||||
{provide: ActivatedRoute, useValue: {params: Observable.from([{}])}}
|
{provide: ActivatedRoute, useValue: {params: Observable.from([{}])}}
|
||||||
]);
|
]);
|
||||||
|
@@ -17,7 +17,15 @@
|
|||||||
|
|
||||||
import { ReflectiveInjector } from '@angular/core';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
import { AlfrescoSearchService } from './alfresco-search.service';
|
import { AlfrescoSearchService } from './alfresco-search.service';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService, StorageService, LogService } from 'ng2-alfresco-core';
|
import {
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoSettingsService,
|
||||||
|
AlfrescoApiService,
|
||||||
|
StorageService,
|
||||||
|
CookieService,
|
||||||
|
LogService
|
||||||
|
} from 'ng2-alfresco-core';
|
||||||
|
import { CookieServiceMock } from './../../../ng2-alfresco-core/src/assets/cookie.service.mock';
|
||||||
import { fakeApi, fakeSearch, fakeError } from '../assets/alfresco-search.service.mock';
|
import { fakeApi, fakeSearch, fakeError } from '../assets/alfresco-search.service.mock';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
@@ -35,6 +43,7 @@ describe('AlfrescoSearchService', () => {
|
|||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService
|
LogService
|
||||||
]);
|
]);
|
||||||
service = injector.get(AlfrescoSearchService);
|
service = injector.get(AlfrescoSearchService);
|
||||||
|
@@ -17,7 +17,16 @@
|
|||||||
|
|
||||||
import { ReflectiveInjector } from '@angular/core';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
import { AlfrescoThumbnailService } from './alfresco-thumbnail.service';
|
import { AlfrescoThumbnailService } from './alfresco-thumbnail.service';
|
||||||
import { AlfrescoApiService, AlfrescoAuthenticationService, AlfrescoContentService, AlfrescoSettingsService, StorageService, LogService } from 'ng2-alfresco-core';
|
import {
|
||||||
|
AlfrescoApiService,
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoContentService,
|
||||||
|
AlfrescoSettingsService,
|
||||||
|
StorageService,
|
||||||
|
CookieService,
|
||||||
|
LogService
|
||||||
|
} from 'ng2-alfresco-core';
|
||||||
|
import { CookieServiceMock } from './../../../ng2-alfresco-core/src/assets/cookie.service.mock';
|
||||||
|
|
||||||
describe('AlfrescoThumbnailService', () => {
|
describe('AlfrescoThumbnailService', () => {
|
||||||
|
|
||||||
@@ -32,6 +41,7 @@ describe('AlfrescoThumbnailService', () => {
|
|||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoThumbnailService,
|
AlfrescoThumbnailService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService
|
LogService
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@@ -24,8 +24,10 @@ import {
|
|||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
CookieService,
|
||||||
LogService
|
LogService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
|
import { CookieServiceMock } from './../../../ng2-alfresco-core/src/assets/cookie.service.mock';
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('EcmUserService', () => {
|
describe('EcmUserService', () => {
|
||||||
@@ -43,6 +45,7 @@ describe('EcmUserService', () => {
|
|||||||
AlfrescoContentService,
|
AlfrescoContentService,
|
||||||
EcmUserService,
|
EcmUserService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
LogService
|
LogService
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@@ -108,6 +108,7 @@
|
|||||||
"istanbul-instrumenter-loader": "0.2.0",
|
"istanbul-instrumenter-loader": "0.2.0",
|
||||||
"jasmine-ajax": "^3.2.0",
|
"jasmine-ajax": "^3.2.0",
|
||||||
"jasmine-core": "2.4.1",
|
"jasmine-core": "2.4.1",
|
||||||
|
"happypack": "3.0.0",
|
||||||
"karma": "^0.13.22",
|
"karma": "^0.13.22",
|
||||||
"karma-chrome-launcher": "~1.0.1",
|
"karma-chrome-launcher": "~1.0.1",
|
||||||
"karma-coverage": "^1.1.1",
|
"karma-coverage": "^1.1.1",
|
||||||
|
Reference in New Issue
Block a user