61 lines
2.3 KiB
PHP
61 lines
2.3 KiB
PHP
|
<?php
|
||
|
namespace Mince;
|
||
|
|
||
|
use Index\Routing\IRouter;
|
||
|
|
||
|
class HomeRoutes {
|
||
|
public function __construct(
|
||
|
private Templating $templating,
|
||
|
private object $userInfo
|
||
|
) {}
|
||
|
|
||
|
public function register(IRouter $router): void {
|
||
|
$router->get('/', [$this, 'getIndex']);
|
||
|
|
||
|
$router->get('/index.php', function($response) {
|
||
|
$response->redirect('/', true);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public function getIndex($response, $request) {
|
||
|
$name = (string)$request->getParam('name');
|
||
|
$error = (string)$request->getParam('error');
|
||
|
|
||
|
if(!empty($error) && ctype_lower($error)) {
|
||
|
$errors = [
|
||
|
'request' => ['Invalid request type.', 'Try to reload the page and try again.'],
|
||
|
'verify' => ['Request verification failed.', 'Try to reload the page and try again.'],
|
||
|
'itainthappenin' => ['Haha', 'No'],
|
||
|
'short' => ['Invalid username', 'The provided name is too short.'],
|
||
|
'long' => ['Invalid username', 'The provided name is too long.'],
|
||
|
'invalid' => ['Invalid username', 'The provided name contains invalid characters.'],
|
||
|
'conflict' => ['Username conflict', 'This username is already whitelisted with someone, contact flashwave if this is unexpected.'],
|
||
|
'connect' => ['Failed to connect to the server', 'The server is probably offline, pope flashwave if this is not expected.'],
|
||
|
'not-listed' => ['You have not been whitelisted yet', 'Add yourself to the whitelist before trying to remove yourself from it.'],
|
||
|
];
|
||
|
|
||
|
if(array_key_exists($error, $errors)) {
|
||
|
$errTitle = $errors[$error][0];
|
||
|
$errBody = $errors[$error][1];
|
||
|
} else {
|
||
|
$errTitle = 'Unexpected response from server';
|
||
|
$errBody = $error;
|
||
|
}
|
||
|
|
||
|
$this->templating->addVars([
|
||
|
'error' => [
|
||
|
'title' => $errTitle,
|
||
|
'body' => $errBody,
|
||
|
],
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
if($this->userInfo->mc_whitelisted > 0)
|
||
|
$this->templating->setVar('whitelist_pending', floor($this->userInfo->mc_whitelisted / 300) === floor(time() / 300));
|
||
|
|
||
|
return $this->templating->render('index', [
|
||
|
'wladdform_username' => $name,
|
||
|
]);
|
||
|
}
|
||
|
}
|