From a74c5108fd3b3e5eb317d42da3456d6d8ea2ef75 Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Tue, 28 Nov 2017 10:42:41 +0300 Subject: [PATCH 1/4] Fixed: Couple small issues with Auth forms Added custom validator for Password Matching to Register forms --- .../forgot-password-2.component.ts | 2 +- .../forgot-password.component.ts | 2 +- .../authentication/lock/lock.component.ts | 2 +- .../register-2/register-2.component.html | 7 ++-- .../register-2/register-2.component.ts | 33 +++++++++++++++++-- .../register/register.component.html | 7 ++-- .../register/register.component.ts | 33 +++++++++++++++++-- .../reset-password-2.component.ts | 2 +- .../reset-password.component.ts | 2 +- 9 files changed, 76 insertions(+), 14 deletions(-) diff --git a/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts b/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts index 611dcb0d..6a26dd6c 100644 --- a/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts +++ b/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts @@ -57,7 +57,7 @@ export class FuseForgotPassword2Component implements OnInit this.forgotPasswordFormErrors[field] = {}; // Get the control - const control = this.forgotPasswordFormErrors.get(field); + const control = this.forgotPasswordForm.get(field); if ( control && control.dirty && !control.valid ) { diff --git a/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.ts b/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.ts index 5c060222..1ea17741 100644 --- a/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.ts +++ b/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.ts @@ -56,7 +56,7 @@ export class FuseForgotPasswordComponent implements OnInit this.forgotPasswordFormErrors[field] = {}; // Get the control - const control = this.forgotPasswordFormErrors.get(field); + const control = this.forgotPasswordForm.get(field); if ( control && control.dirty && !control.valid ) { diff --git a/src/app/main/content/pages/authentication/lock/lock.component.ts b/src/app/main/content/pages/authentication/lock/lock.component.ts index 27fc8c5d..6132336f 100644 --- a/src/app/main/content/pages/authentication/lock/lock.component.ts +++ b/src/app/main/content/pages/authentication/lock/lock.component.ts @@ -55,7 +55,7 @@ export class FuseLockComponent implements OnInit { for ( const field in this.lockFormErrors ) { - if ( this.lockFormErrors.hasOwnProperty(field) ) + if ( !this.lockFormErrors.hasOwnProperty(field) ) { continue; } diff --git a/src/app/main/content/pages/authentication/register-2/register-2.component.html b/src/app/main/content/pages/authentication/register-2/register-2.component.html index c3a3269f..eacb649d 100644 --- a/src/app/main/content/pages/authentication/register-2/register-2.component.html +++ b/src/app/main/content/pages/authentication/register-2/register-2.component.html @@ -48,17 +48,20 @@ - + Password is required - + Password confirmation is required + + Password confirmation must match with password +
diff --git a/src/app/main/content/pages/authentication/register-2/register-2.component.ts b/src/app/main/content/pages/authentication/register-2/register-2.component.ts index 57e6db4a..f4923bd6 100644 --- a/src/app/main/content/pages/authentication/register-2/register-2.component.ts +++ b/src/app/main/content/pages/authentication/register-2/register-2.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; @@ -42,7 +42,7 @@ export class FuseRegister2Component implements OnInit name : ['', Validators.required], email : ['', [Validators.required, Validators.email]], password : ['', Validators.required], - passwordConfirm: ['', Validators.required] + passwordConfirm: ['', [Validators.required, confirmPassword]] }); this.registerForm.valueChanges.subscribe(() => { @@ -72,3 +72,32 @@ export class FuseRegister2Component implements OnInit } } } + + +function confirmPassword(control: AbstractControl) +{ + if ( !control.parent || !control ) + { + return; + } + + const password = control.parent.get('password'); + const passwordConfirm = control.parent.get('passwordConfirm'); + + if ( !password || !passwordConfirm ) + { + return; + } + + if ( passwordConfirm.value === '' ) + { + return; + } + + if ( password.value !== passwordConfirm.value ) + { + return { + passwordsNotMatch: true + }; + } +} diff --git a/src/app/main/content/pages/authentication/register/register.component.html b/src/app/main/content/pages/authentication/register/register.component.html index 32f6d0bb..4ac04c61 100644 --- a/src/app/main/content/pages/authentication/register/register.component.html +++ b/src/app/main/content/pages/authentication/register/register.component.html @@ -30,17 +30,20 @@ - + Password is required - + Password confirmation is required + + Password confirmation must match with password +
diff --git a/src/app/main/content/pages/authentication/register/register.component.ts b/src/app/main/content/pages/authentication/register/register.component.ts index 69b64353..1aa85da0 100644 --- a/src/app/main/content/pages/authentication/register/register.component.ts +++ b/src/app/main/content/pages/authentication/register/register.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; @@ -38,12 +38,11 @@ export class FuseRegisterComponent implements OnInit ngOnInit() { - this.registerForm = this.formBuilder.group({ name : ['', Validators.required], email : ['', [Validators.required, Validators.email]], password : ['', Validators.required], - passwordConfirm: ['', Validators.required] + passwordConfirm: ['', [Validators.required, confirmPassword]] }); this.registerForm.valueChanges.subscribe(() => { @@ -73,3 +72,31 @@ export class FuseRegisterComponent implements OnInit } } } + +function confirmPassword(control: AbstractControl) +{ + if ( !control.parent || !control ) + { + return; + } + + const password = control.parent.get('password'); + const passwordConfirm = control.parent.get('passwordConfirm'); + + if ( !password || !passwordConfirm ) + { + return; + } + + if ( passwordConfirm.value === '' ) + { + return; + } + + if ( password.value !== passwordConfirm.value ) + { + return { + passwordsNotMatch: true + }; + } +} diff --git a/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.ts b/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.ts index 9a9b8a62..e433bdfa 100644 --- a/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.ts +++ b/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.ts @@ -52,7 +52,7 @@ export class FuseResetPassword2Component implements OnInit { for ( const field in this.resetPasswordFormErrors ) { - if ( this.resetPasswordFormErrors.hasOwnProperty(field) ) + if ( !this.resetPasswordFormErrors.hasOwnProperty(field) ) { continue; } diff --git a/src/app/main/content/pages/authentication/reset-password/reset-password.component.ts b/src/app/main/content/pages/authentication/reset-password/reset-password.component.ts index f33643d9..53069d27 100644 --- a/src/app/main/content/pages/authentication/reset-password/reset-password.component.ts +++ b/src/app/main/content/pages/authentication/reset-password/reset-password.component.ts @@ -52,7 +52,7 @@ export class FuseResetPasswordComponent implements OnInit { for ( const field in this.resetPasswordFormErrors ) { - if ( this.resetPasswordFormErrors.hasOwnProperty(field) ) + if ( !this.resetPasswordFormErrors.hasOwnProperty(field) ) { continue; } From 4c6ef29e2020c92e4e995ba2779f12076a356a59 Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Tue, 28 Nov 2017 10:48:52 +0300 Subject: [PATCH 2/4] Fixed: Behavior Subject must be array --- src/app/main/content/apps/contacts/contacts.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/main/content/apps/contacts/contacts.service.ts b/src/app/main/content/apps/contacts/contacts.service.ts index 4c96bed4..aa1ff0c2 100644 --- a/src/app/main/content/apps/contacts/contacts.service.ts +++ b/src/app/main/content/apps/contacts/contacts.service.ts @@ -10,7 +10,7 @@ import { Subject } from 'rxjs/Subject'; @Injectable() export class ContactsService implements Resolve { - onContactsChanged: BehaviorSubject = new BehaviorSubject({}); + onContactsChanged: BehaviorSubject = new BehaviorSubject([]); onSelectedContactsChanged: BehaviorSubject = new BehaviorSubject([]); onUserDataChanged: BehaviorSubject = new BehaviorSubject([]); onSearchTextChanged: Subject = new Subject(); From ad21d9fed56f2d0d1974ebd4d6aa5295763deaa2 Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Thu, 30 Nov 2017 10:21:22 +0300 Subject: [PATCH 3/4] Further improvements to Auth pages --- .../forgot-password-2.component.html | 3 +- .../forgot-password-2.component.ts | 1 - .../forgot-password.component.html | 3 +- .../authentication/lock/lock.component.ts | 1 - .../login-2/login-2.component.html | 5 +-- .../login-2/login-2.component.ts | 1 - .../authentication/login/login.component.html | 2 +- .../authentication/login/login.component.ts | 1 - .../mail-confirm/mail-confirm.component.ts | 3 +- .../register-2/register-2.component.html | 5 +-- .../register-2/register-2.component.ts | 2 -- .../register/register.component.html | 2 +- .../register/register.component.ts | 1 - .../reset-password-2.component.html | 10 ++++-- .../reset-password-2.component.ts | 33 +++++++++++++++++-- .../reset-password.component.html | 7 ++-- .../reset-password.component.ts | 33 +++++++++++++++++-- 17 files changed, 85 insertions(+), 28 deletions(-) diff --git a/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.html b/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.html index 70d797b6..668cac38 100644 --- a/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.html +++ b/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.html @@ -17,7 +17,8 @@
-
+
diff --git a/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts b/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts index 6a26dd6c..b934433a 100644 --- a/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts +++ b/src/app/main/content/pages/authentication/forgot-password-2/forgot-password-2.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; - import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; diff --git a/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.html b/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.html index 65694575..5fdedb29 100644 --- a/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.html +++ b/src/app/main/content/pages/authentication/forgot-password/forgot-password.component.html @@ -1,6 +1,7 @@
-
+
diff --git a/src/app/main/content/pages/authentication/lock/lock.component.ts b/src/app/main/content/pages/authentication/lock/lock.component.ts index 6132336f..22e18a08 100644 --- a/src/app/main/content/pages/authentication/lock/lock.component.ts +++ b/src/app/main/content/pages/authentication/lock/lock.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; - import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; diff --git a/src/app/main/content/pages/authentication/login-2/login-2.component.html b/src/app/main/content/pages/authentication/login-2/login-2.component.html index 435581f4..68377365 100644 --- a/src/app/main/content/pages/authentication/login-2/login-2.component.html +++ b/src/app/main/content/pages/authentication/login-2/login-2.component.html @@ -17,7 +17,8 @@
-
+
@@ -41,7 +42,7 @@ - + Password is required diff --git a/src/app/main/content/pages/authentication/login-2/login-2.component.ts b/src/app/main/content/pages/authentication/login-2/login-2.component.ts index f74ba611..c0637711 100644 --- a/src/app/main/content/pages/authentication/login-2/login-2.component.ts +++ b/src/app/main/content/pages/authentication/login-2/login-2.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; - import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; diff --git a/src/app/main/content/pages/authentication/login/login.component.html b/src/app/main/content/pages/authentication/login/login.component.html index d47e9e6e..b94ddc49 100644 --- a/src/app/main/content/pages/authentication/login/login.component.html +++ b/src/app/main/content/pages/authentication/login/login.component.html @@ -23,7 +23,7 @@ - + Password is required diff --git a/src/app/main/content/pages/authentication/login/login.component.ts b/src/app/main/content/pages/authentication/login/login.component.ts index c8f4f4a4..0d052fb9 100644 --- a/src/app/main/content/pages/authentication/login/login.component.ts +++ b/src/app/main/content/pages/authentication/login/login.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; - import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; diff --git a/src/app/main/content/pages/authentication/mail-confirm/mail-confirm.component.ts b/src/app/main/content/pages/authentication/mail-confirm/mail-confirm.component.ts index 91fef411..b0c357f2 100644 --- a/src/app/main/content/pages/authentication/mail-confirm/mail-confirm.component.ts +++ b/src/app/main/content/pages/authentication/mail-confirm/mail-confirm.component.ts @@ -1,5 +1,4 @@ -import { Component} from '@angular/core'; - +import { Component } from '@angular/core'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; diff --git a/src/app/main/content/pages/authentication/register-2/register-2.component.html b/src/app/main/content/pages/authentication/register-2/register-2.component.html index eacb649d..82331d80 100644 --- a/src/app/main/content/pages/authentication/register-2/register-2.component.html +++ b/src/app/main/content/pages/authentication/register-2/register-2.component.html @@ -17,7 +17,8 @@
-
+
@@ -60,7 +61,7 @@ Password confirmation is required - Password confirmation must match with password + Passwords must match diff --git a/src/app/main/content/pages/authentication/register-2/register-2.component.ts b/src/app/main/content/pages/authentication/register-2/register-2.component.ts index f4923bd6..441bcae2 100644 --- a/src/app/main/content/pages/authentication/register-2/register-2.component.ts +++ b/src/app/main/content/pages/authentication/register-2/register-2.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; - import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; @@ -73,7 +72,6 @@ export class FuseRegister2Component implements OnInit } } - function confirmPassword(control: AbstractControl) { if ( !control.parent || !control ) diff --git a/src/app/main/content/pages/authentication/register/register.component.html b/src/app/main/content/pages/authentication/register/register.component.html index 4ac04c61..12c92522 100644 --- a/src/app/main/content/pages/authentication/register/register.component.html +++ b/src/app/main/content/pages/authentication/register/register.component.html @@ -42,7 +42,7 @@ Password confirmation is required - Password confirmation must match with password + Passwords must match diff --git a/src/app/main/content/pages/authentication/register/register.component.ts b/src/app/main/content/pages/authentication/register/register.component.ts index 1aa85da0..e1df0c37 100644 --- a/src/app/main/content/pages/authentication/register/register.component.ts +++ b/src/app/main/content/pages/authentication/register/register.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; - import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FuseConfigService } from '../../../../../core/services/config.service'; import { fuseAnimations } from '../../../../../core/animations'; diff --git a/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.html b/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.html index 4ad45524..e5017346 100644 --- a/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.html +++ b/src/app/main/content/pages/authentication/reset-password-2/reset-password-2.component.html @@ -17,7 +17,8 @@
-
+
@@ -41,17 +42,20 @@ - + Password is required - + Password confirmation is required + + Passwords must match +