renamed ApiUser to ApiKeys
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
4f02c68cc5
commit
69659bb33f
@ -9,7 +9,7 @@ use PDOException;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ApiUsers
|
||||
class ApiKeys
|
||||
{
|
||||
public function __construct(private DatabaseConnection $databaseConnection)
|
||||
{}
|
||||
@ -21,7 +21,7 @@ class ApiUsers
|
||||
public function findAll(): bool|array
|
||||
{
|
||||
$sql = "
|
||||
SELECT id, api_token_prefix, api_token
|
||||
SELECT id, name, api_token_prefix, api_token
|
||||
FROM " . DatabaseConnection::TABLE_USER;
|
||||
|
||||
try {
|
||||
@ -41,7 +41,7 @@ class ApiUsers
|
||||
public function findByID(Int $id): bool|array
|
||||
{
|
||||
$sql = "
|
||||
SELECT api_token_prefix, api_token
|
||||
SELECT name, api_token_prefix, api_token
|
||||
FROM " . DatabaseConnection::TABLE_USER . "
|
||||
WHERE id = :id;
|
||||
";
|
||||
@ -65,7 +65,7 @@ class ApiUsers
|
||||
public function findByPrefix(String $prefix): bool|array
|
||||
{
|
||||
$sql = "
|
||||
SELECT api_token
|
||||
SELECT name, api_token
|
||||
FROM " . DatabaseConnection::TABLE_USER . "
|
||||
WHERE api_token_prefix = :prefix";
|
||||
|
||||
@ -83,7 +83,7 @@ class ApiUsers
|
||||
/**
|
||||
* @return array|void
|
||||
*/
|
||||
public function create()
|
||||
public function create(String $name = '')
|
||||
{
|
||||
$tokenPrefix = uniqid();
|
||||
$result['tokenPrefix'] = $tokenPrefix;
|
||||
@ -97,13 +97,15 @@ class ApiUsers
|
||||
$token = password_hash(password: $tokenPrefix . '.' . $key, algo: PASSWORD_ARGON2ID);
|
||||
|
||||
$sql = "
|
||||
INSERT INTO " . DatabaseConnection::TABLE_USER . " (api_token_prefix, api_token)
|
||||
INSERT INTO " . DatabaseConnection::TABLE_USER . " (name, api_token_prefix, api_token)
|
||||
VALUES (:token_prefix, :token)";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||
$statement->bindParam(param: ':token_prefix', var: $tokenPrefix);
|
||||
$statement->bindParam(param: ':token', var: $token);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
|
||||
$statement->execute();
|
||||
$result['row'] = $this->databaseConnection->getConnection()->lastInsertId();
|
||||
return $result;
|
Loading…
Reference in New Issue
Block a user