|
1 | 1 | from typing import TYPE_CHECKING
|
2 | 2 |
|
3 |
| -from dominate.tags import section |
4 |
| -from dominate.util import raw |
| 3 | +from django.urls import reverse |
| 4 | +from dominate.tags import button, div, form, p, section |
5 | 5 |
|
6 |
| -from apps.lichess_bridge.authentication import ( |
7 |
| - get_lichess_token_retrieval_via_oauth2_process_starting_url, |
8 |
| -) |
| 6 | +from apps.webui.components import common_styles |
| 7 | +from apps.webui.components.forms_common import csrf_hidden_input |
9 | 8 | from apps.webui.components.layout import page
|
10 | 9 |
|
| 10 | +from ...lichess_api import get_lichess_api_client |
| 11 | +from ..misc_ui import detach_lichess_account_form |
| 12 | +from ..svg_icons import ICON_SVG_LOG_IN |
| 13 | + |
11 | 14 | if TYPE_CHECKING:
|
12 | 15 | from django.http import HttpRequest
|
13 | 16 |
|
14 |
| - from apps.lichess_bridge.authentication import ( |
15 |
| - LichessTokenRetrievalProcessContext, |
16 |
| - ) |
| 17 | + from ...models import LichessAccessToken |
17 | 18 |
|
18 | 19 |
|
19 | 20 | def lichess_no_account_linked_page(
|
20 | 21 | *,
|
21 | 22 | request: "HttpRequest",
|
22 |
| - lichess_oauth2_process_context: "LichessTokenRetrievalProcessContext", |
23 | 23 | ) -> str:
|
24 |
| - target_url = get_lichess_token_retrieval_via_oauth2_process_starting_url( |
25 |
| - context=lichess_oauth2_process_context |
26 |
| - ) |
27 |
| - |
28 | 24 | return page(
|
29 | 25 | section(
|
30 |
| - raw(f"""Click here: <a href="{target_url}">{target_url}</a>"""), |
| 26 | + form( |
| 27 | + csrf_hidden_input(request), |
| 28 | + p("Click here to log in to Lichess"), |
| 29 | + button( |
| 30 | + "Log in via Lichess", |
| 31 | + " ", |
| 32 | + ICON_SVG_LOG_IN, |
| 33 | + type="submit", |
| 34 | + cls=common_styles.BUTTON_CLASSES, |
| 35 | + ), |
| 36 | + action=reverse("lichess_bridge:oauth2_start_flow"), |
| 37 | + method="POST", |
| 38 | + ), |
31 | 39 | cls="text-slate-50",
|
32 | 40 | ),
|
33 | 41 | request=request,
|
34 | 42 | title="Lichess - no account linked",
|
35 | 43 | )
|
| 44 | + |
| 45 | + |
| 46 | +def lichess_account_linked_homepage( |
| 47 | + *, |
| 48 | + request: "HttpRequest", |
| 49 | + access_token: "LichessAccessToken", |
| 50 | +) -> str: |
| 51 | + me = get_lichess_api_client(access_token).account.get() |
| 52 | + |
| 53 | + return page( |
| 54 | + div( |
| 55 | + section( |
| 56 | + f'Hello {me["username"]}!', |
| 57 | + cls="text-slate-50", |
| 58 | + ), |
| 59 | + div( |
| 60 | + detach_lichess_account_form(request), |
| 61 | + cls="mt-4", |
| 62 | + ), |
| 63 | + cls="w-full mx-auto bg-slate-900 min-h-48 " |
| 64 | + "md:max-w-3xl xl:max-w-7xl xl:border xl:rounded-md xl:border-neutral-800", |
| 65 | + ), |
| 66 | + request=request, |
| 67 | + title="Lichess - account linked", |
| 68 | + ) |
0 commit comments