-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- docker-compose - add postfix image - backend - add SMTP_HOST to settings - send user an email with a verification link when they sign up - frontend - add /verify/[[code]] route - shows message & login page if verification successful, or account is already verified - shows error message otherwise - resolves #109
- Loading branch information
Showing
7 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import { verifyVerify } from "$lib/client/services.gen"; | ||
import UserLogin from "$lib/components/UserLogin.svelte"; | ||
import { | ||
CheckCircleOutline, | ||
ExclamationCircleOutline, | ||
} from "flowbite-svelte-icons"; | ||
import { onMount } from "svelte"; | ||
import { _ } from "svelte-i18n"; | ||
onMount(async () => { | ||
const { data, error } = await verifyVerify({ | ||
body: { token: $page.params.code }, | ||
}); | ||
if ((!error && data) || error?.detail === "VERIFY_USER_ALREADY_VERIFIED") { | ||
success = true; | ||
return; | ||
} | ||
console.log(error); | ||
success = false; | ||
}); | ||
let success: boolean = $state(false); | ||
</script> | ||
|
||
<div class="m-2 mx-auto flex flex-col w-full items-center justify-center p-2 text-gray-700 dark:text-gray-400"> | ||
{#if success} | ||
<div class="flex flex-row"> | ||
<CheckCircleOutline size="xl" color="green" class="m-2"/> | ||
<div class="m-2 p-2"> | ||
{$_('registration.emailValidationMessage')} | ||
</div> | ||
</div> | ||
<UserLogin/> | ||
{:else} | ||
<div class="flex flex-row"> | ||
<ExclamationCircleOutline size="xl" color="red" class="m-2"/> | ||
<div class="m-2 p-2"> | ||
{$_('registration.emailValidationError')} | ||
</div> | ||
</div> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import smtplib | ||
from email.message import EmailMessage | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
|
||
class SMTPMock: | ||
last_message: EmailMessage | None = None | ||
|
||
def __init__(self, *args, **kwargs): | ||
pass | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, *args): | ||
pass | ||
|
||
def send_message(self, msg: EmailMessage, **kwargs): | ||
SMTPMock.last_message = msg | ||
|
||
|
||
@pytest.fixture | ||
def smtp_mock(monkeypatch: pytest.MonkeyPatch): | ||
monkeypatch.setattr(smtplib, "SMTP", SMTPMock) | ||
return SMTPMock | ||
|
||
|
||
def test_register_new_user(public_client: TestClient, smtp_mock: SMTPMock): | ||
assert smtp_mock.last_message is None | ||
email = "u1@asdgdasf.com" | ||
response = public_client.post( | ||
"/auth/register", json={"email": email, "password": "p1"} | ||
) | ||
assert response.status_code == 201 | ||
msg = smtp_mock.last_message | ||
assert msg is not None | ||
assert "aktivieren" in msg.get("Subject").lower() | ||
assert msg.get("To") == email | ||
assert "/verify/" in msg.get_content() |