File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
src/app/core/components/two-factor-auth Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import {
33 UntypedFormBuilder ,
4+ UntypedFormControl ,
45 UntypedFormGroup ,
56 Validators ,
67} from '@angular/forms' ;
@@ -50,6 +51,7 @@ export class TwoFactorAuthComponent implements OnInit {
5051 async ngOnInit ( ) {
5152 this . loading = true ;
5253 this . methods = await this . api . idpuser . getTwoFactorMethods ( ) ;
54+
5355 this . loading = false ;
5456 }
5557
@@ -140,13 +142,22 @@ export class TwoFactorAuthComponent implements OnInit {
140142 } else if ( this . method === 'sms' ) {
141143 contactInfoControl . setValidators ( [
142144 Validators . required ,
143- Validators . maxLength ( 18 ) ,
144- Validators . minLength ( 17 ) ,
145+ this . smsLengthValidator ( ) ,
145146 ] ) ;
146147 }
147148 contactInfoControl . updateValueAndValidity ( ) ;
148149 }
149150
151+ private smsLengthValidator ( ) {
152+ return ( control : UntypedFormControl ) => {
153+ const value = control . value || '' ;
154+ if ( value . length === 14 || value . length === 18 || value . length === 17 ) {
155+ return null ;
156+ }
157+ return { invalidSmsLength : true } ;
158+ } ;
159+ }
160+
150161 hasMethod ( method : string ) : boolean {
151162 return this . methods . some ( ( m ) => m . method === method ) ;
152163 }
You can’t perform that action at this time.
0 commit comments