|
<?php |
|
|
|
namespace Kanboard\Validator; |
|
|
|
use SimpleValidator\Validator; |
|
use SimpleValidator\Validators; |
|
use Gregwar\Captcha\CaptchaBuilder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetValidator extends BaseValidator |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function validateCreation(array $values) |
|
{ |
|
return $this->executeValidators(array('validateFields', 'validateCaptcha'), $values); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function validateModification(array $values) |
|
{ |
|
$v = new Validator($values, $this->commonPasswordValidationRules()); |
|
|
|
return array( |
|
$v->execute(), |
|
$v->getErrors(), |
|
); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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', 191), 191), |
|
)); |
|
|
|
return array( |
|
$v->execute(), |
|
$v->getErrors(), |
|
); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function validateCaptcha(array $values) |
|
{ |
|
$errors = array(); |
|
|
|
if (! session_exists('captcha')) { |
|
$result = false; |
|
} else { |
|
$builder = new CaptchaBuilder; |
|
$builder->setPhrase(session_get('captcha')); |
|
$result = $builder->testPhrase(isset($values['captcha']) ? $values['captcha'] : ''); |
|
|
|
if (! $result) { |
|
$errors['captcha'] = array(t('Invalid captcha')); |
|
} |
|
|
|
|
|
session_remove('captcha'); |
|
} |
|
|
|
return array($result, $errors); |
|
} |
|
} |
|
|