Skip to content

Commit

Permalink
add UI ability to create dev app with name
Browse files Browse the repository at this point in the history
  • Loading branch information
fisher60 committed Jun 6, 2024
1 parent f0ffffa commit ee0d09f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 13 additions & 5 deletions abandonauth/routers/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from fastapi.responses import HTMLResponse, RedirectResponse, Response
from fastapi.templating import Jinja2Templates
from prisma.models import DeveloperApplication
from starlette.status import HTTP_303_SEE_OTHER, HTTP_400_BAD_REQUEST, HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND
from starlette.status import (
HTTP_200_OK,
HTTP_303_SEE_OTHER,
HTTP_400_BAD_REQUEST,
HTTP_403_FORBIDDEN,
HTTP_404_NOT_FOUND,
)

from abandonauth import templates # pyright: ignore [reportAttributeAccessIssue]
from abandonauth.dependencies.services import build_abandon_auth_redirect_url, user_info_from_me_response
Expand Down Expand Up @@ -39,7 +45,7 @@ async def index(request: Request, code: str | None = None) -> RedirectResponse:
resp = await client.post(f"{BASE_URL}/login", headers=login_headers, json=login_body)

# If login failed, set token to None so that the user will be redirected back to the login page
token = None if resp.status_code != HTTPStatus.OK else resp.json().get("token")
token = None if resp.status_code != HTTP_200_OK else resp.json().get("token")
else:
token = request.cookies.get("Authorization")

Expand All @@ -48,7 +54,7 @@ async def index(request: Request, code: str | None = None) -> RedirectResponse:
if token:
async with httpx.AsyncClient() as client:
headers = {"Authorization": f"Bearer {token}"}
authenticated = (await client.get(f"{BASE_URL}/me", headers=headers)).status_code == HTTPStatus.OK
authenticated = (await client.get(f"{BASE_URL}/me", headers=headers)).status_code == HTTP_200_OK

if authenticated is False:
return RedirectResponse(build_abandon_auth_redirect_url())
Expand Down Expand Up @@ -96,7 +102,7 @@ async def create_new_developer_application_form(request: Request) -> Response:


@router.post("/applications/new", include_in_schema=False)
async def create_new_developer_applications(request: Request) -> Response:
async def create_new_developer_applications(request: Request, dev_app_name: Annotated[str, Form()]) -> Response:
"""Page for managing developer applications."""
user_info = await user_info_from_me_response(request)

Expand All @@ -105,7 +111,9 @@ async def create_new_developer_applications(request: Request) -> Response:

async with httpx.AsyncClient() as client:
headers = {"Authorization": f"Bearer {user_info.token}"}
new_dev_app = (await client.post(f"{BASE_URL}/developer_application", headers=headers)).json()
new_dev_app = (
await client.post(f"{BASE_URL}/developer_application", headers=headers, json={"name": dev_app_name})
).json()

return jinja_templates.TemplateResponse(
"created_application_info.html",
Expand Down
7 changes: 6 additions & 1 deletion abandonauth/templates/create_developer_app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
{% block content %}
{% include "navbar.html" %}
<div class="mainApp">
<h1>Create A New Developer Application</h1>
<form method="post">
<button class="button" style="margin-top: 2em;">Create Application</button>
<div class="editCallbackForm">
<label for="developer_app_name">Dev App Name</label>
<input type="text" id="developer_app_name" name="dev_app_name">
<button class="button-submit">Submit</button>
</div>
</form>
</div>
{% endblock %}

0 comments on commit ee0d09f

Please sign in to comment.