Hi, The problem is when try to validate it says that only email and username fields are required but it comes from auto PresenceOf model validation. So when I try to add for password Regex and/or PresenceOf it just doesn't work.
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Email as EmailValidator;
use Phalcon\Mvc\Model\Validator\Regex as RegexValidator;
use Phalcon\Mvc\Model\Validator\Uniqueness as UniquenessValidator;
use Phalcon\Mvc\Model\Validator\PresenceOf;
class Users extends Model
{
public $id;
public $email;
public $password;
public $username;
public $type;
public $token;
public function validation()
{
$this->validate(new PresenceOf(
array(
"field" => "password",
"message" => "Password is required !"
)
));
$this->validate(new RegexValidator(
array(
'field' => 'password',
'pattern' => '/^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$/',
'message' => 'The password must be at least 8 characters long and must be a combination of upper and lower case letters and numbers.'
)
));
$this->validate(new EmailValidator(
array(
"field" => "email",
"message" => "Email address is not correct"
)
));
$this->validate(new UniquenessValidator(array(
'field' => 'email',
'message' => 'You cant use thi e-mail, please try with another one!'
)));
return $this->validationHasFailed() != true;
}
public function getId()
{
return $this->id;
}
public function getEmail()
{
return $this->email;
}
public function getPassword()
{
return $this->password;
}
public function getUsername()
{
return $this->username;
}
public function getType()
{
return $this->type;
}
public function setId($id)
{
$this->id = $id;
}
public function setEmail($email)
{
$this->email = $email;
}
public function setPassword($password)
{
$this->password = $this->getDi()->getSecurity()->hash($password);
}
public function setUsername($username)
{
$this->username = $username;
}
public function setType($type)
{
$this->type = $type;
}
public function getToken()
{
return $this->token;
}
public function setToken($token)
{
$this->token = $this->getDi()->getSecurity()->hash($token);
}
}