52 lines
2.2 KiB
JavaScript
52 lines
2.2 KiB
JavaScript
(function () {
|
|
// Bootstrap 5을 사용한다고 가정. data-bs-* 이벤트로 처리.
|
|
const changePasswordModal = document.getElementById('changePasswordModal');
|
|
const modalUserInfo = document.getElementById('modalUserInfo');
|
|
const changePasswordForm = document.getElementById('changePasswordForm');
|
|
const newPasswordInput = document.getElementById('newPasswordInput');
|
|
const confirmPasswordInput = document.getElementById('confirmPasswordInput');
|
|
const pwMismatch = document.getElementById('pwMismatch');
|
|
|
|
if (!changePasswordModal) return;
|
|
|
|
changePasswordModal.addEventListener('show.bs.modal', function (event) {
|
|
const button = event.relatedTarget; // 버튼 that triggered the modal
|
|
const userId = button.getAttribute('data-user-id');
|
|
const username = button.getAttribute('data-username') || ('ID ' + userId);
|
|
|
|
// 표시 텍스트 세팅
|
|
modalUserInfo.textContent = username + ' (ID: ' + userId + ')';
|
|
|
|
// 폼 action 동적 설정: admin.reset_password 라우트 기대
|
|
// 예: /admin/users/123/reset_password
|
|
// Note: This assumes the URL pattern exists. Adjust if needed.
|
|
const baseUrl = changePasswordForm.getAttribute('data-base-url') || '/admin/users/0/reset_password';
|
|
changePasswordForm.action = baseUrl.replace('/0/', '/' + userId + '/');
|
|
|
|
// 폼 내부 비밀번호 필드 초기화
|
|
newPasswordInput.value = '';
|
|
confirmPasswordInput.value = '';
|
|
confirmPasswordInput.classList.remove('is-invalid');
|
|
pwMismatch.style.display = 'none';
|
|
});
|
|
|
|
// 폼 제출 전 클라이언트에서 비밀번호 일치 검사
|
|
changePasswordForm.addEventListener('submit', function (e) {
|
|
const a = newPasswordInput.value || '';
|
|
const b = confirmPasswordInput.value || '';
|
|
if (a.length < 8) {
|
|
newPasswordInput.focus();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
if (a !== b) {
|
|
e.preventDefault();
|
|
confirmPasswordInput.classList.add('is-invalid');
|
|
pwMismatch.style.display = 'block';
|
|
confirmPasswordInput.focus();
|
|
return;
|
|
}
|
|
// 제출 허용 (서버측에서도 반드시 검증)
|
|
});
|
|
})();
|