Autosave: 20260225-075148
This commit is contained in:
parent
d516502011
commit
5122560397
@ -57,6 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
// API for sending code
|
// API for sending code
|
||||||
if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
||||||
|
ob_start();
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
$account = $_GET['account'] ?? '';
|
$account = $_GET['account'] ?? '';
|
||||||
$type = $_GET['type'] ?? 'email';
|
$type = $_GET['type'] ?? 'email';
|
||||||
@ -66,6 +67,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
|||||||
|
|
||||||
if ($type === 'email') {
|
if ($type === 'email') {
|
||||||
if (!filter_var($account, FILTER_VALIDATE_EMAIL)) {
|
if (!filter_var($account, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
ob_clean();
|
||||||
echo json_encode(['success' => false, 'error' => __('invalid_email')]);
|
echo json_encode(['success' => false, 'error' => __('invalid_email')]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -75,6 +77,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
|||||||
$content = __('verification_code') . ": $code";
|
$content = __('verification_code') . ": $code";
|
||||||
$res = MailService::sendMail($account, $subject, $content, $content);
|
$res = MailService::sendMail($account, $subject, $content, $content);
|
||||||
if (!$res['success']) {
|
if (!$res['success']) {
|
||||||
|
ob_clean();
|
||||||
echo json_encode(['success' => false, 'error' => $res['error'] ?? __('send_failed')]);
|
echo json_encode(['success' => false, 'error' => $res['error'] ?? __('send_failed')]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -83,6 +86,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
|||||||
// SMS logic here if needed
|
// SMS logic here if needed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ob_clean();
|
||||||
echo json_encode(['success' => true]);
|
echo json_encode(['success' => true]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -241,13 +245,25 @@ function sendCode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const btn = document.getElementById('sendBtn');
|
const btn = document.getElementById('sendBtn');
|
||||||
|
const oldText = btn.innerText;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
fetch('?action=send_code&account=' + encodeURIComponent(account) + '&type=' + type)
|
fetch('?action=send_code&account=' + encodeURIComponent(account) + '&type=' + type)
|
||||||
.then(res => res.json())
|
.then(res => {
|
||||||
|
if (!res.ok) throw new Error('Network error: ' + res.status);
|
||||||
|
return res.text().then(text => {
|
||||||
|
try {
|
||||||
|
return JSON.parse(text);
|
||||||
|
} catch(e) {
|
||||||
|
console.error('Raw response:', text);
|
||||||
|
throw new Error('Invalid JSON response');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
let seconds = 60;
|
let seconds = 60;
|
||||||
|
btn.innerText = seconds + 's';
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
seconds--;
|
seconds--;
|
||||||
btn.innerText = seconds + 's';
|
btn.innerText = seconds + 's';
|
||||||
@ -260,7 +276,14 @@ function sendCode() {
|
|||||||
} else {
|
} else {
|
||||||
alert(data.error || '<?= __('send_failed') ?>');
|
alert(data.error || '<?= __('send_failed') ?>');
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
|
btn.innerText = oldText;
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
alert('Error: ' + err.message);
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerText = oldText;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -80,12 +80,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
// Add API for sending verification code
|
// Add API for sending verification code
|
||||||
if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
||||||
|
ob_start();
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
$account = $_GET['account'] ?? '';
|
$account = $_GET['account'] ?? '';
|
||||||
$type = $_GET['type'] ?? 'email';
|
$type = $_GET['type'] ?? 'email';
|
||||||
|
|
||||||
if ($type === 'email') {
|
if ($type === 'email') {
|
||||||
if (!filter_var($account, FILTER_VALIDATE_EMAIL)) {
|
if (!filter_var($account, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
ob_clean();
|
||||||
echo json_encode(['success' => false, 'error' => __('invalid_email')]);
|
echo json_encode(['success' => false, 'error' => __('invalid_email')]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -102,6 +104,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
|||||||
$res = MailService::sendMail($account, $subject, $content, $content);
|
$res = MailService::sendMail($account, $subject, $content, $content);
|
||||||
|
|
||||||
if (!$res['success']) {
|
if (!$res['success']) {
|
||||||
|
ob_clean();
|
||||||
echo json_encode(['success' => false, 'error' => $res['error'] ?? __('send_failed')]);
|
echo json_encode(['success' => false, 'error' => $res['error'] ?? __('send_failed')]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -111,6 +114,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'send_code') {
|
|||||||
// For now, we just store it in session.
|
// For now, we just store it in session.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ob_clean();
|
||||||
echo json_encode(['success' => true]);
|
echo json_encode(['success' => true]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -296,13 +300,25 @@ function sendCode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const btn = document.getElementById('sendBtn');
|
const btn = document.getElementById('sendBtn');
|
||||||
|
const oldText = btn.innerText;
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
fetch('?action=send_code&account=' + encodeURIComponent(account) + '&type=' + type)
|
fetch('?action=send_code&account=' + encodeURIComponent(account) + '&type=' + type)
|
||||||
.then(res => res.json())
|
.then(res => {
|
||||||
|
if (!res.ok) throw new Error('Network error: ' + res.status);
|
||||||
|
return res.text().then(text => {
|
||||||
|
try {
|
||||||
|
return JSON.parse(text);
|
||||||
|
} catch(e) {
|
||||||
|
console.error('Raw response:', text);
|
||||||
|
throw new Error('Invalid JSON response');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
let seconds = 60;
|
let seconds = 60;
|
||||||
|
btn.innerText = seconds + 's';
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
seconds--;
|
seconds--;
|
||||||
btn.innerText = seconds + 's';
|
btn.innerText = seconds + 's';
|
||||||
@ -315,7 +331,14 @@ function sendCode() {
|
|||||||
} else {
|
} else {
|
||||||
alert(data.error || '<?= __('send_failed') ?>');
|
alert(data.error || '<?= __('send_failed') ?>');
|
||||||
btn.disabled = false;
|
btn.disabled = false;
|
||||||
|
btn.innerText = oldText;
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
alert('Error: ' + err.message);
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerText = oldText;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user