-
Notifications
You must be signed in to change notification settings - Fork 16
Migrate to ReCaptcha's v2 API #11
Changes from all commits
6197b44
17af428
2d3b861
e1cb18d
a3a5ba0
5df0b0a
414626a
b66196c
6f3ec60
80e6011
3d57b08
8fbdd9c
b4ea9dc
8c89395
e176722
881c2ea
5e603ae
94a5cbb
a336acd
7978e18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Zend Framework coding standard"> | ||
<description>Zend Framework coding standard</description> | ||
<ruleset name="Zend Framework Coding Standard"> | ||
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/> | ||
|
||
<!-- display progress --> | ||
<arg value="p"/> | ||
<arg name="colors"/> | ||
|
||
<!-- inherit rules from: --> | ||
<rule ref="PSR2"/> | ||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/> | ||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"> | ||
<properties> | ||
<property name="ignoreBlankLines" value="false"/> | ||
</properties> | ||
</rule> | ||
|
||
<!-- Paths to check --> | ||
<file>src</file> | ||
<file>test</file> | ||
<!-- Paths to check --> | ||
<file>src</file> | ||
<file>test</file> | ||
</ruleset> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ public function setEmailValidator(ValidatorInterface $validator) | |
*/ | ||
protected function requireMcrypt() | ||
{ | ||
if (!extension_loaded('mcrypt')) { | ||
if (! extension_loaded('mcrypt')) { | ||
throw new MailHideException(sprintf( | ||
'Use of the %s component requires the mcrypt extension to be enabled in PHP', | ||
__CLASS__ | ||
|
@@ -177,23 +177,65 @@ public function getDefaultOptions() | |
} | ||
|
||
/** | ||
* Override the setPrivateKey method | ||
* Set the private key property | ||
* | ||
* Override the parent method to store a binary representation of the private key as well. | ||
* | ||
* Note that we use the nomenclature "private key" as this is what MailHide's API | ||
* uses, even though the parent ReCaptcha API uses "secret key" | ||
* | ||
* @param string $privateKey | ||
* @return MailHide | ||
*/ | ||
public function setPrivateKey($privateKey) | ||
{ | ||
parent::setPrivateKey($privateKey); | ||
parent::setSecretKey($privateKey); | ||
|
||
/* Pack the private key into a binary string */ | ||
$this->privateKeyPacked = pack('H*', $this->privateKey); | ||
$this->privateKeyPacked = pack('H*', $this->getSecretKey()); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* get the private key property | ||
* | ||
* Note that we use the nomenclature "private key" as this is what MailHide's API | ||
* uses, even though the parent ReCaptcha API uses "secret key" | ||
* | ||
* @return string | ||
*/ | ||
public function getPrivateKey() | ||
{ | ||
return parent::getSecretKey(); | ||
} | ||
|
||
/** | ||
* set the public key property | ||
* | ||
* Note that we use the nomenclature "public key" as this is what MailHide's API | ||
* uses, even though the parent ReCaptcha API uses "site key" | ||
* | ||
* @param string $publicKey | ||
*/ | ||
public function setPublicKey($publicKey) | ||
{ | ||
return parent::setSiteKey($publicKey); | ||
} | ||
|
||
/** | ||
* Get the public key property | ||
* | ||
* Note that we use the nomenclature "public key" as this is what MailHide's API | ||
* uses, even though the parent ReCaptcha API uses "site key" | ||
* | ||
* @return string | ||
*/ | ||
public function getPublicKey() | ||
{ | ||
return parent::getSiteKey(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these proxy methods maybe be marked deprecated now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They aren't actually deprecated for MailHide as that's the correct wording for its API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, sounds good. |
||
|
||
/** | ||
* Set the email property | ||
* | ||
|
@@ -207,7 +249,7 @@ public function setEmail($email) | |
$this->email = $email; | ||
|
||
$validator = $this->getEmailValidator(); | ||
if (!$validator->isValid($email)) { | ||
if (! $validator->isValid($email)) { | ||
throw new MailHideException('Invalid email address provided'); | ||
} | ||
|
||
|
@@ -273,11 +315,11 @@ public function getHtml($email = null) | |
throw new MailHideException('Missing email address'); | ||
} | ||
|
||
if ($this->publicKey === null) { | ||
if ($this->getPublicKey() === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MailHide is still on v1's API which uses the nomenclature "public_key" and "private_key". Seemed sensible to be consistent within this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Maybe add some verbiage indicating that, then? |
||
throw new MailHideException('Missing public key'); | ||
} | ||
|
||
if ($this->privateKey === null) { | ||
if ($this->getPrivateKey() === null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MailHide is still on v1's API which uses the nomenclature "public_key" and "private_key". |
||
throw new MailHideException('Missing private key'); | ||
} | ||
|
||
|
@@ -330,7 +372,7 @@ protected function getUrl() | |
return sprintf( | ||
'%s?k=%s&c=%s', | ||
self::MAILHIDE_SERVER, | ||
$this->publicKey, | ||
$this->getSiteKey(), | ||
strtr(base64_encode($emailEncrypted), '+/', '-_') | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉