The PHP app runs on Cafe24 shared web hosting -- calling it 'cloud' was misleading. Renames the directory, the edge client module, and every doc/script/identifier that used the term. - cloud/ -> server/ (incl. server/deploy/build_cafe24_package.sh paths) - edge/cloudclient.py -> edge/serverclient.py, CloudClient -> ServerClient - cloud/docs/cloud-deploy.md -> server/docs/server-deploy.md - CLOUD_* env/config keys -> SERVER_* - tests renamed to match Tests: PHP 109 pass (4 skipped), pytest 167 pass. dist/ regenerated.
79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
/**
|
|
* Login form handler: intercepts form submission and submits via fetch.
|
|
* On success (200), redirects to dashboard. On error (401/423), shows
|
|
* the #login-error element with a user-friendly message.
|
|
*
|
|
* XSS-safe: all dynamic values are set via textContent, never innerHTML.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
// Mount prefix: '' at the web root, '/move_detect' when the app shares a www/ with another
|
|
// site. Injected by src/View/layout.php from the server's SCRIPT_NAME.
|
|
var B = window.APP_BASE || '';
|
|
|
|
var form = document.querySelector('.login-form');
|
|
if (!form) return;
|
|
|
|
var errorEl = document.getElementById('login-error');
|
|
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
|
|
// Hide any previous error message
|
|
if (errorEl) {
|
|
errorEl.setAttribute('hidden', '');
|
|
errorEl.textContent = '';
|
|
}
|
|
|
|
// Collect form data and convert to application/x-www-form-urlencoded
|
|
var formData = new FormData(form);
|
|
var body = new URLSearchParams(formData).toString();
|
|
|
|
fetch(B + '/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
body: body
|
|
})
|
|
.then(function (res) {
|
|
if (res.status === 200) {
|
|
// Success: redirect to dashboard
|
|
window.location.href = B + '/';
|
|
return null;
|
|
}
|
|
// Error: parse response and show error message
|
|
if (!res.ok) throw new Error('login_failed:' + res.status);
|
|
return res.json();
|
|
})
|
|
.then(function (data) {
|
|
if (data && data.error) {
|
|
showError(data.error);
|
|
}
|
|
})
|
|
.catch(function (err) {
|
|
// Extract status code from error message if available
|
|
var status = /login_failed:(\d+)/.exec(String(err)) ? parseInt(RegExp.$1) : 0;
|
|
if (status === 401 || status === 0) {
|
|
showError('invalid_credentials');
|
|
} else if (status === 423) {
|
|
showError('locked');
|
|
}
|
|
});
|
|
});
|
|
|
|
function showError(errorCode) {
|
|
if (!errorEl) return;
|
|
|
|
var message;
|
|
if (errorCode === 'invalid_credentials') {
|
|
message = '로그인 실패';
|
|
} else if (errorCode === 'locked') {
|
|
message = '계정 잠김';
|
|
} else {
|
|
message = '로그인 실패';
|
|
}
|
|
|
|
errorEl.textContent = message;
|
|
errorEl.removeAttribute('hidden');
|
|
}
|
|
})();
|