app/forms/UserSettings.php: adding a admin flag.
This commit is contained in:
parent
adaf80d967
commit
e332e1a7e7
1 changed files with 14 additions and 2 deletions
|
|
@ -36,6 +36,18 @@ use Phalcon\Validation\Validator\Callback as CallbackValidator,
|
|||
|
||||
class UserSettings extends FormBase
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_admin;
|
||||
|
||||
public function __construct(UserModel $user = null, bool $admin = false)
|
||||
{
|
||||
$this->_admin = $admin;
|
||||
|
||||
parent::__construct($user);
|
||||
}
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
$this->setValidation(new \Phalcon\Validation());
|
||||
|
|
@ -118,7 +130,7 @@ class UserSettings extends FormBase
|
|||
$current_pw = $this->getEntity()->getPassword();
|
||||
|
||||
// Current
|
||||
if (strlen($current_pw) > 0) {
|
||||
if ($this->_admin === false && strlen($current_pw) > 0) {
|
||||
$current = new Password('passwordCurrent', array(
|
||||
'class' => 'form-control',
|
||||
));
|
||||
|
|
@ -143,7 +155,7 @@ class UserSettings extends FormBase
|
|||
// Validation
|
||||
$validation = $this->getValidation();
|
||||
|
||||
if (strlen($current_pw) > 0) {
|
||||
if ($this->_admin === false && strlen($current_pw) > 0) {
|
||||
$validation->add('passwordCurrent', new CallbackValidator([
|
||||
'callback' => function($data) {
|
||||
$new_pw = $data['passwordNew'];
|
||||
|
|
|
|||
Reference in a new issue