mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-11-28 10:30:42 +00:00
add methods for creating and getting api keys
This commit is contained in:
parent
06e939cf04
commit
af0e23a39c
|
|
@ -465,6 +465,7 @@ class SeedDMS_Core_DMS {
|
|||
$this->classnames['documentcontent'] = 'SeedDMS_Core_DocumentContent';
|
||||
$this->classnames['user'] = 'SeedDMS_Core_User';
|
||||
$this->classnames['role'] = 'SeedDMS_Core_Role';
|
||||
$this->classnames['apikey'] = 'SeedDMS_Core_ApiKey';
|
||||
$this->classnames['group'] = 'SeedDMS_Core_Group';
|
||||
$this->classnames['attributedefinitiongroup'] = 'SeedDMS_Core_AttributeDefinitionGroup';
|
||||
$this->classnames['transmittal'] = 'SeedDMS_Core_Transmittal';
|
||||
|
|
@ -2782,6 +2783,40 @@ class SeedDMS_Core_DMS {
|
|||
return $this->getRole($this->db->getInsertID('tblRoles'));
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Get a apikey by its key name
|
||||
*
|
||||
* @param integer $name name of key
|
||||
* @return object/boolean apikey or false if no role was found
|
||||
*/
|
||||
function getApiKeyByApiKey($name) { /* {{{ */
|
||||
$classname = $this->classnames['apikey'];
|
||||
return $classname::getInstance($name, $this, 'apikey');
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Create a new apikey
|
||||
*
|
||||
* @param string $apikey name of key
|
||||
* @return object/boolean instance of {@link SeedDMS_Core_ApiKey} or false in
|
||||
* case of an error.
|
||||
*/
|
||||
function addApiKey($apikey, $user, $disabled=false, $expires=null) { /* {{{ */
|
||||
if (is_object($this->getApiKeyByApiKey($apikey))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->classnames['user'] != get_class($user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$queryStr = "INSERT INTO `tblApiKeys` (`apikey`, `user`, `disabled`, `expires`) VALUES (".$this->db->qstr($apikey).", ".$user->getID().", ".($disabled ? 1 : 0).", ".($expires ? $this->db->qstr($expires) : "NULL").")";
|
||||
if (!$this->db->getResult($queryStr))
|
||||
return false;
|
||||
|
||||
return $this->getApiKey($this->db->getInsertID('tblApiKeys'));
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Get a transmittal by its id
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user