519 lines
16 KiB
HTML
519 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="id">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Register - Lost & Found</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
:root {
|
|
--primary: #2563eb;
|
|
--primary-dark: #1e40af;
|
|
--danger: #ef4444;
|
|
--success: #10b981;
|
|
--warning: #f59e0b;
|
|
--light: #f8fafc;
|
|
--dark: #1e293b;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 20px;
|
|
}
|
|
|
|
.register-container {
|
|
background: white;
|
|
border-radius: 20px;
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
overflow: hidden;
|
|
max-width: 500px;
|
|
width: 100%;
|
|
margin: 20px auto;
|
|
}
|
|
|
|
.register-header {
|
|
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
|
|
color: white;
|
|
padding: 40px 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.register-header h1 {
|
|
font-size: 2rem;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.register-header p {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.register-body {
|
|
padding: 40px 30px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: var(--dark);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.form-group input,
|
|
.form-group select {
|
|
width: 100%;
|
|
padding: 12px 15px;
|
|
border: 2px solid #e2e8f0;
|
|
border-radius: 10px;
|
|
font-size: 1rem;
|
|
transition: border-color 0.3s;
|
|
}
|
|
|
|
.form-group input:focus,
|
|
.form-group select:focus {
|
|
outline: none;
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.form-group input.error,
|
|
.form-group select.error {
|
|
border-color: var(--danger);
|
|
}
|
|
|
|
.error-message {
|
|
color: var(--danger);
|
|
font-size: 0.85rem;
|
|
margin-top: 5px;
|
|
display: none;
|
|
}
|
|
|
|
.error-message.show {
|
|
display: block;
|
|
}
|
|
|
|
.alert {
|
|
padding: 12px 15px;
|
|
border-radius: 10px;
|
|
margin-bottom: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.alert.show {
|
|
display: block;
|
|
}
|
|
|
|
.alert-error {
|
|
background: #fee;
|
|
color: var(--danger);
|
|
border: 1px solid var(--danger);
|
|
}
|
|
|
|
.alert-success {
|
|
background: #efe;
|
|
color: var(--success);
|
|
border: 1px solid var(--success);
|
|
}
|
|
|
|
.password-strength {
|
|
margin-top: 5px;
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
.strength-weak {
|
|
color: var(--danger);
|
|
}
|
|
|
|
.strength-medium {
|
|
color: var(--warning);
|
|
}
|
|
|
|
.strength-strong {
|
|
color: var(--success);
|
|
}
|
|
|
|
.btn-register {
|
|
width: 100%;
|
|
padding: 15px;
|
|
background: var(--primary);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 10px;
|
|
font-size: 1.1rem;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.btn-register:hover {
|
|
background: var(--primary-dark);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 20px rgba(37, 99, 235, 0.3);
|
|
}
|
|
|
|
.btn-register:disabled {
|
|
background: #94a3b8;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.divider {
|
|
text-align: center;
|
|
margin: 25px 0;
|
|
color: #64748b;
|
|
position: relative;
|
|
}
|
|
|
|
.divider::before,
|
|
.divider::after {
|
|
content: '';
|
|
position: absolute;
|
|
top: 50%;
|
|
width: 45%;
|
|
height: 1px;
|
|
background: #e2e8f0;
|
|
}
|
|
|
|
.divider::before {
|
|
left: 0;
|
|
}
|
|
|
|
.divider::after {
|
|
right: 0;
|
|
}
|
|
|
|
.login-link {
|
|
text-align: center;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.login-link a {
|
|
color: var(--primary);
|
|
text-decoration: none;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.login-link a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.back-home {
|
|
text-align: center;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.back-home a {
|
|
color: #64748b;
|
|
text-decoration: none;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.back-home a:hover {
|
|
color: var(--primary);
|
|
}
|
|
|
|
.loading {
|
|
display: inline-block;
|
|
width: 20px;
|
|
height: 20px;
|
|
border: 3px solid rgba(255,255,255,.3);
|
|
border-radius: 50%;
|
|
border-top-color: white;
|
|
animation: spin 1s ease-in-out infinite;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
.form-row {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 15px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.register-container {
|
|
margin: 10px;
|
|
}
|
|
|
|
.register-header {
|
|
padding: 30px 20px;
|
|
}
|
|
|
|
.register-body {
|
|
padding: 30px 20px;
|
|
}
|
|
|
|
.form-row {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="register-container">
|
|
<div class="register-header">
|
|
<h1>🔐 Register</h1>
|
|
<p>Buat akun Lost & Found System</p>
|
|
</div>
|
|
|
|
<div class="register-body">
|
|
<div id="alertBox" class="alert"></div>
|
|
|
|
<form id="registerForm">
|
|
<div class="form-group">
|
|
<label for="name">Nama Lengkap</label>
|
|
<input type="text" id="name" name="name" placeholder="John Doe" required>
|
|
<div class="error-message" id="nameError">Nama minimal 3 karakter</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" name="email" placeholder="mahasiswa@example.com" required>
|
|
<div class="error-message" id="emailError">Email tidak valid</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="nrp">NRP</label>
|
|
<input type="text" id="nrp" name="nrp" placeholder="5026211234" required>
|
|
<div class="error-message" id="nrpError">NRP minimal 10 digit</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="phone">No. Telepon</label>
|
|
<input type="tel" id="phone" name="phone" placeholder="08123456789" required>
|
|
<div class="error-message" id="phoneError">Nomor tidak valid</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" name="password" placeholder="********" required>
|
|
<div class="password-strength" id="passwordStrength"></div>
|
|
<div class="error-message" id="passwordError">Password minimal 8 karakter</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="confirmPassword">Konfirmasi Password</label>
|
|
<input type="password" id="confirmPassword" name="confirmPassword" placeholder="********" required>
|
|
<div class="error-message" id="confirmPasswordError">Password tidak cocok</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn-register" id="registerBtn">
|
|
Register
|
|
</button>
|
|
</form>
|
|
|
|
<div class="divider">atau</div>
|
|
|
|
<div class="login-link">
|
|
<p>Sudah punya akun? <a href="/login">Login disini</a></p>
|
|
</div>
|
|
|
|
<div class="back-home">
|
|
<a href="/">← Kembali ke Beranda</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const API_URL = 'http://localhost:8080/api';
|
|
|
|
const registerForm = document.getElementById('registerForm');
|
|
const nameInput = document.getElementById('name');
|
|
const emailInput = document.getElementById('email');
|
|
const nrpInput = document.getElementById('nrp');
|
|
const phoneInput = document.getElementById('phone');
|
|
const passwordInput = document.getElementById('password');
|
|
const confirmPasswordInput = document.getElementById('confirmPassword');
|
|
const registerBtn = document.getElementById('registerBtn');
|
|
const alertBox = document.getElementById('alertBox');
|
|
|
|
// Validasi Email
|
|
function validateEmail(email) {
|
|
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
return re.test(email);
|
|
}
|
|
|
|
// Validasi Phone
|
|
function validatePhone(phone) {
|
|
const re = /^(08|62)[0-9]{9,12}$/;
|
|
return re.test(phone);
|
|
}
|
|
|
|
// Check password strength
|
|
function checkPasswordStrength(password) {
|
|
const strengthEl = document.getElementById('passwordStrength');
|
|
let strength = 0;
|
|
|
|
if (password.length >= 8) strength++;
|
|
if (password.match(/[a-z]+/)) strength++;
|
|
if (password.match(/[A-Z]+/)) strength++;
|
|
if (password.match(/[0-9]+/)) strength++;
|
|
if (password.match(/[$@#&!]+/)) strength++;
|
|
|
|
if (password.length < 8) {
|
|
strengthEl.textContent = '';
|
|
strengthEl.className = 'password-strength';
|
|
} else if (strength <= 2) {
|
|
strengthEl.textContent = '⚠️ Password lemah';
|
|
strengthEl.className = 'password-strength strength-weak';
|
|
} else if (strength <= 4) {
|
|
strengthEl.textContent = '✓ Password sedang';
|
|
strengthEl.className = 'password-strength strength-medium';
|
|
} else {
|
|
strengthEl.textContent = '✓ Password kuat';
|
|
strengthEl.className = 'password-strength strength-strong';
|
|
}
|
|
}
|
|
|
|
// Show Alert
|
|
function showAlert(message, type = 'error') {
|
|
alertBox.textContent = message;
|
|
alertBox.className = `alert alert-${type} show`;
|
|
setTimeout(() => {
|
|
alertBox.classList.remove('show');
|
|
}, 5000);
|
|
}
|
|
|
|
// Clear errors
|
|
function clearErrors() {
|
|
document.querySelectorAll('.error-message').forEach(el => {
|
|
el.classList.remove('show');
|
|
});
|
|
document.querySelectorAll('input').forEach(el => {
|
|
el.classList.remove('error');
|
|
});
|
|
}
|
|
|
|
// Password strength checker
|
|
passwordInput.addEventListener('input', (e) => {
|
|
checkPasswordStrength(e.target.value);
|
|
});
|
|
|
|
// Form submit
|
|
registerForm.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
clearErrors();
|
|
|
|
const name = nameInput.value.trim();
|
|
const email = emailInput.value.trim();
|
|
const nrp = nrpInput.value.trim();
|
|
const phone = phoneInput.value.trim();
|
|
const password = passwordInput.value;
|
|
const confirmPassword = confirmPasswordInput.value;
|
|
|
|
// Validasi frontend
|
|
let hasError = false;
|
|
|
|
if (name.length < 3) {
|
|
nameInput.classList.add('error');
|
|
document.getElementById('nameError').classList.add('show');
|
|
hasError = true;
|
|
}
|
|
|
|
if (!validateEmail(email)) {
|
|
emailInput.classList.add('error');
|
|
document.getElementById('emailError').classList.add('show');
|
|
hasError = true;
|
|
}
|
|
|
|
if (nrp.length < 10) {
|
|
nrpInput.classList.add('error');
|
|
document.getElementById('nrpError').classList.add('show');
|
|
hasError = true;
|
|
}
|
|
|
|
if (!validatePhone(phone)) {
|
|
phoneInput.classList.add('error');
|
|
document.getElementById('phoneError').classList.add('show');
|
|
hasError = true;
|
|
}
|
|
|
|
if (password.length < 8) {
|
|
passwordInput.classList.add('error');
|
|
document.getElementById('passwordError').classList.add('show');
|
|
hasError = true;
|
|
}
|
|
|
|
if (password !== confirmPassword) {
|
|
confirmPasswordInput.classList.add('error');
|
|
document.getElementById('confirmPasswordError').classList.add('show');
|
|
hasError = true;
|
|
}
|
|
|
|
if (hasError) return;
|
|
|
|
// Disable button dan tampilkan loading
|
|
registerBtn.disabled = true;
|
|
registerBtn.innerHTML = '<span class="loading"></span> Registering...';
|
|
|
|
try {
|
|
const response = await fetch(`${API_URL}/register`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
name,
|
|
email,
|
|
nrp,
|
|
phone,
|
|
password
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
showAlert('Registrasi berhasil! Mengalihkan ke login...', 'success');
|
|
|
|
setTimeout(() => {
|
|
window.location.href = '/login';
|
|
}, 2000);
|
|
} else {
|
|
showAlert(data.error || 'Registrasi gagal!');
|
|
}
|
|
} catch (error) {
|
|
console.error('Register error:', error);
|
|
showAlert('Terjadi kesalahan. Pastikan server berjalan di port 8080');
|
|
} finally {
|
|
registerBtn.disabled = false;
|
|
registerBtn.textContent = 'Register';
|
|
}
|
|
});
|
|
|
|
// Check jika sudah login - REFACTORED: URL lebih simple
|
|
window.addEventListener('load', () => {
|
|
const token = localStorage.getItem('token');
|
|
const user = JSON.parse(localStorage.getItem('user') || '{}');
|
|
|
|
if (token && user.role) {
|
|
// Redirect ke dashboard sesuai role
|
|
if (user.role === 'admin') {
|
|
window.location.href = '/admin'; // ✅ REFACTORED
|
|
} else if (user.role === 'manager') {
|
|
window.location.href = '/manager'; // ✅ REFACTORED
|
|
} else {
|
|
window.location.href = '/user'; // ✅ REFACTORED
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |