示例#1
0
 /**
  * Authenticate user by $username and $password
  *
  * @param string $username
  * @param string $password
  * @return boolean|Object
  */
 public function recordLogin(Mage_Api_Model_User $user)
 {
     $data = array('logdate' => now(), 'lognum' => $user->getLognum() + 1, 'sessid' => $user->getSessid());
     $condition = $this->_getWriteAdapter()->quoteInto('user_id=?', $user->getUserId());
     $this->_getWriteAdapter()->update($this->getTable('api/user'), $data, $condition);
     return $this;
 }
 /**
  * This method creates a new maintainer by copying the data
  * from the passed customer.
  *
  * @param Mage_Customer_Model_Customer $customer
  * 		The customer to copy the values from
  * @return Faett_Channel_Model_Maintainer The maintainer itself
  */
 public function saveWithCopiedPassword(Mage_Customer_Model_Customer $customer)
 {
     // call the parent class's _beforeSave() method
     parent::_beforeSave();
     // initialize the array with the maintainers data to create
     $data = array('firstname' => $this->getFirstname(), 'lastname' => $this->getLastname(), 'email' => $this->getEmail(), 'modified' => Mage::getSingleton('core/date')->gmtDate(), 'is_active' => true);
     // check if an ID was set
     if ($this->getId() > 0) {
         $data['user_id'] = $this->getId();
     }
     // check if a username was set
     if ($this->getUsername()) {
         $data['username'] = $this->getUsername();
     }
     // copy the users password
     if ($customer->getPasswordHash()) {
         $data['api_key'] = $customer->getPasswordHash();
     }
     // set the data an save the maintainer
     $this->setData($data);
     $this->_getResource()->save($this);
     $this->_afterSave();
     // return the maintainer itself
     return $this;
 }
示例#3
0
 public function cleanOldSessions(Mage_Api_Model_User $user)
 {
     $timeout = Mage::getStoreConfig('api/config/session_timeout');
     $this->_getWriteAdapter()->delete($this->getTable('api/session'), $this->_getReadAdapter()->quoteInto('user_id = ?', $user->getId()) . ' AND ' . new Zend_Db_Expr('(UNIX_TIMESTAMP(\'' . now() . '\') - UNIX_TIMESTAMP(logdate)) > ' . $timeout));
     return $this;
 }
示例#4
0
 /**
  * Clean old session
  *
  * @param Mage_Api_Model_User $user
  * @return Mage_Api_Model_Resource_User
  */
 public function cleanOldSessions(Mage_Api_Model_User $user)
 {
     $readAdapter = $this->_getReadAdapter();
     $writeAdapter = $this->_getWriteAdapter();
     $timeout = Mage::getStoreConfig('api/config/session_timeout');
     $timeSubtract = $readAdapter->getDateAddSql('logdate', $timeout, Varien_Db_Adapter_Interface::INTERVAL_SECOND);
     $writeAdapter->delete($this->getTable('api/session'), array('user_id = ?' => $user->getId(), $readAdapter->quote(now()) . ' > ' . $timeSubtract));
     return $this;
 }