Spaces:
Running
Running
File size: 4,915 Bytes
b82f276 678d065 b82f276 678d065 b82f276 678d065 b82f276 678d065 b82f276 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - Law Bot</title>
<link rel="stylesheet" href="/static/css/styles.css">
<style>
/* Reuse styles from login.html */
.auth-container {
max-width: 400px;
margin: 50px auto;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
color: white;
}
.auth-container h2 {
text-align: center;
margin-bottom: 1.5rem;
}
.form-group {
margin-bottom: 1rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
}
.form-group input {
width: 100%;
padding: 0.75rem;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 6px;
background: rgba(0, 0, 0, 0.2);
color: white;
}
.btn {
width: 100%;
padding: 0.75rem;
background: #9b87f5;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 1rem;
transition: background 0.3s;
}
.btn:hover {
background: #7e69d6;
}
.links {
margin-top: 1rem;
text-align: center;
font-size: 0.9rem;
}
.links a {
color: #D6BCFA;
text-decoration: none;
}
.links a:hover {
text-decoration: underline;
}
</style>
</head>
<body class="dark">
<div class="auth-container">
<h2>Register</h2>
<form id="registerForm">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" required>
</div>
<div class="form-group">
<label for="mobile_number">Mobile Number</label>
<input type="tel" id="mobile_number" placeholder="10-digit number" pattern="\d{10}" maxlength="10" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" required>
</div>
<input type="hidden" id="role">
<button type="submit" class="btn">Register</button>
</form>
<div class="links">
<a href="/login" id="loginLink">Already have an account? Login</a>
</div>
</div>
<script>
const urlParams = new URLSearchParams(window.location.search);
const role = urlParams.get('role');
if (role) {
document.getElementById('role').value = role;
document.getElementById('loginLink').href = `/login?role=${role}`;
}
document.getElementById('registerForm').addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('username').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const mobile_number = document.getElementById('mobile_number').value;
const roleValue = document.getElementById('role').value;
// Simple 10-digit check before submitting
if (!/^\d{10}$/.test(mobile_number)) {
alert('Please enter a valid 10-digit mobile number.');
return;
}
try {
const response = await fetch('/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, email, password, role: roleValue, mobile_number })
});
const data = await response.json();
if (response.ok) {
alert('Registration successful! Please login.');
window.location.href = `/login?role=${roleValue}`;
} else {
alert(data.detail || 'Registration failed');
}
} catch (error) {
console.error('Error:', error);
alert('An error occurred');
}
});
</script>
</body>
</html> |