Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Captcha_Block_Captcha
  • Mage_Captcha_Block_Captcha_Zend
  • Mage_Captcha_Helper_Data
  • Mage_Captcha_Model_Config_Font
  • Mage_Captcha_Model_Config_Form_Abstract
  • Mage_Captcha_Model_Config_Form_Backend
  • Mage_Captcha_Model_Config_Form_Frontend
  • Mage_Captcha_Model_Config_Mode
  • Mage_Captcha_Model_Observer
  • Mage_Captcha_Model_Resource_Log
  • Mage_Captcha_Model_Zend

Interfaces

  • Mage_Captcha_Model_Interface
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Captcha
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Log Attempts resource
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Captcha
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Captcha_Model_Resource_Log extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Type Remote Address
 39:      */
 40:     const TYPE_REMOTE_ADDRESS = 1;
 41: 
 42:     /**
 43:      * Type User Login Name
 44:      */
 45:     const TYPE_LOGIN = 2;
 46: 
 47:     /**
 48:      * Define main table
 49:      *
 50:      */
 51:     protected function _construct()
 52:     {
 53:         $this->_setMainTable('captcha/log');
 54:     }
 55: 
 56:     /**
 57:      * Save or Update count Attempts
 58:      *
 59:      * @param string|null $login
 60:      * @return Mage_Captcha_Model_Resource_Log
 61:      */
 62:     public function logAttempt($login)
 63:     {
 64:         if ($login != null){
 65:             $this->_getWriteAdapter()->insertOnDuplicate(
 66:                 $this->getMainTable(),
 67:                 array(
 68:                      'type' => self::TYPE_LOGIN, 'value' => $login, 'count' => 1,
 69:                      'updated_at' => Mage::getSingleton('core/date')->gmtDate()
 70:                 ),
 71:                 array('count' => new Zend_Db_Expr('count+1'), 'updated_at')
 72:             );
 73:         }
 74:         $ip = Mage::helper('core/http')->getRemoteAddr();
 75:         if ($ip != null) {
 76:             $this->_getWriteAdapter()->insertOnDuplicate(
 77:                 $this->getMainTable(),
 78:                 array(
 79:                      'type' => self::TYPE_REMOTE_ADDRESS, 'value' => $ip, 'count' => 1,
 80:                      'updated_at' => Mage::getSingleton('core/date')->gmtDate()
 81:                 ),
 82:                 array('count' => new Zend_Db_Expr('count+1'), 'updated_at')
 83:             );
 84:         }
 85:         return $this;
 86:     }
 87: 
 88:     /**
 89:      * Delete User attempts by login
 90:      *
 91:      * @param string $login
 92:      * @return Mage_Captcha_Model_Resource_Log
 93:      */
 94:     public function deleteUserAttempts($login)
 95:     {
 96:         if ($login != null) {
 97:             $this->_getWriteAdapter()->delete(
 98:                 $this->getMainTable(),
 99:                 array('type = ?' => self::TYPE_LOGIN, 'value = ?' => $login)
100:             );
101:         }
102:         $ip = Mage::helper('core/http')->getRemoteAddr();
103:         if ($ip != null) {
104:             $this->_getWriteAdapter()->delete(
105:                 $this->getMainTable(), array('type = ?' => self::TYPE_REMOTE_ADDRESS, 'value = ?' => $ip)
106:             );
107:         }
108: 
109:         return $this;
110:     }
111: 
112:     /**
113:      * Get count attempts by ip
114:      *
115:      * @return null|int
116:      */
117:     public function countAttemptsByRemoteAddress()
118:     {
119:         $ip = Mage::helper('core/http')->getRemoteAddr();
120:         if (!$ip) {
121:             return 0;
122:         }
123:         $read = $this->_getReadAdapter();
124:         $select = $read->select()->from($this->getMainTable(), 'count')->where('type = ?', self::TYPE_REMOTE_ADDRESS)
125:             ->where('value = ?', $ip);
126:         return $read->fetchOne($select);
127:     }
128: 
129:     /**
130:      * Get count attempts by user login
131:      *
132:      * @param string $login
133:      * @return null|int
134:      */
135:     public function countAttemptsByUserLogin($login)
136:     {
137:         if (!$login) {
138:             return 0;
139:         }
140:         $read = $this->_getReadAdapter();
141:         $select = $read->select()->from($this->getMainTable(), 'count')->where('type = ?', self::TYPE_LOGIN)
142:             ->where('value = ?', $login);
143:         return $read->fetchOne($select);
144:     }
145: 
146:     /**
147:      * Delete attempts with expired in update_at time
148:      *
149:      * @return void
150:      */
151:     public function deleteOldAttempts()
152:     {
153:         $this->_getWriteAdapter()->delete(
154:             $this->getMainTable(),
155:             array('updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, time() - 60*30))
156:         );
157:     }
158: }
159: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0