nextcloud-install/register-ui/public/app.js
2026-06-24 09:23:58 +03:00

72 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const form = document.getElementById('register-form');
const formError = document.getElementById('form-error');
const successBlock = document.getElementById('success');
const closedBanner = document.getElementById('closed-banner');
const submitBtn = document.getElementById('submit-btn');
let config = {};
async function loadConfig() {
const res = await fetch('/api/config');
config = await res.json();
document.getElementById('footer-login').href = config.nextcloudUrl;
document.getElementById('login-link').href = config.nextcloudUrl;
if (config.allowedEmailDomains?.length) {
document.getElementById('email-hint').textContent =
`Только: ${config.allowedEmailDomains.join(', ')}`;
}
if (!config.enabled) {
closedBanner.classList.remove('hidden');
form.classList.add('hidden');
submitBtn.disabled = true;
}
}
form.addEventListener('submit', async (e) => {
e.preventDefault();
formError.classList.add('hidden');
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
const password2 = document.getElementById('password2').value;
const email = document.getElementById('email').value.trim();
const displayName = document.getElementById('displayName').value.trim();
if (password !== password2) {
formError.textContent = 'Пароли не совпадают';
formError.classList.remove('hidden');
return;
}
submitBtn.disabled = true;
submitBtn.textContent = 'Создание…';
try {
const res = await fetch('/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password, email, displayName }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'Ошибка');
form.classList.add('hidden');
successBlock.classList.remove('hidden');
document.getElementById('success-user').textContent = username;
document.getElementById('login-link').href = data.loginUrl || config.nextcloudUrl;
} catch (err) {
formError.textContent = err.message;
formError.classList.remove('hidden');
submitBtn.disabled = false;
submitBtn.textContent = 'Зарегистрироваться';
}
});
loadConfig().catch(() => {
formError.textContent = 'Не удалось загрузить настройки';
formError.classList.remove('hidden');
});