1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Validator/PasswordResetValidator.php
2016-01-24 17:50:52 +01:00

92 lines
2.4 KiB
PHP

<?php
namespace Kanboard\Validator;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
use Gregwar\Captcha\CaptchaBuilder;
/**
* Password Reset Validator
*
* @package validator
* @author Frederic Guillot
*/
class PasswordResetValidator extends Base
{
/**
* Validate creation
*
* @access public
* @param array $values Form values
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/
public function validateCreation(array $values)
{
return $this->executeValidators(array('validateFields', 'validateCaptcha'), $values);
}
/**
* Validate modification
*
* @access public
* @param array $values Form values
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/
public function validateModification(array $values)
{
$v = new Validator($values, $this->commonPasswordValidationRules());
return array(
$v->execute(),
$v->getErrors(),
);
}
/**
* Validate fields
*
* @access protected
* @param array $values Form values
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/
protected function validateFields(array $values)
{
$v = new Validator($values, array(
new Validators\Required('captcha', t('This value is required')),
new Validators\Required('username', t('The username is required')),
new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50),
));
return array(
$v->execute(),
$v->getErrors(),
);
}
/**
* Validate captcha
*
* @access protected
* @param array $values Form values
* @return boolean
*/
protected function validateCaptcha(array $values)
{
$errors = array();
if (! isset($this->sessionStorage->captcha)) {
$result = false;
} else {
$builder = new CaptchaBuilder;
$builder->setPhrase($this->sessionStorage->captcha);
$result = $builder->testPhrase(isset($values['captcha']) ? $values['captcha'] : '');
if (! $result) {
$errors['captcha'] = array(t('Invalid captcha'));
}
}
return array($result, $errors);;
}
}