/**
* Set the field values
*
* @param array $values
* @param Auth $auth
* @return Login
*/
public function setFieldValues(array $values = null, Auth $auth = null)
{
parent::setFieldValues($values);
if ($_POST && null !== $this->username && null !== $this->password && null !== $auth) {
$auth->authenticate(html_entity_decode($this->username, ENT_QUOTES, 'UTF-8'), html_entity_decode($this->password, ENT_QUOTES, 'UTF-8'));
if (!$auth->isValid()) {
$this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'The login was not correct.'));
} else {
if (!$auth->adapter()->getUser()->verified) {
$this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not verified.'));
} else {
if (!$auth->adapter()->getUser()->active) {
$this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is blocked.'));
} else {
$role = Table\Roles::findById($auth->adapter()->getUser()->role_id);
if (isset($role->id) && null !== $role->permissions) {
$permissions = unserialize($role->permissions);
if (isset($permissions['deny'])) {
foreach ($permissions['deny'] as $deny) {
if ($deny['resource'] == 'login') {
$this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not allowed to login.'));
}
}
}
}
}
}
}
}
return $this;
}