diff --git a/src/DragonKnight/Actions/Help.php b/src/DragonKnight/Actions/Help.php
index b8cbcf8..b17d1f0 100644
--- a/src/DragonKnight/Actions/Help.php
+++ b/src/DragonKnight/Actions/Help.php
@@ -13,8 +13,13 @@ declare(strict_types=1);
namespace DragonKnight\Actions;
+use DragonKnight\DragonKnight;
use DragonKnight\Router;
+use function DragonKnight\db;
+use function DragonKnight\render;
+use function DragonKnight\special_to_string;
+
class Help
{
public static function register_routes(Router $r): Router
@@ -509,8 +514,8 @@ class Help
{
return render('layouts/help', [
'content' => $content,
- 'version' => VERSION,
- 'build' => BUILD,
+ 'version' => DragonKnight::VERSION,
+ 'build' => DragonKnight::BUILD,
]);
}
}
diff --git a/src/DragonKnight/Actions/Users.php b/src/DragonKnight/Actions/Users.php
index 52b5aa1..deb35e4 100644
--- a/src/DragonKnight/Actions/Users.php
+++ b/src/DragonKnight/Actions/Users.php
@@ -13,10 +13,20 @@ declare(strict_types=1);
namespace DragonKnight\Actions;
-use DragonKnight\Lib;
use DragonKnight\Mail;
use DragonKnight\Router;
+use function DragonKnight\db;
+use function DragonKnight\env;
+use function DragonKnight\is_post;
+use function DragonKnight\page_title;
+use function DragonKnight\redirect;
+use function DragonKnight\render;
+use function DragonKnight\token;
+use function DragonKnight\ul_from_validate_errors;
+use function DragonKnight\user;
+use function DragonKnight\validate;
+
class Users
{
public static function register_routes(Router $r): Router
@@ -39,14 +49,14 @@ class Users
{
global $auth;
- if (Lib::is_post()) {
- $form = Lib::validate($_POST, [
+ if (is_post()) {
+ $form = validate($_POST, [
'username' => ['length:3-18', 'alpha-spaces'],
'password' => ['length:6-255'],
]);
if (! $form['valid']) {
- exit(Lib::ul_from_validate_errors($form['errors']));
+ exit(ul_from_validate_errors($form['errors']));
}
$good = $auth->login($form['data']['username'], $form['data']['password']);
@@ -54,12 +64,12 @@ class Users
exit('Invalid username or password. Please go back and try again.');
}
- Lib::redirect('/');
+ redirect('/');
}
- Lib::page_title('Login');
+ page_title('Login');
- return Lib::render('login');
+ return render('login');
}
/**
@@ -69,7 +79,7 @@ class Users
{
global $auth;
$auth->logout();
- Lib::redirect('/login');
+ redirect('/login');
}
/**
@@ -78,7 +88,7 @@ class Users
public static function register()
{
if (isset($_POST['submit'])) {
- $form = Lib::validate($_POST, [
+ $form = validate($_POST, [
'username' => ['length:3-18', 'alpha-spaces', 'unique:users,username'],
'email' => ['email', 'unique:users,email'],
'confirm_email' => ['confirm'],
@@ -88,37 +98,37 @@ class Users
]);
if (! $form['valid']) {
- $err = Lib::ul_from_validate_errors($form['errors']);
+ $err = ul_from_validate_errors($form['errors']);
$page = "The following error(s) occurred when your account was being made:
$err
Please go back and try again.";
} else {
$form = $form['data'];
$password = password_hash($form['password'], PASSWORD_ARGON2ID);
- $token = Lib::env('verify_email') ? Lib::token(8) : 'g2g';
- Lib::db()->query('INSERT INTO users (verify, username, password, email, charclass) VALUES (?, ?, ?, ?, ?)', [
+ $token = env('verify_email') ? token(8) : 'g2g';
+ db()->query('INSERT INTO users (verify, username, password, email, charclass) VALUES (?, ?, ?, ?, ?)', [
$token, $form['username'], $password, $form['email'], $form['charclass'],
]);
- if (Lib::env('verify_email')) {
+ if (env('verify_email')) {
if (self::sendregmail($form['email'], $token)) {
$page = 'Your account was created successfully.
You should receive an Account Verification email shortly. You will need the verification code contained in that email before you are allowed to log in. Once you have received the email, please visit the Verification Page to enter your code and start playing.';
} else {
$page = 'Your account was created successfully.
However, there was a problem sending your verification email. Please check with the game administrator to help resolve this problem.';
}
} else {
- $page = 'Your account was created succesfully.
You may now continue to the Login Page and continue playing '.Lib::env('game_name').'!';
+ $page = 'Your account was created succesfully.
You may now continue to the Login Page and continue playing '.env('game_name').'!';
}
}
} else {
- if (Lib::env('verify_email')) {
+ if (env('verify_email')) {
$verify_text = '
A verification code will be sent to the address above, and you will not be able to log in without first entering the code. Please be sure to enter your correct email address.';
} else {
$verify_text = '';
}
- $page = Lib::render('register', ['verify_text' => $verify_text]);
+ $page = render('register', ['verify_text' => $verify_text]);
}
- Lib::page_title('Register');
+ page_title('Register');
return $page;
}
@@ -130,17 +140,17 @@ class Users
$e = trim($_POST['email'] ?? '');
$t = trim($_POST['token'] ?? '');
- $query = Lib::db()->query('SELECT id FROM users WHERE username=? AND email=? AND verify=? LIMIT 1;', [$u, $e, $t]);
+ $query = db()->query('SELECT id FROM users WHERE username=? AND email=? AND verify=? LIMIT 1;', [$u, $e, $t]);
if ($query === false) {
exit('Verification failed. Go back, double-check your details, and try again.');
}
- Lib::db()->query("UPDATE users SET verify='g2g' WHERE username=?;", [$u]);
+ db()->query("UPDATE users SET verify='g2g' WHERE username=?;", [$u]);
return 'Your account was verified successfully.
You may now continue to the Login Page and start playing the game.
Thanks for playing!';
}
- return Lib::render('verify');
+ return render('verify');
}
public static function lostpassword()
@@ -148,14 +158,14 @@ class Users
if (isset($_POST['submit'])) {
$e = trim($_POST['email'] ?? '');
- if (! Lib::db()->exists('users', 'email', $e)) {
+ if (! db()->exists('users', 'email', $e)) {
exit('No account with that email address.');
}
- $newpass = Lib::token(16);
+ $newpass = token(16);
$hashed = password_hash($newpass, PASSWORD_ARGON2ID);
- Lib::db()->query('UPDATE users SET password=? WHERE email=?;', [$hashed, $e]);
+ db()->query('UPDATE users SET password=? WHERE email=?;', [$hashed, $e]);
if (self::sendpassemail($e, $newpass)) {
return 'Your new password was emailed to the address you provided.
Once you receive it, you may Log In and continue playing.
Thank you.';
@@ -164,7 +174,7 @@ class Users
return 'There was an error sending your new password.
Please check with the game administrator for more information.
We apologize for the inconvience.';
}
- return Lib::render('lostpassword');
+ return render('lostpassword');
}
public static function changepassword()
@@ -177,7 +187,7 @@ class Users
$np = $_POST['new_password'] ?? '';
$np2 = $_POST['new_password2'] ?? '';
- $user = Lib::db()->query('SELECT password FROM users WHERE username=? LIMIT 1;', [$u]);
+ $user = db()->query('SELECT password FROM users WHERE username=? LIMIT 1;', [$u]);
$user = $user->fetchArray(SQLITE3_ASSOC);
if ($user === false) {
exit('No account with that username.');
@@ -196,7 +206,7 @@ class Users
}
$realnewpass = password_hash($np, PASSWORD_ARGON2ID);
- Lib::db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]);
+ db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]);
$auth->logout();
@@ -206,30 +216,30 @@ class Users
public static function settings()
{
- if (Lib::is_post()) {
- $form = Lib::validate($_POST, [
+ if (is_post()) {
+ $form = validate($_POST, [
'game_skin' => ['in:0,1'],
]);
if (! $form['valid']) {
- exit(Lib::ul_from_validate_errors($form['errors']));
+ exit(ul_from_validate_errors($form['errors']));
}
$form = $form['data'];
- Lib::user()->game_skin = $form['game_skin'];
- Lib::user()->save();
+ user()->game_skin = $form['game_skin'];
+ user()->save();
$alert = '