diff --git a/aurweb/routers/auth.py b/aurweb/routers/auth.py index fdc421f5..1e0b026a 100644 --- a/aurweb/routers/auth.py +++ b/aurweb/routers/auth.py @@ -24,7 +24,6 @@ async def login_template(request: Request, next: str, errors: list = None): @router.get("/login", response_class=HTMLResponse) -@auth_required(False, login=False) async def login_get(request: Request, next: str = "/"): return await login_template(request, next) diff --git a/templates/login.html b/templates/login.html index 2c028936..c62de43e 100644 --- a/templates/login.html +++ b/templates/login.html @@ -5,81 +5,95 @@

AUR {% trans %}Login{% endtrans %}

- {% if request.url.scheme == "http" and config.getboolean("options", "disable_http_login") %} - {% set https_login = url_base.replace("http://", "https://") + "/login" %} -

- {{ "HTTP login is disabled. Please %sswitch to HTTPs%s if you want to login." - | tr - | format( - '' | format(https_login), - "") - | safe - }} -

- {% elif request.user.is_authenticated() %} -

- {{ "Logged-in as: %s" - | tr - | format("%s" | format(request.user.Username)) - | safe - }} - [{% trans %}Logout{% endtrans %}] -

- {% else %} -
-
- {% trans %}Enter login credentials{% endtrans %} - - {% if errors %} -
    - {% for error in errors %} -
  • {{ error }}
  • - {% endfor %} -
- {% endif %} - -

- - - -

- -

- - -

- -

- - -

- -

- - - [{% trans %}Forgot Password{% endtrans %}] - - - -

- -
+ {% if request.user.is_authenticated() %} + +

+ {{ + "Logged-in as: %s" | tr + | format("%s" | format(request.user.Username)) + | safe + }} + + +

+ {% else %} + {% if request.url.scheme == "http" and config.getboolean("options", "disable_http_login") %} + {% set https_login = url_base.replace("http://", "https://") + "/login" %} +

+ {{ "HTTP login is disabled. Please %sswitch to HTTPs%s if you want to login." + | tr + | format( + '' | format(https_login), + "") + | safe + }} +

+ {% elif request.user.is_authenticated() %} +

+ {{ "Logged-in as: %s" + | tr + | format("%s" | format(request.user.Username)) + | safe + }} + [{% trans %}Logout{% endtrans %}] +

+ {% else %} +
+
+ {% trans %}Enter login credentials{% endtrans %} + + {% if errors %} +
    + {% for error in errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} + +

+ + + +

+ +

+ + +

+ +

+ + +

+ +

+ + + [{% trans %}Forgot Password{% endtrans %}] + + + +

+ +
+
+ {% endif %} {% endif %}
diff --git a/test/test_auth_routes.py b/test/test_auth_routes.py index dffd1b94..0157fcc8 100644 --- a/test/test_auth_routes.py +++ b/test/test_auth_routes.py @@ -131,7 +131,7 @@ def test_secure_login(mock): assert user.session == record -def test_authenticated_login_forbidden(): +def test_authenticated_login(): post_data = { "user": "test", "passwd": "testPassword", @@ -139,15 +139,19 @@ def test_authenticated_login_forbidden(): } with client as request: - # Login. + # Try to login. response = request.post("/login", data=post_data, allow_redirects=False) assert response.status_code == int(HTTPStatus.SEE_OTHER) + assert response.headers.get("location") == "/" + # Now, let's verify that we get the logged in rendering + # when requesting GET /login as an authenticated user. # Now, let's verify that we receive 403 Forbidden when we # try to get /login as an authenticated user. response = request.get("/login", allow_redirects=False) - assert response.status_code == int(HTTPStatus.SEE_OTHER) + assert response.status_code == int(HTTPStatus.OK) + assert "Logged-in as: test" in response.text def test_unauthenticated_logout_unauthorized(): diff --git a/web/html/css/aurweb.css b/web/html/css/aurweb.css index dafa8c91..739ac7b7 100644 --- a/web/html/css/aurweb.css +++ b/web/html/css/aurweb.css @@ -232,7 +232,7 @@ input#search-action-submit { /* Styling used to clone styles for a form.link button. */ form.link, form.link button { - display: inline-block; + display: inline; font-family: sans-serif; } form.link button { @@ -247,3 +247,11 @@ form.link button:hover { cursor: pointer; text-decoration: underline; } + +/* Customize form.link when used inside of a page. */ +div.box form.link p { + margin: .33em 0 1em; +} +div.box form.link button { + padding: 0; +}