mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add account (view) route
+ Added get /account/{username} route. + Added account/show.html template which shows a single use Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
4e9ef6fb00
commit
4f928b4577
3 changed files with 142 additions and 3 deletions
|
@ -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)
|
||||
|
|
96
templates/account/show.html
Normal file
96
templates/account/show.html
Normal file
|
@ -0,0 +1,96 @@
|
|||
{% extends "partials/layout.html" %}
|
||||
|
||||
{% block pageContent %}
|
||||
<div class="box">
|
||||
<h2>{% trans %}Accounts{% endtrans %}</h2>
|
||||
|
||||
{% if not request.user.is_authenticated() %}
|
||||
{% trans %}You must log in to view user information.{% endtrans %}
|
||||
{% else %}
|
||||
<table class="arch-bio-entry">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<h3>{{ user.Username }}</h3>
|
||||
<table class="bio">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{% trans %}Username{% endtrans %}:</th>
|
||||
<td>{{ user.Username }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}Account Type{% endtrans %}:</th>
|
||||
<td>{{ user.AccountType }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}Email Address{% endtrans %}:</th>
|
||||
<td>
|
||||
<a href="mailto:{{ user.Email }}">{{ user.Email }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}Real Name{% endtrans %}:</th>
|
||||
<td>{{ user.RealName }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}Homepage{% endtrans %}:</th>
|
||||
<td>
|
||||
{% if user.Homepage %}
|
||||
<a href="{{ user.Homepage }}" rel="nofollow">{{ user.Homepage }}</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}IRC Nick{% endtrans %}:</th>
|
||||
<td>{{ user.IRCNick }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}PGP Key Fingerprint{% endtrans %}:</th>
|
||||
<td>{{ user.PGPKey or '' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}Status{% endtrans %}:</th>
|
||||
<td>{{ "Active" if not user.Suspended else "Suspended" | tr }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}Registration date{% endtrans %}:</th>
|
||||
<td>
|
||||
{{ user.RegistrationTS.strftime("%Y-%m-%d") }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{% trans %}Links{% endtrans %}:</th>
|
||||
<td>
|
||||
<ul>
|
||||
<li>
|
||||
{{ "%sView this user's packages%s"
|
||||
| tr
|
||||
| format('<a href="/packages/?K=%s&SeB=m">' | format(user.Username), "</a>")
|
||||
| safe
|
||||
}}
|
||||
</li>
|
||||
<li>
|
||||
{{ "%sEdit this user's account%s"
|
||||
| tr
|
||||
| format('<a href="%s/edit">' | format(user | account_url), "</a>")
|
||||
| safe
|
||||
}}
|
||||
</li>
|
||||
<li>
|
||||
{{ "%sList this user's comments%s"
|
||||
| tr
|
||||
| format('<a href="%s/comments">' | format(user | account_url), "</a>")
|
||||
| safe
|
||||
}}
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue