リビジョン b3a58ce1
app/Config/bootstrap.php | ||
---|---|---|
90 | 90 |
* |
91 | 91 |
* )); |
92 | 92 |
*/ |
93 |
Configure::write('Recaptcha.publicKey', 'your-public-api-key'); |
|
94 |
Configure::write('Recaptcha.privateKey', 'your-private-api-key'); |
|
93 | 95 |
Configure::write('Dispatcher.filters', array( |
94 | 96 |
'AssetDispatcher', |
95 | 97 |
'CacheDispatcher' |
app/Controller/AppController.php | ||
---|---|---|
45 | 45 |
'Auth' => array( |
46 | 46 |
'loginRedirect' => array( |
47 | 47 |
'controller' => 'users', |
48 |
'action' => 'index'
|
|
48 |
'action' => 'login_top'
|
|
49 | 49 |
), |
50 | 50 |
'logoutRedirect' => array( |
51 | 51 |
'controller' => 'users', |
app/Controller/ProgramsController.php | ||
---|---|---|
1 |
<?php |
|
2 |
App::uses('AppController', 'Controller'); |
|
3 |
/** |
|
4 |
* Programs Controller |
|
5 |
* |
|
6 |
* @property Program $Program |
|
7 |
* @property PaginatorComponent $Paginator |
|
8 |
*/ |
|
9 |
class ProgramsController extends AppController { |
|
10 |
|
|
11 |
public $layout = 'procedure'; |
|
12 |
|
|
13 |
/** |
|
14 |
* Components |
|
15 |
* |
|
16 |
* @var array |
|
17 |
*/ |
|
18 |
public $components = array('Paginator'); |
|
19 |
|
|
20 |
/** |
|
21 |
* index method |
|
22 |
* |
|
23 |
* @return void |
|
24 |
*/ |
|
25 |
public function index() { |
|
26 |
$this->Program->recursive = 0; |
|
27 |
$user_id = $this->Session->read('Auth.User.id'); |
|
28 |
// if (!$this->Program->exists($id)) { |
|
29 |
// throw new NotFoundException(__('Invalid program')); |
|
30 |
// } |
|
31 |
$options = array('conditions' => array('Program.user_id' => $user_id)); |
|
32 |
$this->set('programs', $this->Program->find('all', $options)); |
|
33 |
$this->set('countprograms', $this->Program->find('count', $options)); |
|
34 |
|
|
35 |
|
|
36 |
// $this->set('programs', $this->Paginator->paginate()); |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* view method |
|
41 |
* |
|
42 |
* @throws NotFoundException |
|
43 |
* @param string $id |
|
44 |
* @return void |
|
45 |
*/ |
|
46 |
public function view($id = null) { |
|
47 |
if (!$this->Program->exists($id)) { |
|
48 |
throw new NotFoundException(__('Invalid program')); |
|
49 |
} |
|
50 |
$options = array('conditions' => array('Program.' . $this->Program->primaryKey => $id)); |
|
51 |
$this->set('program', $this->Program->find('first', $options)); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* add method |
|
56 |
* |
|
57 |
* @return void |
|
58 |
*/ |
|
59 |
|
|
60 |
|
|
61 |
public function add() { |
|
62 |
if ($this->request->is('post')) { |
|
63 |
$this->Program->create(); |
|
64 |
if ($this->Program->save($this->request->data)) { |
|
65 |
$this->Flash->success(__('The program has been saved.')); |
|
66 |
return $this->redirect(array('action' => 'index')); |
|
67 |
} else { |
|
68 |
$this->Flash->error(__('The program could not be saved. Please, try again.')); |
|
69 |
} |
|
70 |
} |
|
71 |
$users = $this->Program->User->find('list'); |
|
72 |
$this->set(compact('users')); |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* edit method |
|
77 |
* |
|
78 |
* @throws NotFoundException |
|
79 |
* @param string $id |
|
80 |
* @return void |
|
81 |
*/ |
|
82 |
public function edit($id = null) { |
|
83 |
if (!$this->Program->exists($id)) { |
|
84 |
throw new NotFoundException(__('Invalid program')); |
|
85 |
} |
|
86 |
if ($this->request->is(array('post', 'put'))) { |
|
87 |
if ($this->Program->save($this->request->data)) { |
|
88 |
$this->Flash->success(__('The program has been saved.')); |
|
89 |
return $this->redirect(array('action' => 'index')); |
|
90 |
} else { |
|
91 |
$this->Flash->error(__('The program could not be saved. Please, try again.')); |
|
92 |
} |
|
93 |
} else { |
|
94 |
$options = array('conditions' => array('Program.' . $this->Program->primaryKey => $id)); |
|
95 |
$this->request->data = $this->Program->find('first', $options); |
|
96 |
} |
|
97 |
$users = $this->Program->User->find('list'); |
|
98 |
$this->set(compact('users')); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* delete method |
|
103 |
* |
|
104 |
* @throws NotFoundException |
|
105 |
* @param string $id |
|
106 |
* @return void |
|
107 |
*/ |
|
108 |
public function delete($id = null) { |
|
109 |
$this->Program->id = $id; |
|
110 |
if (!$this->Program->exists()) { |
|
111 |
throw new NotFoundException(__('Invalid program')); |
|
112 |
} |
|
113 |
$this->request->allowMethod('post', 'delete'); |
|
114 |
if ($this->Program->delete()) { |
|
115 |
$this->Flash->success(__('The program has been deleted.')); |
|
116 |
} else { |
|
117 |
$this->Flash->error(__('The program could not be deleted. Please, try again.')); |
|
118 |
} |
|
119 |
return $this->redirect(array('action' => 'index')); |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
|
app/Controller/TopController.php | ||
---|---|---|
37 | 37 |
* @var array |
38 | 38 |
*/ |
39 | 39 |
var $name = 'top'; |
40 |
public $uses = array('ContactValidate'); |
|
40 |
public $uses = array('ContactValidate','Zipcode');
|
|
41 | 41 |
public $layout = 'procedure'; |
42 | 42 |
|
43 | 43 |
function beforeFilter(){ |
... | ... | |
69 | 69 |
public function company() { |
70 | 70 |
} |
71 | 71 |
/** |
72 |
* mypage |
|
73 |
*/ |
|
74 |
public function mypage() { |
|
75 |
} |
|
76 |
/** |
|
77 |
* howto |
|
78 |
*/ |
|
79 |
public function howto() { |
|
80 |
} |
|
81 |
/** |
|
72 | 82 |
* contact |
73 | 83 |
*/ |
74 | 84 |
public function contact() { |
... | ... | |
97 | 107 |
public function contact_complete() { |
98 | 108 |
$this->set('contact',$this->Session->read('contact')); |
99 | 109 |
$name = $this->Session->read('contact.ContactValidate.name'); |
100 |
$mail = $this->Session->read('contact.ContactValidate.mail'); |
|
110 |
$mail = $this->Session->read('contact.ContactValidate.email');
|
|
101 | 111 |
$comment = $this->Session->read('contact.ContactValidate.comment'); |
102 | 112 |
$Email = new CakeEmail(); |
103 | 113 |
$Email->charset('ISO-2022-JP'); |
104 | 114 |
$Email->emailFormat('text'); |
105 | 115 |
$Email->template('user_contact'); |
106 | 116 |
$Email->viewVars(array('name'=>$name,'comment'=>$comment)); |
107 |
$Email->from($mail);
|
|
108 |
$Email->to('yano@i-hearts.jp');
|
|
117 |
$Email->from('yano@i-hearts.jp');
|
|
118 |
$Email->to($mail);
|
|
109 | 119 |
$Email->subject('[PICT CODE]問い合わせ'); |
110 | 120 |
$Email->send(); |
111 | 121 |
} |
122 |
|
|
123 |
|
|
124 |
/** |
|
125 |
*郵便番号から住所を自動入力する* |
|
126 |
* |
|
127 |
* View/add.ctp |
|
128 |
*/ |
|
129 |
public function zipsearch() { |
|
130 |
App::import('Model','ConnectionManager'); |
|
131 |
$db =ConnectionManager::getDataSource('default'); |
|
132 |
|
|
133 |
//Users/zipsearch.ctpを自動で見に行くのを防止 |
|
134 |
$this->autoRender = false; |
|
135 |
|
|
136 |
//リクエストがajaxメソッドで送られてきた場合 |
|
137 |
if($this->request->is('ajax')) { |
|
138 |
|
|
139 |
//formのパラメータ取得 |
|
140 |
$post = $this->request->data['ContactValidate']['postcode']; |
|
141 |
// var_dump($post); |
|
142 |
// exit; |
|
143 |
// $options = array( |
|
144 |
// 'conditions'=>array( |
|
145 |
// 'postcode like' => $post.'%' , |
|
146 |
// ) |
|
147 |
// ); |
|
148 |
$result = $db->query('select * from zipcodes where postcode like "'.$post.'%" limit 1'); |
|
149 |
|
|
150 |
// データをjsonに変換して出力 |
|
151 |
echo json_encode($result); |
|
152 |
|
|
153 |
} |
|
154 |
} |
|
155 |
|
|
112 | 156 |
} |
app/Controller/UsersController.php | ||
---|---|---|
22 | 22 |
* |
23 | 23 |
* @var array |
24 | 24 |
*/ |
25 |
public $components = array('Paginator'); |
|
25 |
public $components = array('Paginator','Recaptcha.Recaptcha');
|
|
26 | 26 |
|
27 | 27 |
/** |
28 | 28 |
* index method |
... | ... | |
206 | 206 |
if ($this->Auth->login()) { |
207 | 207 |
$this->redirect('/Users/login_top'); |
208 | 208 |
} else { |
209 |
$this->Flash->error(__('error')); |
|
209 |
$this->Flash->loginerror('ニックネームか パスワードにまちがいが あるよ!', array( |
|
210 |
'key' => 'positive', |
|
211 |
)); |
|
212 |
//$this->Flash->error(__('error')); |
|
210 | 213 |
// $this->Flash->error(__('<section class="caution"><p>ニックネームか パスワードに<br>まちがいが あるよ!</p></section>')); |
211 | 214 |
} |
212 | 215 |
} |
app/Model/ContactValidate.php | ||
---|---|---|
7 | 7 |
class ContactValidate extends AppModel { |
8 | 8 |
|
9 | 9 |
public $useTable = false; |
10 |
var $name = 'ContactValidate';
|
|
10 |
public $name = 'ContactValidate';
|
|
11 | 11 |
|
12 | 12 |
public $_schema = array( |
13 | 13 |
'name' => array( |
... | ... | |
36 | 36 |
'message' => '入力されていません', |
37 | 37 |
), |
38 | 38 |
), |
39 |
'mail' => array( |
|
39 |
'email' => array(
|
|
40 | 40 |
'notblank' => array( |
41 | 41 |
'rule' => array('notBlank'), |
42 | 42 |
'message' => '入力されていません', |
app/Plugin/Recaptcha/.semver | ||
---|---|---|
1 |
--- |
|
2 |
:major: 2 |
|
3 |
:minor: 2 |
|
4 |
:patch: 4 |
|
5 |
:special: '' |
app/Plugin/Recaptcha/CHANGELOG.md | ||
---|---|---|
1 |
Changelog |
|
2 |
========= |
|
3 |
|
|
4 |
Release 2.2.4 |
|
5 |
------------- |
|
6 |
|
|
7 |
https://github.com/CakeDC/recaptcha/tree/2.2.4 |
|
8 |
|
|
9 |
* [f8459df](https://github.com/CakeDC/recaptcha/commit/f8459df) Formatting some code in Setup.md and updating semver |
|
10 |
* [c2c88a8](https://github.com/CakeDC/recaptcha/commit/c2c88a8) Fixing the installation instructions |
|
11 |
|
|
12 |
Release 2.2.3 |
|
13 |
------------- |
|
14 |
|
|
15 |
https://github.com/CakeDC/recaptcha/tree/2.2.3 |
|
16 |
|
|
17 |
* [ad72132](https://github.com/CakeDC/recaptcha/commit/ad72132) Adding semver |
|
18 |
* [c968276](https://github.com/CakeDC/recaptcha/commit/c968276) Naming a few files uppercased to refelect the plugin standard. |
|
19 |
* [8f5d6c0](https://github.com/CakeDC/recaptcha/commit/8f5d6c0) Fixing the headline of the readme.md |
|
20 |
* [74047b7](https://github.com/CakeDC/recaptcha/commit/74047b7) Working on updating the plugin to the new plugin standard |
|
21 |
* [741cc11](https://github.com/CakeDC/recaptcha/commit/741cc11) Use strict comparison |
|
22 |
* [e3344bd](https://github.com/CakeDC/recaptcha/commit/e3344bd) Cs fixes |
app/Plugin/Recaptcha/CONTRIBUTING.md | ||
---|---|---|
1 |
Contributing |
|
2 |
============ |
|
3 |
|
|
4 |
This repository follows the [CakeDC Plugin Standard](http://cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](http://cakedc.com/contribution-guidelines) for detailed instructions. |
app/Plugin/Recaptcha/Controller/Component/RecaptchaComponent.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
4 |
* |
|
5 |
* Licensed under The MIT License |
|
6 |
* Redistributions of files must retain the above copyright notice. |
|
7 |
* |
|
8 |
* @copyright Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
9 |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
*/ |
|
11 |
|
|
12 |
App::uses('HttpSocket', 'Network/Http'); |
|
13 |
|
|
14 |
/** |
|
15 |
* CakePHP Recaptcha component |
|
16 |
* |
|
17 |
* @package recaptcha |
|
18 |
* @subpackage recaptcha.controllers.components |
|
19 |
*/ |
|
20 |
|
|
21 |
class RecaptchaComponent extends Component { |
|
22 |
|
|
23 |
/** |
|
24 |
* Name |
|
25 |
* |
|
26 |
* @var string |
|
27 |
*/ |
|
28 |
public $Controller = null; |
|
29 |
|
|
30 |
/** |
|
31 |
* Recaptcha API Url |
|
32 |
* |
|
33 |
* @var string |
|
34 |
*/ |
|
35 |
public $apiUrl = 'http://www.google.com/recaptcha/api/verify'; |
|
36 |
|
|
37 |
/** |
|
38 |
* Private API Key |
|
39 |
* |
|
40 |
* @var string |
|
41 |
*/ |
|
42 |
public $privateKey = ''; |
|
43 |
|
|
44 |
/** |
|
45 |
* Error coming back from Recaptcha |
|
46 |
* |
|
47 |
* @var string |
|
48 |
*/ |
|
49 |
public $error = null; |
|
50 |
|
|
51 |
/** |
|
52 |
* Actions that should automatically checked for a recaptcha input |
|
53 |
* |
|
54 |
* @var array |
|
55 |
*/ |
|
56 |
public $actions = array(); |
|
57 |
|
|
58 |
/** |
|
59 |
* Settings |
|
60 |
* |
|
61 |
* @var array |
|
62 |
*/ |
|
63 |
public $settings = array(); |
|
64 |
|
|
65 |
/** |
|
66 |
* Default Options |
|
67 |
* |
|
68 |
* @var array |
|
69 |
*/ |
|
70 |
protected $_defaults = array( |
|
71 |
'errorField' => 'recaptcha', |
|
72 |
'actions' => array() |
|
73 |
); |
|
74 |
|
|
75 |
/** |
|
76 |
* Constructor |
|
77 |
* |
|
78 |
* @param ComponentCollection $collection A ComponentCollection this component can use to lazy load its components |
|
79 |
* @param array $settings Array of configuration settings |
|
80 |
* @return RecaptchaComponent |
|
81 |
*/ |
|
82 |
public function __construct(ComponentCollection $collection, $settings = array()) { |
|
83 |
parent::__construct($collection, $settings); |
|
84 |
$this->Controller = $collection->getController(); |
|
85 |
$this->_defaults['modelClass'] = $this->Controller->modelClass; |
|
86 |
$this->settings = array_merge($this->_defaults, $settings); |
|
87 |
$this->actions = array_merge($this->actions, $this->settings['actions']); |
|
88 |
unset($this->settings['actions']); |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Callback |
|
93 |
* |
|
94 |
* @param Controller $controller Controller with components to initialize |
|
95 |
* @param array $settings Array of configuration settings |
|
96 |
* @throws Exception Throws an exception if Recaptchas config is not present |
|
97 |
* @return void |
|
98 |
*/ |
|
99 |
public function initialize(Controller $controller, $settings = array()) { |
|
100 |
if ($controller->name === 'CakeError') { |
|
101 |
return; |
|
102 |
} |
|
103 |
$this->privateKey = Configure::read('Recaptcha.privateKey'); |
|
104 |
$this->Controller = $controller; |
|
105 |
|
|
106 |
if (!isset($this->Controller->helpers['Recaptcha.Recaptcha'])) { |
|
107 |
$this->Controller->helpers[] = 'Recaptcha.Recaptcha'; |
|
108 |
} |
|
109 |
|
|
110 |
if (empty($this->privateKey)) { |
|
111 |
throw new Exception(__d('recaptcha', "You must set your private Recaptcha key using Configure::write('Recaptcha.privateKey', 'your-key');!", true)); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Callback |
|
117 |
* |
|
118 |
* @param Controller $controller Controller with components to initialize |
|
119 |
* @return void |
|
120 |
*/ |
|
121 |
public function startup(Controller $controller) { |
|
122 |
extract($this->settings); |
|
123 |
$this->Controller->helpers[] = 'Recaptcha.Recaptcha'; |
|
124 |
$this->Controller->{$modelClass}->Behaviors->load('Recaptcha.Recaptcha', array( |
|
125 |
'field' => $errorField |
|
126 |
)); |
|
127 |
|
|
128 |
$this->Controller->{$modelClass}->recaptcha = true; |
|
129 |
if (in_array($this->Controller->action, $this->actions)) { |
|
130 |
if (!$this->verify()) { |
|
131 |
$this->Controller->{$modelClass}->recaptcha = false; |
|
132 |
$this->Controller->{$modelClass}->recaptchaError = $this->error; |
|
133 |
} |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Verifies the recaptcha input |
|
139 |
* |
|
140 |
* Please note that you still have to pass the result to the model and do |
|
141 |
* the validation there to make sure the data is not saved! |
|
142 |
* |
|
143 |
* @return boolean True if the response was correct |
|
144 |
*/ |
|
145 |
public function verify() { |
|
146 |
if (isset($this->Controller->request->data['recaptcha_challenge_field']) && |
|
147 |
isset($this->Controller->request->data['recaptcha_response_field'])) { |
|
148 |
|
|
149 |
$response = $this->_getApiResponse(); |
|
150 |
$response = explode("\n", $response->body()); |
|
151 |
|
|
152 |
if (empty($response[0])) { |
|
153 |
$this->error = __d('recaptcha', 'Invalid API response, please contact the site admin.', true); |
|
154 |
return false; |
|
155 |
} |
|
156 |
|
|
157 |
if ($response[0] === 'true') { |
|
158 |
return true; |
|
159 |
} |
|
160 |
|
|
161 |
if ($response[1] === 'incorrect-captcha-sol') { |
|
162 |
$this->error = __d('recaptcha', 'Incorrect captcha', true); |
|
163 |
} else { |
|
164 |
$this->error = $response[1]; |
|
165 |
} |
|
166 |
} |
|
167 |
return false; |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Queries the Recaptcha API and and returns the raw response |
|
172 |
* |
|
173 |
* @return string |
|
174 |
*/ |
|
175 |
protected function _getApiResponse() { |
|
176 |
$Socket = new HttpSocket(); |
|
177 |
return $Socket->post($this->apiUrl, array( |
|
178 |
'privatekey' => $this->privateKey, |
|
179 |
'remoteip' => env('REMOTE_ADDR'), |
|
180 |
'challenge' => $this->Controller->request->data['recaptcha_challenge_field'], |
|
181 |
'response' => $this->Controller->request->data['recaptcha_response_field'] |
|
182 |
)); |
|
183 |
} |
|
184 |
|
|
185 |
} |
app/Plugin/Recaptcha/Docs/Documentation/Installation.md | ||
---|---|---|
1 |
Installation |
|
2 |
============ |
|
3 |
|
|
4 |
To install the plugin, place the files in a directory labelled "Recaptcha/" in your "app/Plugin/" directory. |
|
5 |
|
|
6 |
Git Submodule |
|
7 |
------------- |
|
8 |
|
|
9 |
If you're using git for version control, you may want to add the **Recaptcha** plugin as a submodule on your repository. To do so, run the following command from the base of your repository: |
|
10 |
|
|
11 |
``` |
|
12 |
git submodule add git@github.com:CakeDC/recaptcha.git app/Plugin/Recaptcha |
|
13 |
``` |
|
14 |
|
|
15 |
After doing so, you will see the submodule in your changes pending, plus the file ".gitmodules". Simply commit and push to your repository. |
|
16 |
|
|
17 |
To initialize the submodule(s) run the following command: |
|
18 |
|
|
19 |
``` |
|
20 |
git submodule update --init --recursive |
|
21 |
``` |
|
22 |
|
|
23 |
To retreive the latest updates to the plugin, assuming you're using the "master" branch, go to "app/Plugin/Recaptcha" and run the following command: |
|
24 |
|
|
25 |
``` |
|
26 |
git pull origin master |
|
27 |
``` |
|
28 |
|
|
29 |
If you're using another branch, just change "master" for the branch you are currently using. |
|
30 |
|
|
31 |
If any updates are added, go back to the base of your own repository, commit and push your changes. This will update your repository to point to the latest updates to the plugin. |
|
32 |
|
|
33 |
Composer |
|
34 |
-------- |
|
35 |
|
|
36 |
The plugin also provides a "composer.json" file, to easily use the plugin through the Composer dependency manager. |
app/Plugin/Recaptcha/Docs/Documentation/Setup.md | ||
---|---|---|
1 |
Setup |
|
2 |
===== |
|
3 |
|
|
4 |
To use the recaptcha plugin its required to include the following two lines in your `/app/Config/bootstrap.php` file. |
|
5 |
|
|
6 |
```php |
|
7 |
Configure::write('Recaptcha.publicKey', 'your-public-api-key'); |
|
8 |
Configure::write('Recaptcha.privateKey', 'your-private-api-key'); |
|
9 |
``` |
|
10 |
|
|
11 |
Don't forget to replace the placeholder text with your actual keys! |
|
12 |
|
|
13 |
Keys can be obtained for free from the [Recaptcha website](http://www.google.com/recaptcha). |
|
14 |
|
|
15 |
Controllers that will be using recaptcha require the Recaptcha Component to be included. Through inclusion of the component, the helper is automatically made available to your views. |
|
16 |
|
|
17 |
```php |
|
18 |
public $components = array('Recaptcha.Recaptcha'); |
|
19 |
``` |
|
20 |
In the view simply call the helpers `display()` method to render the recaptcha input: |
|
21 |
|
|
22 |
```php |
|
23 |
echo $this->Recaptcha->display(); |
|
24 |
``` |
|
25 |
|
|
26 |
You could select another theme, setup it as parameter, for istance: |
|
27 |
|
|
28 |
```php |
|
29 |
echo $this->Recaptcha->display(array( |
|
30 |
'recaptchaOptions' => array( |
|
31 |
'theme' => 'blackglass' |
|
32 |
) |
|
33 |
) |
|
34 |
); |
|
35 |
``` |
|
36 |
|
|
37 |
For the complete list of themes, take a look here: [http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html](http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html). |
|
38 |
|
|
39 |
To check the result simply do something like this in your controller: |
|
40 |
|
|
41 |
```php |
|
42 |
if ($this->request->is('post')) { |
|
43 |
if ($this->Recaptcha->verify()) { |
|
44 |
// do something, save you data, login, whatever |
|
45 |
} else { |
|
46 |
// display the raw API error |
|
47 |
$this->Session->setFlash($this->Recaptcha->error); |
|
48 |
} |
|
49 |
} |
|
50 |
```` |
app/Plugin/Recaptcha/Docs/Home.md | ||
---|---|---|
1 |
Home |
|
2 |
==== |
|
3 |
|
|
4 |
The **Recaptcha** plugin for CakePHP provides spam protection in an easy use helper. |
|
5 |
|
|
6 |
Requirements |
|
7 |
------------ |
|
8 |
|
|
9 |
* CakePHP 2.5+ |
|
10 |
* PHP 5.2.8+ |
|
11 |
|
|
12 |
Documentation |
|
13 |
------------- |
|
14 |
|
|
15 |
* [Installation](Documentation/Installation.md) |
|
16 |
* [Setup](Documentation/Setup.md) |
app/Plugin/Recaptcha/LICENSE.txt | ||
---|---|---|
1 |
The MIT License |
|
2 |
|
|
3 |
Copyright 2007 - 2014, Cake Development Corporation |
|
4 |
1785 E. Sahara Avenue, Suite 490-423 |
|
5 |
Las Vegas, Nevada 89104 |
|
6 |
http://cakedc.com |
|
7 |
|
|
8 |
Permission is hereby granted, free of charge, to any person obtaining a |
|
9 |
copy of this software and associated documentation files (the "Software"), |
|
10 |
to deal in the Software without restriction, including without limitation |
|
11 |
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
12 |
and/or sell copies of the Software, and to permit persons to whom the |
|
13 |
Software is furnished to do so, subject to the following conditions: |
|
14 |
|
|
15 |
The above copyright notice and this permission notice shall be included in |
|
16 |
all copies or substantial portions of the Software. |
|
17 |
|
|
18 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
24 |
DEALINGS IN THE SOFTWARE. |
app/Plugin/Recaptcha/Locale/deu/LC_MESSAGES/recaptcha.po | ||
---|---|---|
1 |
msgid "" |
|
2 |
msgstr "" |
|
3 |
"Project-Id-Version: CakePHP Recaptcha Plugin\n" |
|
4 |
"POT-Creation-Date: 2012-11-19 16:23+0100\n" |
|
5 |
"PO-Revision-Date: \n" |
|
6 |
"Last-Translator: Stéphane BENOIST <stephane@occi-tech.com>\n" |
|
7 |
"Language-Team: media-n <info@media-n.net>\n" |
|
8 |
"Language: \n" |
|
9 |
"MIME-Version: 1.0\n" |
|
10 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
11 |
"Content-Transfer-Encoding: 8bit\n" |
|
12 |
"X-Poedit-Language: German\n" |
|
13 |
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|
14 |
"X-Poedit-Country: GERMANY\n" |
|
15 |
|
|
16 |
#: Controller/Component/RecaptchaComponent.php:108 |
|
17 |
msgid "You must set your private recaptcha key using Configure::write('Recaptcha.privateKey', 'your-key');!" |
|
18 |
msgstr "Sie müssen Ihren privaten Recaptcha Schlüssel setzen in Configure::write('Recaptcha.privateKey', 'your-key');!" |
|
19 |
|
|
20 |
#: Controller/Component/RecaptchaComponent.php:152 |
|
21 |
msgid "Invalid API response, please contact the site admin." |
|
22 |
msgstr "Ungültige API Antwort, kontaktieren Sie bitte die Website admin." |
|
23 |
|
|
24 |
#: Controller/Component/RecaptchaComponent.php:161 |
|
25 |
msgid "Incorrect captcha" |
|
26 |
msgstr "Falsche captcha" |
|
27 |
|
|
28 |
#: View/Helper/RecaptchaHelper.php:177 |
|
29 |
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed." |
|
30 |
msgstr "Um reCAPTCHA Mailhide nutzen zu können muss das mcrypt PHP-Modul installiert werden." |
|
31 |
|
|
32 |
#: View/Helper/RecaptchaHelper.php:207 |
|
33 |
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey" |
|
34 |
msgstr "Es muss ein privater und öffentlicher mail hide Schlüssel erstellt werden. Bitte besuchen Sie: http://mailhide.recaptcha.net/apikey" |
|
35 |
|
app/Plugin/Recaptcha/Locale/fre/LC_MESSAGES/recaptcha.po | ||
---|---|---|
1 |
msgid "" |
|
2 |
msgstr "" |
|
3 |
"Project-Id-Version: CakePHP Recaptcha Plugin\n" |
|
4 |
"POT-Creation-Date: 2012-11-19 16:23+0100\n" |
|
5 |
"PO-Revision-Date: \n" |
|
6 |
"Last-Translator: Stéphane BENOIST <stephane@occi-tech.com>\n" |
|
7 |
"Language-Team: CakeDC <contact@cakedc.com>\n" |
|
8 |
"Language: \n" |
|
9 |
"MIME-Version: 1.0\n" |
|
10 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
11 |
"Content-Transfer-Encoding: 8bit\n" |
|
12 |
"X-Poedit-Language: French\n" |
|
13 |
|
|
14 |
#: Controller/Component/RecaptchaComponent.php:108 |
|
15 |
msgid "You must set your private recaptcha key using Configure::write('Recaptcha.privateKey', 'your-key');!" |
|
16 |
msgstr "Vous devez définir votre clé privée Recaptcha en utilisant Configure::write('Recaptcha.privateKey', 'votre-clé'); !" |
|
17 |
|
|
18 |
#: Controller/Component/RecaptchaComponent.php:152 |
|
19 |
msgid "Invalid API response, please contact the site admin." |
|
20 |
msgstr "Réponse API invalide, contactez l'administrateur du site." |
|
21 |
|
|
22 |
#: Controller/Component/RecaptchaComponent.php:161 |
|
23 |
msgid "Incorrect captcha" |
|
24 |
msgstr "Captcha incorrect" |
|
25 |
|
|
26 |
#: View/Helper/RecaptchaHelper.php:177 |
|
27 |
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed." |
|
28 |
msgstr "Afin d'utiliser reCAPTCHA Mailhide, vous devez avoir le module php mcrypt installé." |
|
29 |
|
|
30 |
#: View/Helper/RecaptchaHelper.php:207 |
|
31 |
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey" |
|
32 |
msgstr "Vous devez définir les clés publique et privée mailhide. Veuillez visiter http://mailhide.recaptcha.net/apikey" |
|
33 |
|
app/Plugin/Recaptcha/Locale/ita/LC_MESSAGES/recaptcha.po | ||
---|---|---|
1 |
# LANGUAGE translation of the CakePHP Categories plugin |
|
2 |
# |
|
3 |
# Copyright 2010, Cake Development Corporation (http://cakedc.com) |
|
4 |
# |
|
5 |
# Licensed under The MIT License |
|
6 |
# Redistributions of files must retain the above copyright notice. |
|
7 |
# |
|
8 |
# @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com) |
|
9 |
# @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
# |
|
11 |
msgid "" |
|
12 |
msgstr "" |
|
13 |
"Project-Id-Version: PROJECT VERSION\n" |
|
14 |
"POT-Creation-Date: 2012-11-19 16:23+0100\n" |
|
15 |
"PO-Revision-Date: 2012-11-19 16:49+0100\n" |
|
16 |
"Last-Translator: Stéphane BENOIST <stephane@occi-tech.com>\n" |
|
17 |
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" |
|
18 |
"Language: \n" |
|
19 |
"MIME-Version: 1.0\n" |
|
20 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
21 |
"Content-Transfer-Encoding: 8bit\n" |
|
22 |
"Plural-Forms: nplurals=2; plural=(n>1);\n" |
|
23 |
"X-Poedit-Language: Italian\n" |
|
24 |
"X-Poedit-Country: ITALY\n" |
|
25 |
|
|
26 |
#: Controller/Component/RecaptchaComponent.php:108 |
|
27 |
msgid "You must set your private recaptcha key using Configure::write('Recaptcha.privateKey', 'your-key');!" |
|
28 |
msgstr "Devi impostare la chiave privata per poter utilizzare reCAPTCHA. Usa: Configure::write('Recaptcha.privateKey', 'chiave');" |
|
29 |
|
|
30 |
#: Controller/Component/RecaptchaComponent.php:152 |
|
31 |
msgid "Invalid API response, please contact the site admin." |
|
32 |
msgstr "" |
|
33 |
|
|
34 |
#: Controller/Component/RecaptchaComponent.php:161 |
|
35 |
msgid "Incorrect captcha" |
|
36 |
msgstr "Captcha non valido" |
|
37 |
|
|
38 |
#: View/Helper/RecaptchaHelper.php:177 |
|
39 |
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed." |
|
40 |
msgstr "Per utilizzare reCAPTCHA Mailhide, devi aver istallato il modulo php mcrypt." |
|
41 |
|
|
42 |
#: View/Helper/RecaptchaHelper.php:207 |
|
43 |
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey" |
|
44 |
msgstr "Devi registrare reCAPTCHA Mailhide API key. http://mailhide.recaptcha.net/apikey" |
|
45 |
|
app/Plugin/Recaptcha/Locale/por/LC_MESSAGES/recaptcha.po | ||
---|---|---|
1 |
# LANGUAGE translation of the CakePHP Categories plugin |
|
2 |
# |
|
3 |
# Copyright 2010, Cake Development Corporation (http://cakedc.com) |
|
4 |
# |
|
5 |
# Licensed under The MIT License |
|
6 |
# Redistributions of files must retain the above copyright notice. |
|
7 |
# |
|
8 |
# @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com) |
|
9 |
# @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
# |
|
11 |
msgid "" |
|
12 |
msgstr "" |
|
13 |
"Project-Id-Version: CakePHP Recaptcha Plugin\n" |
|
14 |
"POT-Creation-Date: 2012-11-19 16:23+0100\n" |
|
15 |
"PO-Revision-Date: 2012-11-19 16:49+0100\n" |
|
16 |
"Last-Translator: Stéphane BENOIST <stephane@occi-tech.com>\n" |
|
17 |
"Language-Team: CakeDC <renan.saddam@gmail.com>\n" |
|
18 |
"Language: \n" |
|
19 |
"MIME-Version: 1.0\n" |
|
20 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
21 |
"Content-Transfer-Encoding: 8bit\n" |
|
22 |
"Plural-Forms: nplurals=2;plural=n>1;\n" |
|
23 |
"X-Poedit-Language: Portuguese\n" |
|
24 |
"X-Poedit-Country: BRAZIL\n" |
|
25 |
|
|
26 |
#: Controller/Component/RecaptchaComponent.php:108 |
|
27 |
msgid "You must set your private recaptcha key using Configure::write('Recaptcha.privateKey', 'your-key');!" |
|
28 |
msgstr "Você deve definir a sua chave privada usando Cofigure::write('Recaptcha.privateKey', 'your-key');!" |
|
29 |
|
|
30 |
#: Controller/Component/RecaptchaComponent.php:152 |
|
31 |
msgid "Invalid API response, please contact the site admin." |
|
32 |
msgstr "" |
|
33 |
|
|
34 |
#: Controller/Component/RecaptchaComponent.php:161 |
|
35 |
msgid "Incorrect captcha" |
|
36 |
msgstr "Captcha incorreto" |
|
37 |
|
|
38 |
#: View/Helper/RecaptchaHelper.php:177 |
|
39 |
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed." |
|
40 |
msgstr "Para usar o reCAPTCHA Mailhide, você precisa ter o módulo php mcrypt instalado." |
|
41 |
|
|
42 |
#: View/Helper/RecaptchaHelper.php:207 |
|
43 |
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey" |
|
44 |
msgstr "Você precisa configurar uma chave privada e pública. Por favor, visite http://mailhide.recaptcha.net/apikey" |
|
45 |
|
app/Plugin/Recaptcha/Locale/recaptcha.pot | ||
---|---|---|
1 |
# LANGUAGE translation of CakePHP Application |
|
2 |
# Copyright YEAR NAME <EMAIL@ADDRESS> |
|
3 |
# |
|
4 |
#, fuzzy |
|
5 |
msgid "" |
|
6 |
msgstr "" |
|
7 |
"Project-Id-Version: PROJECT VERSION\n" |
|
8 |
"POT-Creation-Date: 2012-11-19 16:23+0100\n" |
|
9 |
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" |
|
10 |
"Last-Translator: NAME <EMAIL@ADDRESS>\n" |
|
11 |
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" |
|
12 |
"MIME-Version: 1.0\n" |
|
13 |
"Content-Type: text/plain; charset=utf-8\n" |
|
14 |
"Content-Transfer-Encoding: 8bit\n" |
|
15 |
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" |
|
16 |
|
|
17 |
#: Controller/Component/RecaptchaComponent.php:108 |
|
18 |
msgid "You must set your private recaptcha key using Configure::write('Recaptcha.privateKey', 'your-key');!" |
|
19 |
msgstr "" |
|
20 |
|
|
21 |
#: Controller/Component/RecaptchaComponent.php:152 |
|
22 |
msgid "Invalid API response, please contact the site admin." |
|
23 |
msgstr "" |
|
24 |
|
|
25 |
#: Controller/Component/RecaptchaComponent.php:161 |
|
26 |
msgid "Incorrect captcha" |
|
27 |
msgstr "" |
|
28 |
|
|
29 |
#: View/Helper/RecaptchaHelper.php:177 |
|
30 |
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed." |
|
31 |
msgstr "" |
|
32 |
|
|
33 |
#: View/Helper/RecaptchaHelper.php:207 |
|
34 |
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey" |
|
35 |
msgstr "" |
|
36 |
|
app/Plugin/Recaptcha/Locale/spa/LC_MESSAGES/recaptcha.po | ||
---|---|---|
1 |
msgid "" |
|
2 |
msgstr "" |
|
3 |
"Project-Id-Version: Recaptcha CakePHP plugin\n" |
|
4 |
"POT-Creation-Date: 2012-11-19 16:23+0100\n" |
|
5 |
"PO-Revision-Date: \n" |
|
6 |
"Last-Translator: Stéphane BENOIST <stephane@occi-tech.com>\n" |
|
7 |
"Language-Team: CakeDC <contact@cakedc.com>\n" |
|
8 |
"Language: \n" |
|
9 |
"MIME-Version: 1.0\n" |
|
10 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
11 |
"Content-Transfer-Encoding: 8bit\n" |
|
12 |
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|
13 |
"X-Poedit-Language: Spanish\n" |
|
14 |
"X-Poedit-Country: SPAIN\n" |
|
15 |
|
|
16 |
# LANGUAGE translation of the CakePHP Categories plugin |
|
17 |
# |
|
18 |
# Copyright 2010, Cake Development Corporation (http://cakedc.com) |
|
19 |
# |
|
20 |
# Licensed under The MIT License |
|
21 |
# Redistributions of files must retain the above copyright notice. |
|
22 |
# |
|
23 |
# @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com) |
|
24 |
# @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
25 |
# |
|
26 |
# |
|
27 |
#: Controller/Component/RecaptchaComponent.php:108 |
|
28 |
msgid "You must set your private recaptcha key using Configure::write('Recaptcha.privateKey', 'your-key');!" |
|
29 |
msgstr "Debes configurar tu clave privada de recaptcha usando Configure::write('Recaptcha.privateKey', 'your-key');" |
|
30 |
|
|
31 |
#: Controller/Component/RecaptchaComponent.php:152 |
|
32 |
msgid "Invalid API response, please contact the site admin." |
|
33 |
msgstr "" |
|
34 |
|
|
35 |
#: Controller/Component/RecaptchaComponent.php:161 |
|
36 |
msgid "Incorrect captcha" |
|
37 |
msgstr "Transcripción incorrecta" |
|
38 |
|
|
39 |
#: View/Helper/RecaptchaHelper.php:177 |
|
40 |
msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed." |
|
41 |
msgstr "Para usar la función de oculatar emails de reCAPTCHA , debes tener el modulo mcrypt de php instalado." |
|
42 |
|
|
43 |
#: View/Helper/RecaptchaHelper.php:207 |
|
44 |
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey" |
|
45 |
msgstr "Debes configurar tus claves públicas y privadas de \"mail hide\". Por favor visita http://mailhide.recaptcha.net/apikey" |
|
46 |
|
app/Plugin/Recaptcha/Model/Behavior/RecaptchaBehavior.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
4 |
* |
|
5 |
* Licensed under The MIT License |
|
6 |
* Redistributions of files must retain the above copyright notice. |
|
7 |
* |
|
8 |
* @copyright Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
9 |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
*/ |
|
11 |
|
|
12 |
/** |
|
13 |
* CakePHP Recaptcha Behavior |
|
14 |
* |
|
15 |
* @package recaptcha |
|
16 |
* @subpackage recaptcha.models.behaviors |
|
17 |
*/ |
|
18 |
class RecaptchaBehavior extends ModelBehavior { |
|
19 |
|
|
20 |
/** |
|
21 |
* Settings array |
|
22 |
* |
|
23 |
* @var array |
|
24 |
*/ |
|
25 |
public $settings = array(); |
|
26 |
|
|
27 |
/** |
|
28 |
* Default settings |
|
29 |
* |
|
30 |
* @var array |
|
31 |
*/ |
|
32 |
public $defaults = array( |
|
33 |
'errorField' => 'recaptcha' |
|
34 |
); |
|
35 |
|
|
36 |
/** |
|
37 |
* Setup |
|
38 |
* |
|
39 |
* @param Model $Model Model using this behavior |
|
40 |
* @param array $settings Configuration settings for $model |
|
41 |
* @return void |
|
42 |
*/ |
|
43 |
public function setup(Model $Model, $settings = array()) { |
|
44 |
if (!isset($this->settings[$Model->alias])) { |
|
45 |
$this->settings[$Model->alias] = $this->defaults; |
|
46 |
} |
|
47 |
$this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], (is_array($settings) ? $settings : array())); |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* Validates the captcha responses status set by the component to the model |
|
52 |
* |
|
53 |
* @param Model $Model Model using this behavior |
|
54 |
* @return boolean |
|
55 |
* @see RecaptchaComponent::initialize() |
|
56 |
*/ |
|
57 |
public function validateCaptcha(Model $Model) { |
|
58 |
if (isset($Model->recaptcha) && $Model->recaptcha === false) { |
|
59 |
$Model->invalidate($this->settings[$Model->alias]['errorField'], $Model->recaptchaError); |
|
60 |
} |
|
61 |
return true; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Validates the captcha |
|
66 |
* |
|
67 |
* @param Model $Model Model using this behavior |
|
68 |
* @param array $options Options passed from Model::save() |
|
69 |
* @return void |
|
70 |
*/ |
|
71 |
public function beforeValidate(Model $Model, $options = array()) { |
|
72 |
$this->validateCaptcha($Model); |
|
73 |
return true; |
|
74 |
} |
|
75 |
|
|
76 |
} |
app/Plugin/Recaptcha/README.md | ||
---|---|---|
1 |
CakeDC Recaptcha Plugin |
|
2 |
======================= |
|
3 |
|
|
4 |
The **Recaptcha** plugin for CakePHP provides spam protection in an easy use helper. |
|
5 |
|
|
6 |
Requirements |
|
7 |
------------ |
|
8 |
|
|
9 |
* CakePHP 2.5+ |
|
10 |
* PHP 5.2.8+ |
|
11 |
|
|
12 |
Documentation |
|
13 |
------------- |
|
14 |
|
|
15 |
For documentation, as well as tutorials, see the [Docs](Docs/Home.md) directory of this repository. |
|
16 |
|
|
17 |
Support |
|
18 |
------- |
|
19 |
|
|
20 |
For bugs and feature requests, please use the [issues](https://github.com/CakeDC/recaptcha/issues) section of this repository. |
|
21 |
|
|
22 |
Commercial support is also available, [contact us](http://cakedc.com/contact) for more information. |
|
23 |
|
|
24 |
Contributing |
|
25 |
------------ |
|
26 |
|
|
27 |
This repository follows the [CakeDC Plugin Standard](http://cakedc.com/plugin-standard). If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](http://cakedc.com/contribution-guidelines) for detailed instructions. |
|
28 |
|
|
29 |
License |
|
30 |
------- |
|
31 |
|
|
32 |
Copyright 2007-2014 Cake Development Corporation (CakeDC). All rights reserved. |
|
33 |
|
|
34 |
Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file. |
app/Plugin/Recaptcha/Test/Case/AllRecaptchaTest.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Copyright 2010 - 2014, Cake Development Corporation (http://cakedc.com) |
|
4 |
* |
|
5 |
* Licensed under The MIT License |
|
6 |
* Redistributions of files must retain the above copyright notice. |
|
7 |
* |
|
8 |
* @copyright Copyright 2010 - 2014, Cake Development Corporation (http://cakedc.com) |
|
9 |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
*/ |
|
11 |
|
|
12 |
class AllRecaptchaTest extends PHPUnit_Framework_TestSuite { |
|
13 |
|
|
14 |
/** |
|
15 |
* Suite define the tests for this suite |
|
16 |
* |
|
17 |
* @return void |
|
18 |
*/ |
|
19 |
public static function suite() { |
|
20 |
$Suite = new CakeTestSuite('All Recaptcha Plugin tests'); |
|
21 |
$basePath = CakePlugin::path('Recaptcha') . DS . 'Test' . DS . 'Case' . DS; |
|
22 |
$Suite->addTestDirectory($basePath . DS . 'View' . DS . 'Helper'); |
|
23 |
$Suite->addTestDirectory($basePath . DS . 'Model' . DS . 'Behavior'); |
|
24 |
$Suite->addTestDirectory($basePath . DS . 'Controller' . DS . 'Component'); |
|
25 |
return $Suite; |
|
26 |
} |
|
27 |
|
|
28 |
} |
app/Plugin/Recaptcha/Test/Case/Controller/Component/RecaptchaComponentTest.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
4 |
* |
|
5 |
* Licensed under The MIT License |
|
6 |
* Redistributions of files must retain the above copyright notice. |
|
7 |
* |
|
8 |
* @copyright Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
9 |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
*/ |
|
11 |
|
|
12 |
App::uses('CakeTestCase', 'TestSuite'); |
|
13 |
App::uses('Controller', 'Controller'); |
|
14 |
App::uses('RecaptchaComponent', 'Recaptcha.Controller/Component'); |
|
15 |
|
|
16 |
if (!class_exists('ArticlesTestController')) { |
|
17 |
class ArticleTestController extends Controller { |
|
18 |
|
|
19 |
/** |
|
20 |
* Class name. |
|
21 |
* |
|
22 |
* @var string |
|
23 |
*/ |
|
24 |
public $name = 'ArticleTests'; |
|
25 |
|
|
26 |
/** |
|
27 |
* An array of names of components to load. |
|
28 |
* |
|
29 |
* @var array |
|
30 |
*/ |
|
31 |
public $components = array('Recaptcha.Recaptcha'); |
|
32 |
|
|
33 |
/** |
|
34 |
* An array of names of models to load. |
|
35 |
* |
|
36 |
* @var array |
|
37 |
*/ |
|
38 |
public $uses = array('RecaptchaTestArticle'); |
|
39 |
|
|
40 |
/** |
|
41 |
* |
|
42 |
*/ |
|
43 |
public function test_captcha() { |
|
44 |
} |
|
45 |
|
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
if (!class_exists('RecaptchaTestArticle')) { |
|
50 |
class RecaptchaTestArticle extends CakeTestModel { |
|
51 |
|
|
52 |
/** |
|
53 |
* Class name. |
|
54 |
* |
|
55 |
* @var string |
|
56 |
*/ |
|
57 |
public $name = 'RecaptchaTestArticle'; |
|
58 |
|
|
59 |
/** |
|
60 |
* An array of names of behaviors to load. |
|
61 |
* |
|
62 |
* @var array |
|
63 |
*/ |
|
64 |
public $actsAs = array('Recaptcha.Recaptcha'); |
|
65 |
|
|
66 |
/** |
|
67 |
* Use table. |
|
68 |
* |
|
69 |
* @var mixed False or table name |
|
70 |
*/ |
|
71 |
public $useTable = 'articles'; |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* RecaptchaTestCase |
|
77 |
* |
|
78 |
* @package recaptcha |
|
79 |
* @subpackage recaptcha.tests.cases.components |
|
80 |
*/ |
|
81 |
class RecaptchaComponentTest extends CakeTestCase { |
|
82 |
|
|
83 |
/** |
|
84 |
* fixtures property |
|
85 |
* |
|
86 |
* @var array |
|
87 |
*/ |
|
88 |
public $fixtures = array('plugin.recaptcha.article'); |
|
89 |
|
|
90 |
/** |
|
91 |
* setUp method |
|
92 |
* |
|
93 |
* @return void |
|
94 |
*/ |
|
95 |
public function setUp() { |
|
96 |
parent::setUp(); |
|
97 |
Configure::write('Recaptcha.privateKey', 'private-key'); |
|
98 |
$this->Controller = new ArticleTestController(); |
|
99 |
$this->Controller->constructClasses(); |
|
100 |
$this->Controller->startupProcess(); |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* tearDown method |
|
105 |
* |
|
106 |
* @return void |
|
107 |
*/ |
|
108 |
public function tearDown() { |
|
109 |
unset($this->Controller); |
|
110 |
ClassRegistry::flush(); |
|
111 |
parent::tearDown(); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* testRecaptcha |
|
116 |
* |
|
117 |
* @return void |
|
118 |
*/ |
|
119 |
public function testRecaptcha() { |
|
120 |
$this->Controller->request->data['recaptcha_challenge_field'] = 'something'; |
|
121 |
$this->Controller->request->data['recaptcha_response_field'] = 'something'; |
|
122 |
$this->assertFalse($this->Controller->Recaptcha->verify()); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Checking that the helper was added by the component to the controllers helpers array |
|
127 |
* |
|
128 |
* @link https://github.com/CakeDC/recaptcha/issues/14 |
|
129 |
*/ |
|
130 |
public function testHelperWasLoaded() { |
|
131 |
$this->assertTrue(in_array('Recaptcha.Recaptcha', $this->Controller->helpers)); |
|
132 |
} |
|
133 |
} |
app/Plugin/Recaptcha/Test/Case/Model/Behavior/RecaptchaBehaviorTest.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
4 |
* |
|
5 |
* Licensed under The MIT License |
|
6 |
* Redistributions of files must retain the above copyright notice. |
|
7 |
* |
|
8 |
* @copyright Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
9 |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
*/ |
|
11 |
|
|
12 |
App::uses('RecaptchaBehavior', 'Recaptcha.Model/Behavior'); |
|
13 |
|
|
14 |
/** |
|
15 |
* Slugged Article |
|
16 |
*/ |
|
17 |
class RecaptchaArticle extends CakeTestModel { |
|
18 |
|
|
19 |
/** |
|
20 |
* Class name. |
|
21 |
* |
|
22 |
* @var string |
|
23 |
*/ |
|
24 |
public $name = 'RecaptchaArticle'; |
|
25 |
|
|
26 |
/** |
|
27 |
* An array of names of behaviors to load. |
|
28 |
* |
|
29 |
* @var array |
|
30 |
*/ |
|
31 |
public $actsAs = array('Recaptcha.Recaptcha'); |
|
32 |
|
|
33 |
/** |
|
34 |
* Use table. |
|
35 |
* |
|
36 |
* @var mixed False or table name |
|
37 |
*/ |
|
38 |
public $useTable = 'articles'; |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Recaptcha Test case |
|
43 |
*/ |
|
44 |
class RecaptchaBehaviorTest extends CakeTestCase { |
|
45 |
|
|
46 |
/** |
|
47 |
* fixtures property |
|
48 |
* |
|
49 |
* @var array |
|
50 |
*/ |
|
51 |
public $fixtures = array('plugin.recaptcha.article'); |
|
52 |
|
|
53 |
/** |
|
54 |
* Creates the model instance |
|
55 |
* |
|
56 |
* @return void |
|
57 |
*/ |
|
58 |
public function setUp() { |
|
59 |
$this->Model = new RecaptchaArticle(); |
|
60 |
$this->Behavior = new RecaptchaBehavior(); |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Destroy the model instance |
|
65 |
* |
|
66 |
* @return void |
|
67 |
*/ |
|
68 |
public function tearDown() { |
|
69 |
unset($this->Model); |
|
70 |
unset($this->Behavior); |
|
71 |
ClassRegistry::flush(); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* testValidateCaptcha |
|
76 |
* |
|
77 |
* @return void |
|
78 |
*/ |
|
79 |
public function testValidateCaptcha() { |
|
80 |
$this->Model->validateCaptcha(); |
|
81 |
$result = $this->Model->invalidFields(); |
|
82 |
$this->assertTrue(empty($result)); |
|
83 |
$this->Model->recaptcha = false; |
|
84 |
$this->Model->recaptchaError = 'Invalid Recaptcha'; |
|
85 |
$result = $this->Model->invalidFields(); |
|
86 |
$this->assertEqual($result, array('recaptcha' => array('Invalid Recaptcha'))); |
|
87 |
} |
|
88 |
|
|
89 |
} |
app/Plugin/Recaptcha/Test/Case/View/Helper/RecaptchaHelperTest.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
4 |
* |
|
5 |
* Licensed under The MIT License |
|
6 |
* Redistributions of files must retain the above copyright notice. |
|
7 |
* |
|
8 |
* @copyright Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
9 |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
*/ |
|
11 |
|
|
12 |
App::uses('Controller', 'Controller'); |
|
13 |
App::uses('HtmlHelper', 'View/Helper'); |
|
14 |
App::uses('FormHelper', 'View/Helper'); |
|
15 |
App::uses('RecaptchaHelper', 'Recaptcha.View/Helper'); |
|
16 |
|
|
17 |
/** |
|
18 |
* PostsTestController |
|
19 |
* |
|
20 |
* @package recaptcha |
|
21 |
* @subpackage recaptcha.tests.cases.helper |
|
22 |
*/ |
|
23 |
class PostsTestController extends Controller { |
|
24 |
|
|
25 |
/** |
|
26 |
* name property |
|
27 |
* |
|
28 |
* @var string 'Media' |
|
29 |
*/ |
|
30 |
public $name = 'PostsTest'; |
|
31 |
|
|
32 |
/** |
|
33 |
* uses property |
|
34 |
* |
|
35 |
* @var mixed null |
|
36 |
*/ |
|
37 |
public $uses = null; |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* RecaptchaHelperTest |
|
42 |
* |
|
43 |
* @package recaptcha |
|
44 |
* @subpackage recaptcha.tests.cases.helpers |
|
45 |
*/ |
|
46 |
class RecaptchaHelperTest extends CakeTestCase { |
|
47 |
|
|
48 |
/** |
|
49 |
* setUp method |
|
50 |
* |
|
51 |
* The mailHide keys have to be in a certain format see https://groups.google.com/group/recaptcha/browse_thread/thread/3edc0ad4adc33073?pli=1#msg_73107610db1a1c15 |
|
52 |
* |
|
53 |
* @return void |
|
54 |
*/ |
|
55 |
public function setUp() { |
|
56 |
Configure::write('Recaptcha.mailHide.publicKey', '01J_tiDKknxUV8w-2NbVFNAQ=='); |
|
57 |
Configure::write('Recaptcha.mailHide.privateKey', '411744faf004d447f8208fc51159dc03'); |
|
58 |
|
|
59 |
$this->View = new View(new PostsTestController()); |
|
60 |
ClassRegistry::addObject('view', $this->View); |
|
61 |
$this->Recaptcha = new RecaptchaHelper($this->View); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* tearDown method |
|
66 |
* |
|
67 |
* @return void |
|
68 |
*/ |
|
69 |
public function tearDown() { |
|
70 |
ClassRegistry::flush(); |
|
71 |
unset($this->Recaptcha); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* testDisplay method |
|
76 |
* |
|
77 |
* @return void |
|
78 |
*/ |
|
79 |
public function testDisplay() { |
|
80 |
$expected = '<div class="recaptcha"><script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k="></script> |
|
81 |
<noscript> |
|
82 |
<iframe src="https://www.google.com/recaptcha/api/noscript?k=" height="300" width="500" frameborder="0"></iframe><br/> |
|
83 |
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> |
|
84 |
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> |
|
85 |
</noscript></div>'; |
|
86 |
$result = $this->Recaptcha->display(); |
|
87 |
$this->assertEqual($result, $expected); |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* testSignupUrl method |
|
92 |
* |
|
93 |
* @return void |
|
94 |
*/ |
|
95 |
public function testSignupUrl() { |
|
96 |
$expected = 'http://recaptcha.net/api/getkey?domain=' . WWW_ROOT . 'test-app'; |
|
97 |
$result = $this->Recaptcha->signupUrl('test-app'); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* testSignupUrl method |
|
102 |
* |
|
103 |
* @return void |
|
104 |
*/ |
|
105 |
public function testMailHide() { |
|
106 |
$expected = 'http://recaptcha.net/api/getkey?domain=' . WWW_ROOT . 'test-app'; |
|
107 |
$result = $this->Recaptcha->mailHide('contact@cakedc.com'); |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* testMailHideUrl method |
|
112 |
* |
|
113 |
* @return void |
|
114 |
*/ |
|
115 |
public function testMailHideUrl() { |
|
116 |
$result = $this->Recaptcha->mailHideUrl('contact@cakedc.com'); |
|
117 |
} |
|
118 |
|
|
119 |
} |
app/Plugin/Recaptcha/Test/Fixture/ArticleFixture.php | ||
---|---|---|
1 |
<?php |
|
2 |
/** |
|
3 |
* Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
4 |
* |
|
5 |
* Licensed under The MIT License |
|
6 |
* Redistributions of files must retain the above copyright notice. |
|
7 |
* |
|
8 |
* @copyright Copyright 2009-2014, Cake Development Corporation (http://cakedc.com) |
|
9 |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10 |
*/ |
|
11 |
|
|
12 |
/** |
他の形式にエクスポート: Unified diff