-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.html
51 lines (46 loc) · 1.97 KB
/
register.html
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
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LinkUp - Rejestracja</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="form-card">
<h2>Rejestracja</h2>
<form id="registerForm">
<div class="input-group">
<input type="text" id="registerUsername" placeholder="Nazwa użytkownika" required>
</div>
<div class="input-group">
<input type="password" id="registerPassword" placeholder="Hasło" required>
</div>
<button type="submit" class="btn">Zarejestruj się</button>
</form>
<p>Masz już konto? <a href="index.html">Zaloguj się</a></p>
</div>
</div>
<script>
const registerForm = document.getElementById('registerForm');
const registerUsernameInput = document.getElementById('registerUsername');
const registerPasswordInput = document.getElementById('registerPassword');
registerForm.addEventListener('submit', function(event) {
event.preventDefault();
const username = registerUsernameInput.value.trim();
const password = registerPasswordInput.value.trim();
const users = JSON.parse(localStorage.getItem('users')) || [];
const existingUser = users.find(user => user.username === username);
if (!existingUser) {
users.push({ username, password });
localStorage.setItem('users', JSON.stringify(users));
alert('Zarejestrowano pomyślnie! Możesz się teraz zalogować.');
window.location.href = 'index.html';
} else {
alert('Ten użytkownik już istnieje.');
}
});
</script>
</body>
</html>