From: Michael Tremer Date: Thu, 31 Oct 2019 15:48:40 +0000 (+0000) Subject: people: Add UI for password resets X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a76ac21e46142b38c3acb3c5ffc95670f3830412;p=ipfire.org.git people: Add UI for password resets Signed-off-by: Michael Tremer --- diff --git a/src/templates/auth/login.html b/src/templates/auth/login.html index 1cf6ae89..23bdb025 100644 --- a/src/templates/auth/login.html +++ b/src/templates/auth/login.html @@ -5,10 +5,16 @@ {% block content %}
-
+
{{ _("Log In") }}
+ {% if incorrect %} +
+ {{ _("You entered an invalid username or password") }} +
+ {% end %} +
{% raw xsrf_form_html() %} @@ -16,7 +22,8 @@
+ name="username" placeholder="{{ _("Username") }}" + value="{{ username or "" }}" required autofocus>
@@ -28,6 +35,12 @@ {{ _("Log in") }} + +

+ + {{ _("Did you forget your password?") }} + +

diff --git a/src/web/auth.py b/src/web/auth.py index 4a311393..cb980666 100644 --- a/src/web/auth.py +++ b/src/web/auth.py @@ -43,27 +43,35 @@ class LoginHandler(AuthenticationMixin, base.BaseHandler): def get(self): next = self.get_argument("next", None) - self.render("auth/login.html", next=next) + self.render("auth/login.html", next=next, + incorrect=False, username=None) @base.blacklisted @base.ratelimit(minutes=60, requests=5) def post(self): username = self.get_argument("username") password = self.get_argument("password") + next = self.get_argument("next", "/") # Find user account = self.backend.accounts.auth(username, password) if not account: - raise tornado.web.HTTPError(401, "Unknown user or invalid password: %s" % username) + logging.error("Unknown user or invalid password: %s" % username) + + # Set status to 401 + self.set_status(401) + + # Render login page again + return self.render("auth/login.html", + incorrect=True, username=username, next=next, + ) # Create session with self.db.transaction(): self.login(account) - # Determine the page we should redirect to - next = self.get_argument("next", None) - - return self.redirect(next or "/") + # Redirect the user + return self.redirect(next) class LogoutHandler(AuthenticationMixin, base.BaseHandler):