get rid of src/util
This commit is contained in:
parent
18e1427ed3
commit
d82e0fdaf3
|
@ -14,9 +14,9 @@ define('CLASS_MAP', [
|
|||
]);
|
||||
|
||||
require_once SRC . '/helpers.php';
|
||||
require_once SRC . '/util/auth.php';
|
||||
require_once SRC . '/util/components.php';
|
||||
require_once SRC . '/util/enums.php';
|
||||
require_once SRC . 'auth.php';
|
||||
require_once SRC . 'components.php';
|
||||
require_once SRC . 'enums.php';
|
||||
|
||||
require_once SRC . '/models/token.php';
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Create a token for a user. Returns the token on success, or false on failure.
|
||||
*/
|
||||
function token_create($userId)
|
||||
{
|
||||
$token = token();
|
||||
$result = auth_db()->query("INSERT INTO tokens (token, user_id) VALUES (:t, :u)", [
|
||||
':t' => $token,
|
||||
':u' => $userId
|
||||
]);
|
||||
if (!$result) return false;
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a token by token.
|
||||
*/
|
||||
function token_find($token)
|
||||
{
|
||||
$result = auth_db()->query("SELECT * FROM tokens WHERE token = :t", [':t' => $token]);
|
||||
$token = $result->fetchArray(SQLITE3_ASSOC);
|
||||
if (!$token) return false;
|
||||
$result->finalize();
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a token by token.
|
||||
*/
|
||||
function token_delete($token)
|
||||
{
|
||||
return auth_db()->query("DELETE FROM tokens WHERE token = :t", [':t' => $token]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a token by token and created date. Tokens are invalid if older than 7 days.
|
||||
*/
|
||||
function token_validate($token)
|
||||
{
|
||||
$token = token_find($token);
|
||||
if (!$token) return false;
|
||||
if (strtotime('+7 days') < time()) {
|
||||
token_delete($token['token']);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user