1212 class JetRails_Cloudflare_Model_Adminhtml_Api_Overview_Configuration
1313 extends Mage_Core_Model_Abstract {
1414
15- /**
16- * This method caches a zone value based on a passed domain. This is
17- * used cache the result of an API call within an entire session. The
18- * zone id is cached, because it gets used a lot throughout a typical
19- * session.
20- * @param string domain Domain to cache as key
21- * @param string zone The zone to cache as value
22- * @return void
23- */
24- protected function _setCached ( $ domain , $ zone ) {
25- $ session = Mage::getSingleton ("core/session " );
26- $ lookup = array ();
27- if ( !empty ( $ session ->getDomainZone () ) ) {
28- $ lookup = $ session ->getDomainZone ();
29- }
30- $ lookup [ "$ domain " ] = "$ zone " ;
31- $ session ->setDomainZone ( $ lookup );
32- }
33-
34- /**
35- * This method attempts to retrieve a zone id from cache, based on a
36- * domain name. If there is no zone id for the passed domain name, then
37- * false is returned.
38- * @param string domain Domain for zone id
39- * @return mixed Cached zone id or false
40- */
41- protected function _getCached ( $ domain ) {
42- $ session = Mage::getSingleton ("core/session " );
43- $ lookup = $ session ->getDomainZone ();
44- if ( !empty ( $ lookup )
45- && is_array ( $ lookup )
46- && array_key_exists ( "$ domain " , $ lookup ) ) {
47- return $ lookup ["$ domain " ];
48- }
49- return false ;
50- }
51-
5215 /**
5316 * This method takes in a zone and a token. It then makes an API call to
5417 * Cloudflare and finds out if the supplied token for the zone is valid.
@@ -60,6 +23,11 @@ public function validateAuth ( $zone = null, $token = null ) {
6023 $ api = Mage::getModel ("cloudflare/api_request " );
6124 $ api ->setType ( $ api ::REQUEST_GET );
6225 $ response = $ api ->resolve ("user/tokens/verify " );
26+ if ( !$ response ->success ) {
27+ return false ;
28+ }
29+ if ( !$ zone ) $ zone = $ this ->getZoneId ();
30+ $ response = $ api ->resolve ("zones/ $ zone " );
6331 return $ response ->success ;
6432 }
6533
@@ -71,14 +39,7 @@ public function validateAuth ( $zone = null, $token = null ) {
7139 */
7240 public function getZoneId () {
7341 $ data = Mage::helper ("cloudflare/data " );
74- $ domain = $ data ->getDomainName ();
75- $ cached = $ this ->_getCached ("$ domain " );
76- if ( $ cached !== false ) {
77- return $ cached ;
78- }
79- $ zone = $ data ->getAuthZone ();
80- $ this ->_setCached ( "$ domain " , $ zone );
81- return $ zone ;
42+ return $ data ->getAuthZone ();
8243 }
8344
8445 }
0 commit comments