2016-05-15 04:03:21 +05:30
|
|
|
<?php
|
|
|
|
namespace api\validators;
|
|
|
|
|
2016-06-17 02:02:23 +05:30
|
|
|
use common\helpers\Error as E;
|
2016-05-15 04:03:21 +05:30
|
|
|
use common\models\EmailActivation;
|
|
|
|
use yii\validators\Validator;
|
|
|
|
|
|
|
|
class EmailActivationKeyValidator extends Validator {
|
|
|
|
|
2016-06-17 02:02:23 +05:30
|
|
|
public $notExist = E::KEY_NOT_EXISTS;
|
2016-05-15 04:03:21 +05:30
|
|
|
|
2016-06-17 02:02:23 +05:30
|
|
|
public $expired = E::KEY_EXPIRE;
|
2016-05-15 04:03:21 +05:30
|
|
|
|
|
|
|
public function validateValue($value) {
|
|
|
|
if (($model = $this->findEmailActivationModel($value)) === null) {
|
|
|
|
return [$this->notExist, []];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($model->isExpired()) {
|
|
|
|
return [$this->expired, []];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
* @return null|EmailActivation
|
|
|
|
*/
|
|
|
|
protected function findEmailActivationModel($key) {
|
|
|
|
return EmailActivation::findOne($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|