From 29b92647a72b1ee97a99de7e411f0e24865fd69c Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Tue, 26 Mar 2019 16:59:12 +0100 Subject: [PATCH] Refactor the domain and alias checks done at account creation --- inc/accounts.php | 17 +++++++++-------- tpl/accounts.tpl.php | 18 +++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/inc/accounts.php b/inc/accounts.php index a223167..0513670 100644 --- a/inc/accounts.php +++ b/inc/accounts.php @@ -388,20 +388,21 @@ if(!empty($_POST)) { /* Test de validation du formulaire */ if($form->verify(TRUE)) { - $is_domain_present = check_occurence_name($form->getField('domain')->getValue()); - $is_alias_present = check_occurence_name($form->getField('domain_alias')->getValue()); + $errors_check = array(); - 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']) $exec_info = web_add_cluster($form, $conf['admin']['mail']); else $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."); - } } } diff --git a/tpl/accounts.tpl.php b/tpl/accounts.tpl.php index 859b442..89e4c84 100644 --- a/tpl/accounts.tpl.php +++ b/tpl/accounts.tpl.php @@ -13,9 +13,7 @@ * @version 1.0 */ -?> -'; if ($conf['debug'] == TRUE) @@ -23,7 +21,7 @@ if ($exec_info[1]) { print "La commande a échoué\n"; - print_r($exec_info); + print_r($exec_info); } else print "Le compte a été créé avec succès\n"; @@ -35,18 +33,20 @@ print ''; } else { + // If there is validation errors, display them if (isset($errors_check)) { - print '

Erreur(s) :
'; - foreach ($errors_check as $error) { - printf('%s
', $error); - } - print '

'; + print '

Erreur(s) :
'; + foreach ($errors_check as $error) { + printf('%s
', $error); + } + print '

'; } ?> +
Ajout d'un compte - +