1234567891011121314151617181920212223242526 |
- document.getElementById('login-form').addEventListener('submit', function(event) {
- event.preventDefault();
- const username = document.getElementById('username').value;
- const password = document.getElementById('password').value;
- const message = document.getElementById('message');
- let users = [];
- if (localStorage.getItem('users')) {
- users = JSON.parse(localStorage.getItem('users'));
- }
- const user = users.find(u => u.username === username && u.password === password);
- if (!user) {
- message.textContent = "Неправильное имя пользователя или пароль!";
- message.style.color = "red";
- return;
- }
- localStorage.setItem('currentUser', JSON.stringify(user));
- message.textContent = "Вход выполнен успешно!";
- message.style.color = "green";
- setTimeout(() => {
- window.location.href = 'profile.html';
- }, 2000);
- });
|