This is stupid anyway.

This commit is contained in:
flash 2018-02-21 15:39:16 +01:00
parent 95ec65d20a
commit 297081e8c9
2 changed files with 14 additions and 50 deletions

View file

@ -77,41 +77,15 @@ class AuthController extends Controller
);
}
private function hasRegistrations(?string $ipAddr = null): bool
{
$ipAddr = IP::unpack($ipAddr ?? IP::remote());
if ($ipAddr === IP::unpack('127.0.0.1') || $ipAddr === IP::unpack('::1')) {
return false;
}
if (User::withTrashed()->where('register_ip', $ipAddr)->orWhere('last_ip', $ipAddr)->count()) {
return true;
}
return false;
}
public function register()
{
$app = Application::getInstance();
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$twig = $app->templating;
$twig->vars([
'has_registrations' => $this->hasRegistrations(),
]);
return $twig->render('auth.register');
}
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!"];
}

View file

@ -4,34 +4,24 @@
{% block banner_content %}
<h1 style="align-self: center; text-align: left; flex-grow: 1; padding-left: 2em">
{% if has_registrations %}
Your IP address already has an account!
{% else %}
Welcome, thanks for dropping by!
{% endif %}
Welcome, thanks for dropping by!
</h1>
{% endblock %}
{% block content %}
{% 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 class="platform form" id="auth-form">
<div>
<input class="form__text" type="text" name="username" placeholder="Username">
</div>
{% 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>
<input class="form__text" type="password" name="password" placeholder="Password">
</div>
{{ parent() }}
{% endif %}
<div>
<input class="form__text" type="text" name="email" placeholder="E-mail">
</div>
<div>
<button class="button">Create your account!</button>
</div>
</div>
{{ parent() }}
{% endblock %}