Archived
1
0
Fork 0

app/forms/UserSettings.php: adding a admin flag.

This commit is contained in:
Henrik Hautakoski 2019-12-03 11:02:52 +01:00
parent adaf80d967
commit e332e1a7e7
No known key found for this signature in database
GPG key ID: 96765B12FEAC4745

View file

@ -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'];