renamed $statement to $sql
This commit is contained in:
parent
30b9b5da1d
commit
ed5fe80edc
@ -20,13 +20,13 @@ class ApiUsers
|
||||
*/
|
||||
public function findAll(): bool|array
|
||||
{
|
||||
$statement = "
|
||||
$sql = "
|
||||
SELECT id, api_token_prefix, api_token
|
||||
FROM user";
|
||||
|
||||
try {
|
||||
$statement = $this->dbConnection->query($statement);
|
||||
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
$statement = $this->dbConnection->query($sql);
|
||||
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
@ -40,40 +40,46 @@ class ApiUsers
|
||||
*/
|
||||
public function findByID(Int $id): bool|array
|
||||
{
|
||||
$statement = "
|
||||
$sql = "
|
||||
SELECT api_token_prefix, api_token
|
||||
FROM user
|
||||
WHERE id = :id;
|
||||
";
|
||||
|
||||
try {
|
||||
$statement = $this->dbConnection->prepare($statement);
|
||||
$statement->bindParam(':id', $id);
|
||||
$statement = $this->dbConnection->prepare($sql);
|
||||
$statement->bindParam(param: ':id', var: $id);
|
||||
$statement->execute();
|
||||
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param String $prefix
|
||||
*
|
||||
* @return bool|array
|
||||
*/
|
||||
public function findByPrefix(String $prefix): bool|array
|
||||
{
|
||||
$statement = "
|
||||
$sql = "
|
||||
SELECT api_token
|
||||
FROM user
|
||||
WHERE api_token_prefix = :prefix;
|
||||
";
|
||||
WHERE api_token_prefix = :prefix";
|
||||
|
||||
try {
|
||||
$statement = $this->dbConnection->prepare($statement);
|
||||
$statement->bindParam(':prefix', $prefix);
|
||||
$statement = $this->dbConnection->prepare($sql);
|
||||
$statement->bindParam(param: ':prefix', var: $prefix);
|
||||
$statement->execute();
|
||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|void
|
||||
*/
|
||||
@ -82,22 +88,22 @@ class ApiUsers
|
||||
$tokenPrefix = uniqid();
|
||||
$result['tokenPrefix'] = $tokenPrefix;
|
||||
try {
|
||||
$key = bin2hex(random_bytes(24));
|
||||
$key = bin2hex(random_bytes(length: 24));
|
||||
$result['key'] = $key;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
$token = password_hash($tokenPrefix . '.' . $key, PASSWORD_ARGON2ID);
|
||||
$token = password_hash(password: $tokenPrefix . '.' . $key, algo: PASSWORD_ARGON2ID);
|
||||
|
||||
$statement = "
|
||||
$sql = "
|
||||
INSERT INTO user (api_token_prefix, api_token)
|
||||
VALUES (:token_prefix, :token)";
|
||||
|
||||
try {
|
||||
$statement = $this->dbConnection->prepare($statement);
|
||||
$statement->bindParam(':token_prefix', $tokenPrefix);
|
||||
$statement->bindParam(':token', $token);
|
||||
$statement = $this->dbConnection->prepare($sql);
|
||||
$statement->bindParam(param: ':token_prefix', var: $tokenPrefix);
|
||||
$statement->bindParam(param: ':token', var: $token);
|
||||
$statement->execute();
|
||||
$result['row'] = $this->dbConnection->lastInsertId();
|
||||
return $result;
|
||||
@ -114,13 +120,13 @@ class ApiUsers
|
||||
*/
|
||||
public function delete($id): int
|
||||
{
|
||||
$statement = "
|
||||
$sql = "
|
||||
DELETE FROM user
|
||||
WHERE id = :id";
|
||||
|
||||
try {
|
||||
$statement = $this->dbConnection->prepare($statement);
|
||||
$statement->bindParam('id', $id);
|
||||
$statement = $this->dbConnection->prepare($sql);
|
||||
$statement->bindParam(param: 'id', var: $id);
|
||||
$statement->execute();
|
||||
return $statement->rowCount();
|
||||
} catch (PDOException $e) {
|
||||
@ -128,5 +134,4 @@ class ApiUsers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user