Refactor the domain and alias checks done at account creation

This commit is contained in:
Ludovic Poujol 2019-03-26 16:59:12 +01:00
parent b3ec773c64
commit 29b92647a7
2 changed files with 18 additions and 17 deletions

View file

@ -388,20 +388,21 @@ if(!empty($_POST)) {
/* Test de validation du formulaire */ /* Test de validation du formulaire */
if($form->verify(TRUE)) { if($form->verify(TRUE)) {
$is_domain_present = check_occurence_name($form->getField('domain')->getValue()); $errors_check = array();
$is_alias_present = check_occurence_name($form->getField('domain_alias')->getValue());
if (!$is_domain_present && !$is_alias_present) { if(check_occurence_name($form->getField('domain')->getValue())){
array_push($errors_check, "Domaine déjà présent dans d'autres vhosts.");
}
if(check_occurence_name($form->getField('domain_alias')->getValue())){
array_push($errors_check, "Alias déjà présent(s) dans d'autres vhosts.");
}
if (count($errors_check) === 0) {
if ($conf['cluster']) if ($conf['cluster'])
$exec_info = web_add_cluster($form, $conf['admin']['mail']); $exec_info = web_add_cluster($form, $conf['admin']['mail']);
else else
$exec_info = web_add($form, $conf['admin']['mail']); $exec_info = web_add($form, $conf['admin']['mail']);
} }
else {
$errors_check = array();
if ($is_domain_present) array_push($errors_check, "Domaine déjà présent dans d'autres vhosts.");
if ($is_alias_present) array_push($errors_check, "Alias déjà présent(s) dans d'autres vhosts.");
}
} }
} }

View file

@ -13,9 +13,7 @@
* @version 1.0 * @version 1.0
*/ */
?>
<?php
if(!empty($exec_info)) { if(!empty($exec_info)) {
print '<pre>'; print '<pre>';
if ($conf['debug'] == TRUE) if ($conf['debug'] == TRUE)
@ -23,7 +21,7 @@
if ($exec_info[1]) { if ($exec_info[1]) {
print "La commande a <strong>échoué</strong>\n"; print "La commande a <strong>échoué</strong>\n";
print_r($exec_info); print_r($exec_info);
} }
else print "Le compte a été créé avec succès\n"; else print "Le compte a été créé avec succès\n";
@ -35,18 +33,20 @@
print '</pre>'; print '</pre>';
} else { } else {
// If there is validation errors, display them
if (isset($errors_check)) { if (isset($errors_check)) {
print '<p class="form-error"><strong>Erreur(s) : </strong><br>'; print '<p class="form-error"><strong>Erreur(s) : </strong><br>';
foreach ($errors_check as $error) { foreach ($errors_check as $error) {
printf('%s<br>', $error); printf('%s<br>', $error);
} }
print '</p>'; print '</p>';
} }
?> ?>
<form name="form-add" id="form-add" action="" method="POST"> <form name="form-add" id="form-add" action="" method="POST">
<fieldset> <fieldset>
<legend>Ajout d'un compte</legend> <legend>Ajout d'un compte</legend>
<?php print $form; ?> <?= $form ?>
<p><input type="submit" value="Créer"/></p> <p><input type="submit" value="Créer"/></p>
</fieldset> </fieldset>
</form> </form>