-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
50 lines (40 loc) · 1.44 KB
/
Copy pathauth.js
File metadata and controls
50 lines (40 loc) · 1.44 KB
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
// ARQUIVO: auth.js
// Simulação de Autenticação usando LocalStorage
const USER_STORAGE_KEY = 'synthlearn_user_account';
const LOGGED_IN_KEY = 'synthlearn_is_logged_in';
function registerUser(email, password) {
// Permite apenas UMA conta salva para simplificar a simulação
if (localStorage.getItem(USER_STORAGE_KEY)) {
return false;
}
const user = { email: email, password: password };
localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user));
localStorage.setItem(LOGGED_IN_KEY, 'true');
return true;
}
function loginUser(email, password) {
const storedUser = localStorage.getItem(USER_STORAGE_KEY);
if (!storedUser) return false;
const user = JSON.parse(storedUser);
if (user.email === email && user.password === password) {
localStorage.setItem(LOGGED_IN_KEY, 'true');
return true;
}
return false;
}
function logoutUser() {
localStorage.removeItem(LOGGED_IN_KEY);
}
function isUserLoggedIn() {
return localStorage.getItem(LOGGED_IN_KEY) === 'true';
}
function getRegisteredUser() {
const storedUser = localStorage.getItem(USER_STORAGE_KEY);
return storedUser ? JSON.parse(storedUser) : null;
}
// Exporta as funções para que possam ser usadas em outras páginas.
window.registerUser = registerUser;
window.loginUser = loginUser;
window.logoutUser = logoutUser;
window.isUserLoggedIn = isUserLoggedIn;
window.getRegisteredUser = getRegisteredUser;