diff --git a/frontend/src/components/debug/index.tsx b/frontend/src/components/debug/index.tsx index 1097897ff8bfe539ca1899e9149ca48a07293b2c..a151d73ff3a5802c4f38a2f6df20ce995393d275 100644 --- a/frontend/src/components/debug/index.tsx +++ b/frontend/src/components/debug/index.tsx @@ -82,6 +82,19 @@ export const Debug = () => { }) } + + const testMail = () => { + fetch('/api/ui/v1/testmail/', { + credentials: 'same-origin', + }) + .then((data) => { + console.log(data) + }) + .catch((err) => { + console.log(err) + }) + } + const whoami = () => { fetch('/api/ui/v1/whoami/', { headers: { @@ -151,6 +164,9 @@ export const Debug = () => { <Button type="button" onClick={() => logout()}> LOGOUT </Button> + <Button type="button" onClick={() => testMail()}> + SEND TEST MAIL + </Button> </Stack> <Box sx={{ maxWidth: '30rem' }}> <Table> diff --git a/gregui/urls.py b/gregui/urls.py index 56e17df61e6251dd7d569ba4d0a64892b440298c..cc6fa884e2da3bc3a1884dcb83b4382a0f0ac9f9 100644 --- a/gregui/urls.py +++ b/gregui/urls.py @@ -17,6 +17,7 @@ urlpatterns: List[URLResolver] = [ path("api/ui/v1/logout/", views.logout_view, name="api-logout"), path("api/ui/v1/login/", views.login_view, name="api-login"), path("api/ui/v1/session/", views.SessionView.as_view(), name="api-session"), + path("api/ui/v1/testmail/", views.send_test_email, name="api-testmail"), path("api/ui/v1/whoami/", views.WhoAmIView.as_view(), name="api-whoami"), path("api/ui/v1/userinfo/", UserInfoView.as_view()), # type: ignore path("api/ui/v1/ous/", OusView.as_view()), diff --git a/gregui/views.py b/gregui/views.py index 0801eda1a1f60441677b32e47484ec1970e1b1fd..2bf3fc9d8c59fccfc5a75fe5ae29685e34e2a23b 100644 --- a/gregui/views.py +++ b/gregui/views.py @@ -8,6 +8,7 @@ from rest_framework.views import APIView from greg.models import Role, Sponsor from greg.permissions import IsSponsor +from gregui import mailutils from gregui.models import GregUserProfile @@ -37,6 +38,11 @@ def login_view(request): return redirect("/api/ui/v1/whoami/") +def send_test_email(request): + mailutils.send_registration_mail("test@example.no", "Foo Bar") + return JsonResponse({"detail": "Created task to send test mail."}) + + class SessionView(APIView): authentication_classes = [SessionAuthentication, BasicAuthentication] permission_classes = [IsAuthenticated]