+
{
+describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture;
let debug: DebugElement;
@@ -523,11 +525,9 @@ describe('AlfrescoLogin', () => {
expect(component.error).toBe(false);
expect(component.success).toBe(true);
- expect(component.onSuccess.emit).toHaveBeenCalledWith({
- token: true,
- username: 'fake-username',
- password: 'fake-password'
- });
+ expect(component.onSuccess.emit).toHaveBeenCalledWith(
+ new LoginSuccessEvent({ type: 'type', ticket: 'ticket' }, 'fake-username', 'fake-password')
+ );
});
it('should emit onError event after the login has failed', () => {
@@ -553,7 +553,9 @@ describe('AlfrescoLogin', () => {
expect(component.success).toBe(false);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
- expect(component.onError.emit).toHaveBeenCalledWith('Fake server error');
+ expect(component.onError.emit).toHaveBeenCalledWith(
+ new LoginErrorEvent('Fake server error')
+ );
});
it('should render the password in clear when the toggleShowPassword is call', () => {
@@ -598,6 +600,6 @@ describe('AlfrescoLogin', () => {
expect(component.success).toBe(false);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS');
- expect(component.onError.emit).toHaveBeenCalledWith('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS');
+ expect(component.onError.emit).toHaveBeenCalledWith(new LoginErrorEvent('LOGIN.MESSAGES.LOGIN-ERROR-PROVIDERS'));
});
});
diff --git a/ng2-components/ng2-alfresco-login/src/components/login.component.ts b/ng2-components/ng2-alfresco-login/src/components/login.component.ts
index d77a1f6163..57b94688c9 100644
--- a/ng2-components/ng2-alfresco-login/src/components/login.component.ts
+++ b/ng2-components/ng2-alfresco-login/src/components/login.component.ts
@@ -19,7 +19,10 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output, TemplateRef
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoTranslationService, LogService } from 'ng2-alfresco-core';
-import { FormSubmitEvent } from '../models/form-submit-event.model';
+
+import { LoginErrorEvent } from '../models/login-error.event';
+import { LoginSubmitEvent } from '../models/login-submit.event';
+import { LoginSuccessEvent } from '../models/login-success.event';
declare var require: any;
@@ -30,7 +33,7 @@ enum LoginSteps {
}
@Component({
- selector: 'adf-login, alfresco-login',
+ selector: 'adf-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss'],
host: {'(blur)': 'onBlur($event)'},
@@ -74,13 +77,13 @@ export class LoginComponent implements OnInit {
successRoute: string = null;
@Output()
- onSuccess = new EventEmitter();
+ onSuccess = new EventEmitter();
@Output()
- onError = new EventEmitter();
+ onError = new EventEmitter();
@Output()
- executeSubmit: EventEmitter = new EventEmitter();
+ executeSubmit = new EventEmitter();
form: FormGroup;
error: boolean = false;
@@ -139,7 +142,7 @@ export class LoginComponent implements OnInit {
this.disableError();
- let args = new FormSubmitEvent(this.form);
+ const args = new LoginSubmitEvent(this.form);
this.executeSubmit.emit(args);
if (args.defaultPrevented) {
@@ -183,7 +186,7 @@ export class LoginComponent implements OnInit {
(token: any) => {
this.actualLoginStep = LoginSteps.Welcome;
this.success = true;
- this.onSuccess.emit({token: token, username: values.username, password: values.password});
+ this.onSuccess.emit(new LoginSuccessEvent(token, values.username, values.password));
if (this.successRoute) {
this.router.navigate([this.successRoute]);
}
@@ -192,7 +195,7 @@ export class LoginComponent implements OnInit {
this.actualLoginStep = LoginSteps.Landing;
this.displayErrorMessage(err);
this.enableError();
- this.onError.emit(err);
+ this.onError.emit(new LoginErrorEvent(err));
},
() => this.logService.info('Login done')
);
@@ -230,7 +233,7 @@ export class LoginComponent implements OnInit {
this.enableError();
let messageProviders: any;
messageProviders = this.translateService.get(this.errorMsg);
- this.onError.emit(messageProviders.value);
+ this.onError.emit(new LoginErrorEvent(messageProviders.value));
return false;
}
return true;
@@ -251,7 +254,7 @@ export class LoginComponent implements OnInit {
* @param ruleId - i.e. required | minlength | maxlength
* @param msg
*/
- public addCustomValidationError(field: string, ruleId: string, msg: string, params?: any) {
+ addCustomValidationError(field: string, ruleId: string, msg: string, params?: any) {
if (params) {
this.translateService.get(msg, params).subscribe((res: string) => {
this._message[field][ruleId] = res;
diff --git a/ng2-components/ng2-alfresco-login/src/models/login-error.event.ts b/ng2-components/ng2-alfresco-login/src/models/login-error.event.ts
new file mode 100644
index 0000000000..be2708bf24
--- /dev/null
+++ b/ng2-components/ng2-alfresco-login/src/models/login-error.event.ts
@@ -0,0 +1,20 @@
+/*!
+ * @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 LoginErrorEvent {
+ constructor(public err: any) {}
+}
diff --git a/ng2-components/ng2-alfresco-login/src/models/form-submit-event.model.ts b/ng2-components/ng2-alfresco-login/src/models/login-submit.event.ts
similarity index 96%
rename from ng2-components/ng2-alfresco-login/src/models/form-submit-event.model.ts
rename to ng2-components/ng2-alfresco-login/src/models/login-submit.event.ts
index 957b0b7d0f..b2548069a2 100644
--- a/ng2-components/ng2-alfresco-login/src/models/form-submit-event.model.ts
+++ b/ng2-components/ng2-alfresco-login/src/models/login-submit.event.ts
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-export class FormSubmitEvent {
+export class LoginSubmitEvent {
private _values: any;
private _defaultPrevented: boolean = false;
diff --git a/ng2-components/ng2-alfresco-login/src/models/login-success.event.ts b/ng2-components/ng2-alfresco-login/src/models/login-success.event.ts
new file mode 100644
index 0000000000..7cc11ad81f
--- /dev/null
+++ b/ng2-components/ng2-alfresco-login/src/models/login-success.event.ts
@@ -0,0 +1,24 @@
+/*!
+ * @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 LoginSuccessEvent {
+ constructor(
+ public token: any,
+ public username: string,
+ public password: string) {
+ }
+}