@@ -35,6 +35,7 @@ import { CorePath } from '@singletons/path';
3535import { CoreDom } from '@singletons/dom' ;
3636import { CoreSitesFactory } from '@services/sites-factory' ;
3737import { EMAIL_SIGNUP_FEATURE_NAME } from '@features/login/constants' ;
38+ import { CoreInputErrorsMessages } from '@components/input-errors/input-errors' ;
3839
3940/**
4041 * Page to signup using email.
@@ -46,6 +47,10 @@ import { EMAIL_SIGNUP_FEATURE_NAME } from '@features/login/constants';
4647} )
4748export class CoreLoginEmailSignupPage implements OnInit {
4849
50+ // Accept A-Z in strict chars pattern to be able to differentiate it from the lowercase pattern.
51+ protected static readonly USERNAME_STRICT_CHARS_PATTERN = '^[A-Z-.@_a-z0-9]*$' ;
52+ protected static readonly USERNAME_LOWERCASE_PATTERN = '^[^A-Z]*$' ;
53+
4954 @ViewChild ( CoreRecaptchaComponent ) recaptchaComponent ?: CoreRecaptchaComponent ;
5055 @ViewChild ( 'ageForm' ) ageFormElement ?: ElementRef ;
5156 @ViewChild ( 'signupFormEl' ) signupFormElement ?: ElementRef ;
@@ -77,12 +82,12 @@ export class CoreLoginEmailSignupPage implements OnInit {
7782 supportEmail ?: string ;
7883
7984 // Validation errors.
80- usernameErrors : Record < string , string > ;
81- passwordErrors : Record < string , string > ;
82- emailErrors : Record < string , string > ;
83- email2Errors : Record < string , string > ;
84- policyErrors : Record < string , string > ;
85- namefieldsErrors ?: Record < string , Record < string , string > > ;
85+ usernameErrors : CoreInputErrorsMessages ;
86+ passwordErrors : CoreInputErrorsMessages ;
87+ emailErrors : CoreInputErrorsMessages ;
88+ email2Errors : CoreInputErrorsMessages ;
89+ policyErrors : CoreInputErrorsMessages ;
90+ namefieldsErrors ?: Record < string , CoreInputErrorsMessages > ;
8691
8792 constructor (
8893 protected fb : FormBuilder ,
@@ -98,14 +103,19 @@ export class CoreLoginEmailSignupPage implements OnInit {
98103
99104 // Create the signupForm with the basic controls. More controls will be added later.
100105 this . signupForm = this . fb . group ( {
101- username : [ '' , Validators . required ] ,
102106 password : [ '' , Validators . required ] ,
103107 email : [ '' , Validators . compose ( [ Validators . required , Validators . email ] ) ] ,
104108 email2 : [ '' , Validators . compose ( [ Validators . required , Validators . email ] ) ] ,
105109 } ) ;
106110
107111 // Setup validation errors.
108- this . usernameErrors = { required : 'core.login.usernamerequired' } ;
112+ this . usernameErrors = {
113+ required : 'core.login.usernamerequired' ,
114+ pattern : {
115+ [ CoreLoginEmailSignupPage . USERNAME_STRICT_CHARS_PATTERN ] : 'core.login.invalidusername' ,
116+ [ CoreLoginEmailSignupPage . USERNAME_LOWERCASE_PATTERN ] : 'core.login.usernamelowercase' ,
117+ } ,
118+ } ;
109119 this . passwordErrors = { required : 'core.login.passwordrequired' } ;
110120 this . emailErrors = { required : 'core.login.missingemail' } ;
111121 this . policyErrors = { required : 'core.login.policyagree' } ;
@@ -140,6 +150,13 @@ export class CoreLoginEmailSignupPage implements OnInit {
140150 * Complete the FormGroup using the settings received from server.
141151 */
142152 protected completeFormGroup ( ) : void {
153+ const checkStrictChars = this . settings ?. extendedusernamechars === false ;
154+ this . signupForm . addControl ( 'username' , this . fb . control ( '' , Validators . compose ( [
155+ Validators . required ,
156+ Validators . pattern ( CoreLoginEmailSignupPage . USERNAME_LOWERCASE_PATTERN ) ,
157+ checkStrictChars ? Validators . pattern ( CoreLoginEmailSignupPage . USERNAME_STRICT_CHARS_PATTERN ) : undefined ,
158+ ] ) ) ) ;
159+
143160 this . signupForm . addControl ( 'city' , this . fb . control ( this . settings ?. defaultcity || '' ) ) ;
144161 this . signUpCountryControl = this . fb . control ( this . settings ?. country || '' , { nonNullable : true } ) ;
145162 this . signupForm . addControl ( 'country' , this . signUpCountryControl ) ;
0 commit comments