-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.html
More file actions
95 lines (81 loc) · 3.45 KB
/
auth.html
File metadata and controls
95 lines (81 loc) · 3.45 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Регистрация</title>
<script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-auth-compat.js"></script>
<link rel="stylesheet" href="style_auth.css">
</head>
<body>
<form id="signup-form">
<h1>Регистрация</h1>
<input type="email" id="email" placeholder="Email" required>
<input type="password" id="password" placeholder="Password" required>
<div class="information">
<strong id="info">
</strong>
</div>
<button type="submit">Зарегистрироваться</button>
<h8><a href="login.html">Войти в аккаунт</a><h8></h8>
</form>
<script>
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "{{FIREBASE_API_KEY}}",
authDomain: "{{FIREBASE_AUTH_DOMAIN}}",
projectId: "{{FIREBASE_PROJECT_ID}}",
storageBucket: "{{FIREBASE_STORAGE_BUCKET}}",
messagingSenderId: "{{FIREBASE_MESSAGING_SENDER_ID}}",
appId: "{{FIREBASE_APP_ID}}",
measurementId: "{{FIREBASE_MEASUREMENT_ID}}"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
var delay = 0; // Время задержки между печатанием символов в милисекндах.
elem_info = document.getElementById("info"); // id элемента для вывода результата
console.log(elem_info)
var print_text = function(text, elem, delay) {
if(text.length > 0) {
elem.innerHTML = text;
}
}
var replace_text = function(elem) {
elem.innerHTML = ''
}
document.getElementById('signup-form').addEventListener('submit', (e) => {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
replace_text(elem_info)
auth.createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
const user = userCredential.user;
console.log("User created successfully:", user);
print_text('Аккаунт создан успешно. Проверка почты отправлена.', elem_info, delay);
// Send email verification
user.sendEmailVerification()
.then(() => {
console.log("Email verification sent.");
print_text('Пожалуйста, проверьте свою почту для подтверждения.', elem_info, delay);
})
.catch((error) => {
console.error("Error sending email verification:", error);
print_text('Ошибка при отправке подтверждения почты. Попробуйте еще раз.', elem_info, delay);
});
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.error("Error creating user:", errorCode, errorMessage);
if (errorCode === 'auth/email-already-in-use') {
print_text('Аккаунт для данной почты уже создан.', elem_info, delay);
} else {
print_text(`Ошибка: ${errorMessage}`, elem_info, delay);
}
});
});
</script>
</body>
</html>