diff --git a/aurweb/routers/accounts.py b/aurweb/routers/accounts.py index 689f7f58..c7c96003 100644 --- a/aurweb/routers/accounts.py +++ b/aurweb/routers/accounts.py @@ -3,7 +3,7 @@ import copy from datetime import datetime from http import HTTPStatus -from fastapi import APIRouter, Form, Request +from fastapi import APIRouter, Form, HTTPException, Request from fastapi.responses import HTMLResponse, RedirectResponse from sqlalchemy import and_, func, or_ @@ -553,4 +553,18 @@ async def account_edit_post(request: Request, # Update cookies with requests, in case they were changed. response = render_template(request, "account/edit.html", context) return util.migrate_cookies(request, response) ->>>>>> > dddd1137... add account edit(settings) routes + + +@router.get("/account/{username}") +@auth_required(True, template=("account/show.html", "Accounts")) +async def account(request: Request, username: str): + user = db.query(User, User.Username == username).first() + + context = await make_variable_context(request, "Accounts") + + if not user: + raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) + + context["user"] = user + + return render_template(request, "account/show.html", context) diff --git a/templates/account/show.html b/templates/account/show.html new file mode 100644 index 00000000..139ff1f5 --- /dev/null +++ b/templates/account/show.html @@ -0,0 +1,96 @@ +{% extends "partials/layout.html" %} + +{% block pageContent %} +
+

{% trans %}Accounts{% endtrans %}

+ + {% if not request.user.is_authenticated() %} + {% trans %}You must log in to view user information.{% endtrans %} + {% else %} + + + + + +
+

{{ user.Username }}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{% trans %}Username{% endtrans %}:{{ user.Username }}
{% trans %}Account Type{% endtrans %}:{{ user.AccountType }}
{% trans %}Email Address{% endtrans %}: + {{ user.Email }} +
{% trans %}Real Name{% endtrans %}:{{ user.RealName }}
{% trans %}Homepage{% endtrans %}: + {% if user.Homepage %} + {{ user.Homepage }} + {% endif %} +
{% trans %}IRC Nick{% endtrans %}:{{ user.IRCNick }}
{% trans %}PGP Key Fingerprint{% endtrans %}:{{ user.PGPKey or '' }}
{% trans %}Status{% endtrans %}:{{ "Active" if not user.Suspended else "Suspended" | tr }}
{% trans %}Registration date{% endtrans %}: + {{ user.RegistrationTS.strftime("%Y-%m-%d") }} +
{% trans %}Links{% endtrans %}: + +
+
+ {% endif %} +
+{% endblock %} diff --git a/test/test_accounts_routes.py b/test/test_accounts_routes.py index 540adde7..c42736fa 100644 --- a/test/test_accounts_routes.py +++ b/test/test_accounts_routes.py @@ -869,4 +869,33 @@ def test_post_account_edit_password(): assert user.valid_password("newPassword") ->>>>>> > dddd1137... add account edit(settings) routes +def test_get_account(): + request = Request() + sid = user.login(request, "testPassword") + + with client as request: + response = request.get("/account/test", cookies={"AURSID": sid}, + allow_redirects=False) + + assert response.status_code == int(HTTPStatus.OK) + + +def test_get_account_not_found(): + request = Request() + sid = user.login(request, "testPassword") + + with client as request: + response = request.get("/account/not_found", cookies={"AURSID": sid}, + allow_redirects=False) + + assert response.status_code == int(HTTPStatus.NOT_FOUND) + + +def test_get_account_unauthenticated(): + with client as request: + response = request.get("/account/test", allow_redirects=False) + + assert response.status_code == int(HTTPStatus.UNAUTHORIZED) + + content = response.content.decode() + assert "You must log in to view user information." in content