Browse Source

Reorganized captcha code.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
3d5388ff2b
  1. 2
      apps/advanced/frontend/controllers/SiteController.php
  2. 2
      apps/advanced/frontend/views/site/contact.php
  3. 2
      apps/basic/controllers/SiteController.php
  4. 2
      apps/basic/views/site/contact.php
  5. 2
      framework/yii/assets.php
  6. 2
      framework/yii/assets/yii.captcha.js
  7. 4
      framework/yii/base/Model.php
  8. 5
      framework/yii/captcha/Captcha.php
  9. 11
      framework/yii/captcha/CaptchaAction.php
  10. 3
      framework/yii/captcha/CaptchaAsset.php
  11. 6
      framework/yii/captcha/CaptchaValidator.php
  12. 0
      framework/yii/captcha/SpicyRice.md
  13. 0
      framework/yii/captcha/SpicyRice.ttf
  14. 16
      framework/yii/classes.php
  15. 2
      framework/yii/validators/Validator.php
  16. 2
      tests/unit/data/base/Singer.php

2
apps/advanced/frontend/controllers/SiteController.php

@ -16,7 +16,7 @@ class SiteController extends Controller
{
return array(
'captcha' => array(
'class' => 'yii\web\CaptchaAction',
'class' => 'yii\captcha\CaptchaAction',
),
);
}

2
apps/advanced/frontend/views/site/contact.php

@ -1,7 +1,7 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\widgets\Captcha;
use yii\captcha\Captcha;
/**
* @var yii\base\View $this

2
apps/basic/controllers/SiteController.php

@ -13,7 +13,7 @@ class SiteController extends Controller
{
return array(
'captcha' => array(
'class' => 'yii\web\CaptchaAction',
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_DEV ? 'testme' : null,
),
);

2
apps/basic/views/site/contact.php

@ -1,7 +1,7 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\widgets\Captcha;
use yii\captcha\Captcha;
/**
* @var yii\base\View $this

2
framework/yii/assets.php

@ -6,6 +6,6 @@ return array(
yii\validators\PunycodeAsset::className(),
yii\validators\ValidationAsset::className(),
yii\widgets\ActiveFormAsset::className(),
yii\widgets\CaptchaAsset::className(),
yii\captcha\CaptchaAsset::className(),
yii\widgets\MaskedInputAsset::className(),
);

2
framework/yii/assets/yii.captcha.js

@ -1,7 +1,7 @@
/**
* Yii Captcha widget.
*
* This is the JavaScript widget used by the yii\widgets\Captcha widget.
* This is the JavaScript widget used by the yii\captcha\Captcha widget.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC

4
framework/yii/base/Model.php

@ -117,8 +117,8 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
* array('password', 'compare', 'compareAttribute' => 'password2', 'on' => 'register'),
* // an inline validator defined via the "authenticate()" method in the model class
* array('password', 'authenticate', 'on' => 'login'),
* // a validator of class "CaptchaValidator"
* array('captcha', 'CaptchaValidator'),
* // a validator of class "DateRangeValidator"
* array('dateRange', 'DateRangeValidator'),
* );
* ~~~
*

5
framework/yii/widgets/Captcha.php → framework/yii/captcha/Captcha.php

@ -5,13 +5,14 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
namespace yii\Captcha;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\CaptchaAction;
use yii\widgets\InputWidget;
/**
* Captcha renders a CAPTCHA image and an input field that takes user-entered verification code.

11
framework/yii/web/CaptchaAction.php → framework/yii/captcha/CaptchaAction.php

@ -5,12 +5,11 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
namespace yii\captcha;
use Yii;
use yii\base\Action;
use yii\base\InvalidConfigException;
use yii\widgets\Captcha;
/**
* CaptchaAction renders a CAPTCHA image.
@ -85,7 +84,7 @@ class CaptchaAction extends Action
/**
* @var string the TrueType font file. This can be either a file path or path alias.
*/
public $fontFile = '@yii/web/SpicyRice.ttf';
public $fontFile = '@yii/captcha/SpicyRice.ttf';
/**
* @var string the fixed verification code. When this property is set,
* [[getVerifyCode()]] will always return the value of this property.
@ -116,12 +115,14 @@ class CaptchaAction extends Action
if (isset($_GET[self::REFRESH_GET_VAR])) {
// AJAX request for regenerating code
$code = $this->getVerifyCode(true);
/** @var \yii\web\Controller $controller */
$controller = $this->controller;
return json_encode(array(
'hash1' => $this->generateValidationHash($code),
'hash2' => $this->generateValidationHash(strtolower($code)),
// we add a random 'v' parameter so that FireFox can refresh the image
// when src attribute of image tag is changed
'url' => $this->controller->createUrl($this->id, array('v' => uniqid())),
'url' => $controller->createUrl($this->id, array('v' => uniqid())),
));
} else {
$this->setHttpHeaders();
@ -153,7 +154,7 @@ class CaptchaAction extends Action
return $this->fixedVerifyCode;
}
$session = Yii::$app->session;
$session = Yii::$app->getSession();
$session->open();
$name = $this->getSessionKey();
if ($session[$name] === null || $regenerate) {

3
framework/yii/widgets/CaptchaAsset.php → framework/yii/captcha/CaptchaAsset.php

@ -5,7 +5,8 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
namespace yii\captcha;
use yii\web\AssetBundle;
/**

6
framework/yii/validators/CaptchaValidator.php → framework/yii/captcha/CaptchaValidator.php

@ -5,11 +5,13 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\validators;
namespace yii\captcha;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\validators\ValidationAsset;
use yii\validators\Validator;
/**
* CaptchaValidator validates that the attribute value is the same as the verification code displayed in the CAPTCHA.
@ -74,7 +76,7 @@ class CaptchaValidator extends Validator
/**
* Returns the CAPTCHA action object.
* @throws InvalidConfigException
* @return \yii\web\CaptchaAction the action object
* @return \yii\captcha\CaptchaAction the action object
*/
public function getCaptchaAction()
{

0
framework/yii/web/SpicyRice.md → framework/yii/captcha/SpicyRice.md

0
framework/yii/web/SpicyRice.ttf → framework/yii/captcha/SpicyRice.ttf

16
framework/yii/classes.php

@ -91,6 +91,10 @@ return array(
'yii\caching\WinCache' => YII_PATH . '/caching/WinCache.php',
'yii\caching\XCache' => YII_PATH . '/caching/XCache.php',
'yii\caching\ZendDataCache' => YII_PATH . '/caching/ZendDataCache.php',
'yii\captcha\Captcha' => YII_PATH . '/captcha/Captcha.php',
'yii\captcha\CaptchaAction' => YII_PATH . '/captcha/CaptchaAction.php',
'yii\captcha\CaptchaAsset' => YII_PATH . '/captcha/CaptchaAsset.php',
'yii\captcha\CaptchaValidator' => YII_PATH . '/captcha/CaptchaValidator.php',
'yii\data\ActiveDataProvider' => YII_PATH . '/data/ActiveDataProvider.php',
'yii\data\ArrayDataProvider' => YII_PATH . '/data/ArrayDataProvider.php',
'yii\data\DataProvider' => YII_PATH . '/data/DataProvider.php',
@ -167,7 +171,6 @@ return array(
'yii\rbac\PhpManager' => YII_PATH . '/rbac/PhpManager.php',
'yii\requirements\YiiRequirementChecker' => YII_PATH . '/requirements/YiiRequirementChecker.php',
'yii\validators\BooleanValidator' => YII_PATH . '/validators/BooleanValidator.php',
'yii\validators\CaptchaValidator' => YII_PATH . '/validators/CaptchaValidator.php',
'yii\validators\CompareValidator' => YII_PATH . '/validators/CompareValidator.php',
'yii\validators\DateValidator' => YII_PATH . '/validators/DateValidator.php',
'yii\validators\DefaultValueValidator' => YII_PATH . '/validators/DefaultValueValidator.php',
@ -193,7 +196,6 @@ return array(
'yii\web\AssetConverter' => YII_PATH . '/web/AssetConverter.php',
'yii\web\AssetManager' => YII_PATH . '/web/AssetManager.php',
'yii\web\CacheSession' => YII_PATH . '/web/CacheSession.php',
'yii\web\CaptchaAction' => YII_PATH . '/web/CaptchaAction.php',
'yii\web\Controller' => YII_PATH . '/web/Controller.php',
'yii\web\Cookie' => YII_PATH . '/web/Cookie.php',
'yii\web\CookieCollection' => YII_PATH . '/web/CookieCollection.php',
@ -225,14 +227,18 @@ return array(
'yii\widgets\ActiveFormAsset' => YII_PATH . '/widgets/ActiveFormAsset.php',
'yii\widgets\Block' => YII_PATH . '/widgets/Block.php',
'yii\widgets\Breadcrumbs' => YII_PATH . '/widgets/Breadcrumbs.php',
'yii\widgets\Captcha' => YII_PATH . '/widgets/Captcha.php',
'yii\widgets\CaptchaAsset' => YII_PATH . '/widgets/CaptchaAsset.php',
'yii\widgets\ContentDecorator' => YII_PATH . '/widgets/ContentDecorator.php',
'yii\widgets\DetailView' => YII_PATH . '/widgets/DetailView.php',
'yii\widgets\FragmentCache' => YII_PATH . '/widgets/FragmentCache.php',
'yii\widgets\grid\CheckboxColumn' => YII_PATH . '/widgets/grid/CheckboxColumn.php',
'yii\widgets\grid\Column' => YII_PATH . '/widgets/grid/Column.php',
'yii\widgets\grid\DataColumn' => YII_PATH . '/widgets/grid/DataColumn.php',
'yii\widgets\GridView' => YII_PATH . '/widgets/GridView.php',
'yii\widgets\InputWidget' => YII_PATH . '/widgets/InputWidget.php',
'yii\widgets\LinkPager' => YII_PATH . '/widgets/LinkPager.php',
'yii\widgets\ListPager' => YII_PATH . '/widgets/ListPager.php',
'yii\widgets\LinkSorter' => YII_PATH . '/widgets/LinkSorter.php',
'yii\widgets\ListView' => YII_PATH . '/widgets/ListView.php',
'yii\widgets\ListViewBase' => YII_PATH . '/widgets/ListViewBase.php',
'yii\widgets\MaskedInput' => YII_PATH . '/widgets/MaskedInput.php',
'yii\widgets\MaskedInputAsset' => YII_PATH . '/widgets/MaskedInputAsset.php',
'yii\widgets\Menu' => YII_PATH . '/widgets/Menu.php',

2
framework/yii/validators/Validator.php

@ -49,7 +49,7 @@ abstract class Validator extends Component
*/
public static $builtInValidators = array(
'boolean' => 'yii\validators\BooleanValidator',
'captcha' => 'yii\validators\CaptchaValidator',
'captcha' => 'yii\captcha\CaptchaValidator',
'compare' => 'yii\validators\CompareValidator',
'date' => 'yii\validators\DateValidator',
'default' => 'yii\validators\DefaultValueValidator',

2
tests/unit/data/base/Singer.php

@ -15,7 +15,7 @@ class Singer extends Model
return array(
array('lastName', 'default', 'value' => 'Lennon'),
array('lastName', 'required'),
array('underscore_style', 'yii\validators\CaptchaValidator'),
array('underscore_style', 'yii\captcha\CaptchaValidator'),
);
}
}

Loading…
Cancel
Save