Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AccessKeyManager.inc.php
1 <?php
2 
19  var $accessKeyDao;
20 
25  function AccessKeyManager() {
26  $this->accessKeyDao = DAORegistry::getDAO('AccessKeyDAO');
27  $this->_performPeriodicCleanup();
28  }
29 
35  function generateKeyHash($key) {
36  return md5($key);
37  }
38 
49  function validateKey($context, $userId, $keyHash, $assocId = null) {
50  return $this->accessKeyDao->getAccessKeyByKeyHash($context, $userId, $keyHash, $assocId);
51  }
52 
61  function createKey($context, $userId, $assocId, $expiryDays) {
62  $accessKey = new AccessKey();
63  $accessKey->setContext($context);
64  $accessKey->setUserId($userId);
65  $accessKey->setAssocId($assocId);
66  $accessKey->setExpiryDate(Core::getCurrentDate(time() + (60 * 60 * 24 * $expiryDays)));
67 
69  $accessKey->setKeyHash($this->generateKeyHash($key));
70 
71  $this->accessKeyDao->insertObject($accessKey);
72 
73  return $key;
74  }
75 
80  if (time() % 100 == 0) {
81  $accessKeyDao = DAORegistry::getDAO('AccessKeyDAO');
82  $accessKeyDao->deleteExpiredKeys();
83  }
84  }
85 }
86 
87 ?>
static & getDAO($name, $dbconn=null)
static generatePassword($length=8)
Class defining operations for AccessKey management.
createKey($context, $userId, $assocId, $expiryDays)
AccessKey class.
validateKey($context, $userId, $keyHash, $assocId=null)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95