feat: add 6-digit code email verification to signup flow

- POST /v1/signup/free now returns verification code (temp in response)
- New POST /v1/signup/verify endpoint to verify code and get API key
- Codes expire after 15 minutes, max 3 attempts
- Frontend updated with 2-step signup modal (email → code → key)
- Legacy token verification kept for existing links
This commit is contained in:
OpenClaw 2026-02-14 18:25:55 +00:00
parent 0a3f935af1
commit f59b99203e
4 changed files with 219 additions and 59 deletions

View file

@ -1,6 +1,9 @@
var signupEmail = '';
function showState(state) {
['signupInitial', 'signupLoading', 'signupResult'].forEach(function(id) {
document.getElementById(id).classList.remove('active');
['signupInitial', 'signupLoading', 'signupVerify', 'signupResult'].forEach(function(id) {
var el = document.getElementById(id);
if (el) el.classList.remove('active');
});
document.getElementById(state).classList.add('active');
}
@ -9,7 +12,10 @@ function openSignup() {
document.getElementById('signupModal').classList.add('active');
showState('signupInitial');
document.getElementById('signupError').style.display = 'none';
document.getElementById('verifyError').style.display = 'none';
document.getElementById('signupEmail').value = '';
document.getElementById('verifyCode').value = '';
signupEmail = '';
}
function closeSignup() {
@ -48,8 +54,11 @@ async function submitSignup() {
return;
}
// Show "check your email" message
showState('signupResult');
signupEmail = email;
document.getElementById('verifyEmailDisplay').textContent = email;
showState('signupVerify');
document.getElementById('verifyCode').focus();
btn.disabled = false;
} catch (err) {
showState('signupInitial');
errEl.textContent = 'Network error. Please try again.';
@ -58,11 +67,50 @@ async function submitSignup() {
}
}
async function submitVerify() {
var errEl = document.getElementById('verifyError');
var btn = document.getElementById('verifyBtn');
var codeInput = document.getElementById('verifyCode');
var code = codeInput.value.trim();
if (!code || !/^\d{6}$/.test(code)) {
errEl.textContent = 'Please enter a 6-digit code.';
errEl.style.display = 'block';
return;
}
errEl.style.display = 'none';
btn.disabled = true;
try {
var res = await fetch('/v1/signup/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: signupEmail, code: code })
});
var data = await res.json();
if (!res.ok) {
errEl.textContent = data.error || 'Verification failed.';
errEl.style.display = 'block';
btn.disabled = false;
return;
}
document.getElementById('apiKeyText').textContent = data.apiKey;
showState('signupResult');
} catch (err) {
errEl.textContent = 'Network error. Please try again.';
errEl.style.display = 'block';
btn.disabled = false;
}
}
function copyKey() {
var key = document.getElementById('apiKeyText').textContent;
var btn = document.getElementById('copyBtn');
function showCopied() {
btn.textContent = '✓ Copied!';
btn.textContent = '\u2713 Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 2000);
}
try {
@ -96,6 +144,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('btn-checkout').addEventListener('click', checkout);
document.getElementById('btn-close-signup').addEventListener('click', closeSignup);
document.getElementById('signupBtn').addEventListener('click', submitSignup);
document.getElementById('verifyBtn').addEventListener('click', submitVerify);
document.getElementById('signupModal').addEventListener('click', function(e) {
if (e.target === this) closeSignup();
});