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
|
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()
|
public function initialize()
|
||||||
{
|
{
|
||||||
$this->setValidation(new \Phalcon\Validation());
|
$this->setValidation(new \Phalcon\Validation());
|
||||||
|
|
@ -118,7 +130,7 @@ class UserSettings extends FormBase
|
||||||
$current_pw = $this->getEntity()->getPassword();
|
$current_pw = $this->getEntity()->getPassword();
|
||||||
|
|
||||||
// Current
|
// Current
|
||||||
if (strlen($current_pw) > 0) {
|
if ($this->_admin === false && strlen($current_pw) > 0) {
|
||||||
$current = new Password('passwordCurrent', array(
|
$current = new Password('passwordCurrent', array(
|
||||||
'class' => 'form-control',
|
'class' => 'form-control',
|
||||||
));
|
));
|
||||||
|
|
@ -143,7 +155,7 @@ class UserSettings extends FormBase
|
||||||
// Validation
|
// Validation
|
||||||
$validation = $this->getValidation();
|
$validation = $this->getValidation();
|
||||||
|
|
||||||
if (strlen($current_pw) > 0) {
|
if ($this->_admin === false && strlen($current_pw) > 0) {
|
||||||
$validation->add('passwordCurrent', new CallbackValidator([
|
$validation->add('passwordCurrent', new CallbackValidator([
|
||||||
'callback' => function($data) {
|
'callback' => function($data) {
|
||||||
$new_pw = $data['passwordNew'];
|
$new_pw = $data['passwordNew'];
|
||||||
|
|
|
||||||
Reference in a new issue