Révision e326068a
Ajouté par Assos Assos il y a plus de 5 ans
drupal7/sites/all/modules/recaptcha/recaptcha-php/src/ReCaptcha/Response.php | ||
---|---|---|
3 | 3 |
* This is a PHP library that handles calling reCAPTCHA. |
4 | 4 |
* |
5 | 5 |
* @copyright Copyright (c) 2015, Google Inc. |
6 |
* @link http://www.google.com/recaptcha |
|
6 |
* @link https://www.google.com/recaptcha
|
|
7 | 7 |
* |
8 | 8 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | 9 |
* of this software and associated documentation files (the "Software"), to deal |
... | ... | |
32 | 32 |
class Response |
33 | 33 |
{ |
34 | 34 |
/** |
35 |
* Succes or failure. |
|
35 |
* Success or failure.
|
|
36 | 36 |
* @var boolean |
37 | 37 |
*/ |
38 | 38 |
private $success = false; |
... | ... | |
43 | 43 |
*/ |
44 | 44 |
private $errorCodes = array(); |
45 | 45 |
|
46 |
/** |
|
47 |
* The hostname of the site where the reCAPTCHA was solved. |
|
48 |
* @var string |
|
49 |
*/ |
|
50 |
private $hostname; |
|
51 |
|
|
52 |
/** |
|
53 |
* Timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ) |
|
54 |
* @var string |
|
55 |
*/ |
|
56 |
private $challengeTs; |
|
57 |
|
|
58 |
/** |
|
59 |
* APK package name |
|
60 |
* @var string |
|
61 |
*/ |
|
62 |
private $apkPackageName; |
|
63 |
|
|
64 |
/** |
|
65 |
* Score assigned to the request |
|
66 |
* @var float |
|
67 |
*/ |
|
68 |
private $score; |
|
69 |
|
|
70 |
/** |
|
71 |
* Action as specified by the page |
|
72 |
* @var string |
|
73 |
*/ |
|
74 |
private $action; |
|
75 |
|
|
46 | 76 |
/** |
47 | 77 |
* Build the response from the expected JSON returned by the service. |
48 | 78 |
* |
... | ... | |
54 | 84 |
$responseData = json_decode($json, true); |
55 | 85 |
|
56 | 86 |
if (!$responseData) { |
57 |
return new Response(false, array('invalid-json'));
|
|
87 |
return new Response(false, array(ReCaptcha::E_INVALID_JSON));
|
|
58 | 88 |
} |
59 | 89 |
|
90 |
$hostname = isset($responseData['hostname']) ? $responseData['hostname'] : null; |
|
91 |
$challengeTs = isset($responseData['challenge_ts']) ? $responseData['challenge_ts'] : null; |
|
92 |
$apkPackageName = isset($responseData['apk_package_name']) ? $responseData['apk_package_name'] : null; |
|
93 |
$score = isset($responseData['score']) ? floatval($responseData['score']) : null; |
|
94 |
$action = isset($responseData['action']) ? $responseData['action'] : null; |
|
95 |
|
|
60 | 96 |
if (isset($responseData['success']) && $responseData['success'] == true) { |
61 |
return new Response(true); |
|
97 |
return new Response(true, array(), $hostname, $challengeTs, $apkPackageName, $score, $action);
|
|
62 | 98 |
} |
63 | 99 |
|
64 | 100 |
if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
65 |
return new Response(false, $responseData['error-codes']); |
|
101 |
return new Response(false, $responseData['error-codes'], $hostname, $challengeTs, $apkPackageName, $score, $action);
|
|
66 | 102 |
} |
67 | 103 |
|
68 |
return new Response(false); |
|
104 |
return new Response(false, array(ReCaptcha::E_UNKNOWN_ERROR), $hostname, $challengeTs, $apkPackageName, $score, $action);
|
|
69 | 105 |
} |
70 | 106 |
|
71 | 107 |
/** |
72 | 108 |
* Constructor. |
73 | 109 |
* |
74 | 110 |
* @param boolean $success |
111 |
* @param string $hostname |
|
112 |
* @param string $challengeTs |
|
113 |
* @param string $apkPackageName |
|
114 |
* @param float $score |
|
115 |
* @param strong $action |
|
75 | 116 |
* @param array $errorCodes |
76 | 117 |
*/ |
77 |
public function __construct($success, array $errorCodes = array()) |
|
118 |
public function __construct($success, array $errorCodes = array(), $hostname = null, $challengeTs = null, $apkPackageName = null, $score = null, $action = null)
|
|
78 | 119 |
{ |
79 | 120 |
$this->success = $success; |
121 |
$this->hostname = $hostname; |
|
122 |
$this->challengeTs = $challengeTs; |
|
123 |
$this->apkPackageName = $apkPackageName; |
|
124 |
$this->score = $score; |
|
125 |
$this->action = $action; |
|
80 | 126 |
$this->errorCodes = $errorCodes; |
81 | 127 |
} |
82 | 128 |
|
... | ... | |
99 | 145 |
{ |
100 | 146 |
return $this->errorCodes; |
101 | 147 |
} |
148 |
|
|
149 |
/** |
|
150 |
* Get hostname. |
|
151 |
* |
|
152 |
* @return string |
|
153 |
*/ |
|
154 |
public function getHostname() |
|
155 |
{ |
|
156 |
return $this->hostname; |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Get challenge timestamp |
|
161 |
* |
|
162 |
* @return string |
|
163 |
*/ |
|
164 |
public function getChallengeTs() |
|
165 |
{ |
|
166 |
return $this->challengeTs; |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* Get APK package name |
|
171 |
* |
|
172 |
* @return string |
|
173 |
*/ |
|
174 |
public function getApkPackageName() |
|
175 |
{ |
|
176 |
return $this->apkPackageName; |
|
177 |
} |
|
178 |
/** |
|
179 |
* Get score |
|
180 |
* |
|
181 |
* @return float |
|
182 |
*/ |
|
183 |
public function getScore() |
|
184 |
{ |
|
185 |
return $this->score; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Get action |
|
190 |
* |
|
191 |
* @return string |
|
192 |
*/ |
|
193 |
public function getAction() |
|
194 |
{ |
|
195 |
return $this->action; |
|
196 |
} |
|
197 |
|
|
198 |
public function toArray() |
|
199 |
{ |
|
200 |
return array( |
|
201 |
'success' => $this->isSuccess(), |
|
202 |
'hostname' => $this->getHostname(), |
|
203 |
'challenge_ts' => $this->getChallengeTs(), |
|
204 |
'apk_package_name' => $this->getApkPackageName(), |
|
205 |
'score' => $this->getScore(), |
|
206 |
'action' => $this->getAction(), |
|
207 |
'error-codes' => $this->getErrorCodes(), |
|
208 |
); |
|
209 |
} |
|
102 | 210 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules