-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #960 from proditis/master
Improvements to multiple components
- Loading branch information
Showing
22 changed files
with
464 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
backend/components/validators/HourRegistrationValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Check memcache key for registrations performed by this IP. | ||
*/ | ||
namespace app\components\validators; | ||
|
||
use yii\validators\Validator; | ||
use yii\helpers\ArrayHelper; | ||
|
||
class HourRegistrationValidator extends Validator | ||
{ | ||
public $max=3; | ||
public $message; | ||
public $counter; | ||
public $client_ip; | ||
public function init() | ||
{ | ||
$this->message=\Yii::t('app',"You reached your maximum registrations for this hour!"); | ||
if(!$this->counter) | ||
$this->counter=intval(\Yii::$app->cache->memcache->get('registeredip:'.$this->client_ip)); | ||
parent::init(); | ||
} | ||
public function validateValue($value) | ||
{ | ||
if (\Yii::$app->sys->signup_HourRegistrationValidator!==false && intval($this->counter)>=$this->max) | ||
{ | ||
return [$this->message, [ | ||
'signup_ip' => $value, | ||
]]; | ||
} | ||
|
||
} | ||
public function validateAttribute($model, $attribute) | ||
{ | ||
$value = $model->$attribute; | ||
if(\Yii::$app->sys->signup_HourRegistrationValidator!==false && intval($this->counter)>=$this->max) | ||
{ | ||
$model->addError($attribute, $this->message); | ||
} | ||
} | ||
|
||
public function clientValidateAttribute($model, $attribute, $view) | ||
{ | ||
if(\Yii::$app->sys->signup_HourRegistrationValidator!==false) | ||
{ | ||
$message = json_encode($this->message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); | ||
return <<<JS | ||
if ({$this->counter}>={$this->max}) { | ||
messages.push($message); | ||
return false; | ||
} | ||
JS; | ||
|
||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
backend/components/validators/LowerRangeValidator copy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* @link http://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license http://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace app\components\validators; | ||
|
||
use Yii; | ||
use yii\base\InvalidConfigException; | ||
use yii\helpers\ArrayHelper; | ||
use yii\validators\ValidationAsset; | ||
/** | ||
* RangeValidator validates that the attribute value is among a list of values. | ||
* | ||
* The range can be specified via the [[range]] property. | ||
* If the [[not]] property is set true, the validator will ensure the attribute value | ||
* is NOT among the specified range. | ||
* | ||
* @author Qiang Xue <qiang.xue@gmail.com> | ||
* @since 2.0 | ||
*/ | ||
class LowerRangeValidator extends \yii\validators\RangeValidator | ||
{ | ||
/** | ||
* @var array|\Traversable|\Closure $range | ||
*/ | ||
public $range; | ||
/** | ||
* @var bool whether the comparison is strict (both type and value must be the same) | ||
*/ | ||
public $strict=false; | ||
/** | ||
* @var bool whether to invert the validation logic. Defaults to false. If set to true, | ||
* the attribute value should NOT be among the list of values defined via [[range]]. | ||
*/ | ||
public $not=false; | ||
/** | ||
* @var bool whether to allow array type attribute. | ||
*/ | ||
public $allowArray=false; | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
if($this->message === null) | ||
{ | ||
$this->message=Yii::t('yii', '{attribute} is invalid.'); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function validateValue($value) | ||
{ | ||
$in=false; | ||
|
||
if(ArrayHelper::isIn(mb_strtolower($value), (array) $this->range, $this->strict)) | ||
{ | ||
$in=true; | ||
} | ||
return $this->not !== $in ? null : [$this->message, []]; | ||
} | ||
} |
Oops, something went wrong.