Some security (through obscurity, sorta) measures.
This commit is contained in:
parent
7d74ebea27
commit
64f30b0cbb
2 changed files with 57 additions and 16 deletions
|
@ -48,19 +48,42 @@ class AuthController extends Controller
|
|||
return ['error' => 'You are now logged in!', 'next' => '/'];
|
||||
}
|
||||
|
||||
public function register()
|
||||
private function hasRegistrations(?string $ipAddr = null): bool
|
||||
{
|
||||
if (!flashii_is_ready()) {
|
||||
return "not yet!";
|
||||
$ipAddr = IP::unpack($ipAddr ?? IP::remote());
|
||||
|
||||
if (User::where('register_ip', $ipAddr)->orWhere('last_ip', $ipAddr)->count()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$app = Application::getInstance();
|
||||
$twig = $app->templating;
|
||||
$twig->vars([
|
||||
'has_registrations' => $this->hasRegistrations(),
|
||||
]);
|
||||
|
||||
return $twig->render('auth.register');
|
||||
}
|
||||
|
||||
if (!flashii_is_ready()) {
|
||||
return [
|
||||
'error' => "Nice try, but you'll have to wait a little longer. I appreciate your excitement though!"
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->hasRegistrations()) {
|
||||
return [
|
||||
'error' => "Someone already used an account from this IP address!\r\n"
|
||||
. "But don't worry, this is a temporary measure and you'll be able to register sometime soon."
|
||||
];
|
||||
}
|
||||
|
||||
if (!isset($_POST['username'], $_POST['password'], $_POST['email'])) {
|
||||
return ['error' => "You didn't fill all the forms!"];
|
||||
}
|
||||
|
|
|
@ -3,23 +3,41 @@
|
|||
{% set banner_classes = 'banner--large landing__banner' %}
|
||||
|
||||
{% block banner_content %}
|
||||
<h1 style="align-self: center; text-align: left; flex-grow: 1; padding-left: 2em">Welcome, thanks for dropping by!</h1>
|
||||
<h1 style="align-self: center; text-align: left; flex-grow: 1; padding-left: 2em">
|
||||
{% if has_registrations %}
|
||||
Your IP address already has an account!
|
||||
{% elseif not flashii_is_ready() %}
|
||||
You'll have to wait a little longer!
|
||||
{% else %}
|
||||
Welcome, thanks for dropping by!
|
||||
{% endif %}
|
||||
</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="platform form" id="auth-form">
|
||||
<div>
|
||||
<input class="form__text" type="text" name="username" placeholder="Username">
|
||||
{% if has_registrations %}
|
||||
<div class="platform" style="text-align: left;">
|
||||
<p>As a temporary security measure we only allow one account per IP address, this will definitely be changed in the future but for now; sorry for the possible inconvenience!</p>
|
||||
</div>
|
||||
<div>
|
||||
<input class="form__text" type="password" name="password" placeholder="Password">
|
||||
{% elseif not flashii_is_ready() %}
|
||||
<div class="platform" style="text-align: left;">
|
||||
<p>You'll be able to register once the countdown on the landing page runs out!</p>
|
||||
</div>
|
||||
<div>
|
||||
<input class="form__text" type="text" name="email" placeholder="E-mail">
|
||||
{% else %}
|
||||
<div class="platform form" id="auth-form">
|
||||
<div>
|
||||
<input class="form__text" type="text" name="username" placeholder="Username">
|
||||
</div>
|
||||
<div>
|
||||
<input class="form__text" type="password" name="password" placeholder="Password">
|
||||
</div>
|
||||
<div>
|
||||
<input class="form__text" type="text" name="email" placeholder="E-mail">
|
||||
</div>
|
||||
<div>
|
||||
<button class="button">Create your account!</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button class="button">Create your account!</button>
|
||||
</div>
|
||||
</div>
|
||||
{{ parent() }}
|
||||
{{ parent() }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Reference in a new issue