From 3469dcfcd55cbdce68e61bf360f7c661fd9aac63 Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Tue, 19 Mar 2019 18:38:17 +0100 Subject: [PATCH] New class DomainListInputFormField for alias list validation upon account creation --- evolibs/Form.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ inc/accounts.php | 4 ++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/evolibs/Form.php b/evolibs/Form.php index e398ccb..1e7b2b6 100644 --- a/evolibs/Form.php +++ b/evolibs/Form.php @@ -456,6 +456,58 @@ class DomainInputFormField extends FormField { } } + +class DomainListInputFormField extends FormField { + protected $mandatory = NULL; + protected $textsize = NULL; + + public function __construct($label, $mandatory=TRUE) { + parent::__construct($label); + $this->mandatory = $mandatory; + $this->textsize = $textsize; + } + + public function verify($set_error) { + if($this->mandatory && (!strlen($this->value))) { + if($set_error) $this->error = 'Champ obligatoire'; + return FALSE; + } + + if(strlen($this->value)){ + $list = explode(',', $this->value); + foreach ($list as $value) { + if (!preg_match("/^[a-z0-9-.]+\.[a-z]{2,}$/i", $value)) { + if($set_error) $this->error = 'Ceci n\'est pas un nom de domaine'; + return FALSE; + } + } + } + + return TRUE; + } + + public function getInputHTML() { + $input = ''; + $input .= 'name.'" value="'.htmlspecialchars($this->value,ENT_QUOTES).'"'; + $input .= ' maxlength="'.$this->textsize[1].'" size="'.$this->textsize[0].'" '; + if($this->read_only) { $input .= 'readonly="readonly="'; } + if($this->disabled) { $input .= 'disabled="disabled="'; } + $input .= '/>'; + return $input; + } + + public function __toString() { + $out = ''; + $out .= "

\n"; + $out .= $this->getLabelHTML(); + $out .= $this->getInputHTML(); + $out .= $this->getErrorHTML(); + $out .= "

\n\n"; + return $out; + } +} + class DateInputFormField extends TextInputFormField { public function __construct($label, $mandatory=TRUE) { parent::__construct($label, $mandatory, array(7, 10)); diff --git a/inc/accounts.php b/inc/accounts.php index 45ecc83..8a4c91f 100644 --- a/inc/accounts.php +++ b/inc/accounts.php @@ -252,8 +252,8 @@ function web_add_cluster($form, $admin_mail) { $form = new FormPage("Ajout d'un compte web", FALSE); $form->addField('username', new TextInputFormField("Nom d'utilisateur", TRUE, array(20,16))); $form->addField('domain', new DomainInputFormField("Nom de domaine", TRUE)); -$form->addField('domain_alias', new TextInputFormField("Alias (séparés par une virgule)", FALSE)); -$form->addField('password_random', +$form->addField('domain_alias', new DomainListInputFormField("Alias (séparés par une virgule, sans espaces)", FALSE)); +$form->addField('password_random', new CheckboxInputFormField("Mot de passe aléatoire ?", FALSE)); $form->getField('password_random')->setValue(TRUE); $form->addField('password', new PasswordInputFormField('Mot de passe', FALSE));