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() public function register()
{ {
$app = Application::getInstance(); $app = Application::getInstance();
if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$twig = $app->templating; $twig = $app->templating;
$twig->vars([
'has_registrations' => $this->hasRegistrations(),
]);
return $twig->render('auth.register'); 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'])) { if (!isset($_POST['username'], $_POST['password'], $_POST['email'])) {
return ['error' => "You didn't fill all the forms!"]; return ['error' => "You didn't fill all the forms!"];
} }

View file

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