From 8358661d81b10b65e143e6bb4d0dacd1ea99d0fc Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 25 Jun 2021 21:36:44 +0100 Subject: [PATCH] try and not require a password change on user edit --- include/Form/User.php | 12 ++++++------ public/index.php | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/Form/User.php b/include/Form/User.php index 18bcd80..3c1e09f 100644 --- a/include/Form/User.php +++ b/include/Form/User.php @@ -9,7 +9,7 @@ class User implements Form { */ protected $form; - public function __construct(array $data = []) { + public function __construct(array $data = [], $is_new = false) { $this->form = new \Zend_Form(); @@ -32,19 +32,19 @@ public function __construct(array $data = []) { $email = new \Zend_Form_Element_Text('email'); $email->setRequired(false); - $email->setLabel('Email address'); + $email->setLabel('Email address'); $email->addValidator(new \Zend_Validate_StringLength([1, 100])); $email->addValidator(new \Zend_Validate_EmailAddress()); - $password = new \Zend_Form_Element_Text('password'); - if(empty($data)) { + $password->setRequired(false); + if($is_new) { $password->setRequired(true); } + $password->addValidator(new \Zend_Validate_StringLength([0,100])); $password->setLabel('Password'); - $password->addValidator(new \Zend_Validate_StringLength([1,100])); $uid_select = new \Zend_Form_Element_Select('uid'); @@ -68,7 +68,7 @@ public function __construct(array $data = []) { $this->form->addElement($submit); - if(!empty($data)) { + if(!empty($data)) { $this->form->isValid($data); } diff --git a/public/index.php b/public/index.php index 3fafa36..839e58c 100644 --- a/public/index.php +++ b/public/index.php @@ -20,15 +20,19 @@ $what = 'New User'; $user = []; + $is_new = true; if (isset($_REQUEST['username'])) { $what = 'Edit User'; $user = $model->getUserByUsername($_REQUEST['username']); + if(!empty($user)) { + $is_new = false; + } } $template = new \PureFTPAdmin\Template($what); - $form = new PureFTPAdmin\Form\User(); + $form = new PureFTPAdmin\Form\User([], $is_new); $form->setGidList($model->getGidList()); $form->setUidList($model->getUidList());