resend_verification.html 111 lignes · 4453 octets
{% extends "base.html" %}

{% block title %}{{ page_title }}{% endblock %}

{% block content %}
<div class="min-h-screen flex items-center justify-center bg-base-200 px-4">
    <div class="max-w-lg w-full space-y-6">
        <div class="text-center">
            <h1 class="text-3xl font-bold text-base-content mb-2">{{ title }}</h1>
            <p class="text-base-content/70">
                {{ subtitle }}
            </p>
        </div>

        <div id="alert-error" class="hidden alert alert-error">
            <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
            <span id="alert-error-text"></span>
        </div>

        <div id="alert-success" class="hidden alert alert-success">
            <svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
            <span id="alert-success-text"></span>
        </div>

        <div class="card bg-base-100 shadow-xl p-8">
            <form id="resend-form" class="space-y-4">
                <div class="form-control">
                    <label for="email" class="label">
                        <span class="label-text">{{ email_label }}</span>
                    </label>
                    <input
                        type="email"
                        id="email"
                        name="email"
                        required
                        autocomplete="email"
                        class="input input-bordered w-full"
                        placeholder="{{ email_placeholder }}">
                </div>

                <div class="form-control mt-6">
                    <button type="submit" class="btn btn-primary w-full">
                        {{ submit }}
                    </button>
                </div>
            </form>

            <div class="mt-4 text-sm text-base-content/70 text-center space-y-2">
                <a href="/login" class="text-primary hover:underline">{{ back_to_login }}</a>
            </div>
        </div>
    </div>
</div>

<script>
    const MSG_ERROR_DEFAULT = "{{ error_default }}";
    const MSG_SUCCESS_DEFAULT = "{{ success_default }}";
    const MSG_ERROR_MISSING_EMAIL = "{{ error_missing_email }}";
    const MSG_ERROR_CANNOT_SEND = "{{ error_cannot_send }}";

    const form = document.getElementById('resend-form');
    const alertError = document.getElementById('alert-error');
    const alertErrorText = document.getElementById('alert-error-text');
    const alertSuccess = document.getElementById('alert-success');
    const alertSuccessText = document.getElementById('alert-success-text');

    function showError(msg) {
        if (alertError && alertErrorText) {
            alertErrorText.textContent = msg || MSG_ERROR_DEFAULT;
            alertError.classList.remove('hidden');
        }
        if (alertSuccess) alertSuccess.classList.add('hidden');
    }

    function showSuccess(msg) {
        if (alertSuccess && alertSuccessText) {
            alertSuccessText.textContent = msg || MSG_SUCCESS_DEFAULT;
            alertSuccess.classList.remove('hidden');
        }
        if (alertError) alertError.classList.add('hidden');
    }

    form?.addEventListener('submit', (e) => {
        e.preventDefault();
        const email = document.getElementById('email')?.value;
        if (!email) {
            showError(MSG_ERROR_MISSING_EMAIL);
            return;
        }
        fetch('/api/v1/auth/resend-verification', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ email }),
            credentials: 'include'
        })
        .then(async (resp) => {
            let msg = '';
            try {
                const data = await resp.json();
                msg = data.message || data.error || msg;
            } catch (_) {}
            if (resp.ok) {
                showSuccess(msg || MSG_SUCCESS_DEFAULT);
            } else {
                showError(msg || MSG_ERROR_CANNOT_SEND);
            }
        })
        .catch(() => showError(MSG_ERROR_CANNOT_SEND));
    });
</script>
{% endblock %}