/
index.html
258 lines (203 loc) · 11.5 KB
/
index.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Create the title-->
<title>GlobeTrotter</title>
<!-- Load firebase-->
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.10/firebase-auth.js"></script>
<!-- Load Bootstrap -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"
crossorigin="anonymous"></script>
<!-- Link to CSS -->
<link rel="stylesheet" href="./CSS/intro.css">
</head>
<body onload="init()">
<!-- Create a division for the login page-->
<div class="login-page" id="registerLogin" style="position: absolute; bottom:10vw;left:25%;width:50vw; max-height:70vw">
<div class="carousel slide" id="carouselExampleIndicator" data-ride="carousel" style="position:absolute;top:20vw;width:30vw; height:50vw">
<ol class="carousel-indicators" style="position: absolute; bottom:10vw;left:25%; width: 20vw">
<li data-target="#carouselExampleIndicator" data-slide-to="0" class="active"
style="background-color:#D1E5BE"></li>
<li data-target="#carouselExampleIndicator" data-slide-to="1" style="background-color:#D1E5BE"></li>
<li data-target="#carouselExampleIndicator" data-slide-to="2" style="background-color:#D1E5BE"></li>
<li data-target="#carouselExampleIndicator" data-slide-to="3" style="background-color:#D1E5BE"></li>
</ol>
<div class="carousel-inner" style="position:relative">
<br>
<br>
<br>
<div class="carousel-item active">
<br><img src="./CSS/Media/GTLOGO.png" style='height:5vw; left:2vw'><br>
<br><br>
<h1>GlobeTrotter </h1><br>
<br><br><br><br><br><br><br><br>
</div>
<div class="carousel-item">
<p><br><br><br><br>How it works...<br><br>Build a profile <br><br> Share your favourite travel tips
<br><br> Connect with others nearby</p>
<br><br><br><br><br><br><br><br>
</div>
<div class="carousel-item">
<p>Use the map to find local hotspots and nearby travellers...</p>
<img src="./CSS/Media/GTDEMO.png" style="width:15vw">
<br><br>
</div>
<div class="carousel-item">
<!-- Create a division for both the login and registration form-->
<div class="form" id="form">
<!-- Create a registration form-->
<div class="registerform" id="registerform">
<h1>Register</h1>
<!-- A textbox for the user to input email-->
<input style='height:5vw'type="text" id="email" placeholder="Email:"></input>
<!-- A textbox for the user to input password (hidden) -->
<input style='height:5vw'type="password" id="password" placeholder="Password:"></input>
<!-- A textbox for the user to input a username -->
<!-- <input type="text" id="username" placeholder="Name:"></input> -->
<!-- A button which calls the register function -->
<button id="myBtn" onclick="Register()">Create</button>
<!-- A link to the login form-->
<p class="message">Already Registered? <a href="#" onclick="toggleVisibility();">Login</a>
</p>
</div>
<!-- Create a login form -->
<div class="loginform" id="loginform">
<h1>Login</h1>
<!-- A textbox for the user to login with email -->
<input style='height:5vw'type="text" id="email2" name="email2" placeholder="Email:"></input>
<!-- A textbox fot the user to login with password (hidden) -->
<input style='height:5vw'type="password" id="password2" name="password2" placeholder="Password:"></input>
<!-- A button that calls the login function -->
<button id="myBtn" onclick="Login()">Login</button>
<!-- A link to the registration form -->
<p class="message"> Not Registered? <a href="#" onclick="toggleVisibility();">Register</a>
</p>
</div>
</div>
</div>
</div>
<div style=" position: absolute;max-height:30vw">
<a id="arrow" class="carousel-control-prev" href="#carouselExampleIndicator" role="button"
data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden=true style="color:#D1E5BE;"></span>
<span class="sr-only">Previous</span>
</a>
<a id="arrow" class="carousel-control-next" href="#carouselExampleIndicator" role="button"
data-slide="next">
<span class="carousel-control-next-icon" class="responsive" aria-hidden=true
style="color:#D1E5BE;"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<script>
/**
* Initialise the databse and set the login and register visibility
*/
function init() {
// initialise the display settings
document.getElementById('loginform').style.display = 'block'; //login
document.getElementById('registerform').style.display = 'none'; // register
// Load Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBuduFOLQ40g1UNdo_1JHPnrT36pN8q6zc",
authDomain: "project-name-4a9df.firebaseapp.com",
databaseURL: "https://project-name-4a9df-default-rtdb.firebaseio.com",
projectId: "project-name-4a9df",
storageBucket: "project-name-4a9df.appspot.com",
messagingSenderId: "389888460979",
appId: "1:389888460979:web:c4df9d8b2685a2264c48c6",
measurementId: "G-LVVKK9S300"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
}
/**
* Toggle login and register forms
*/
function toggleVisibility() {
// is visible, red invisible
if (loginform.style.display === 'block') { //login
document.getElementById('registerform').style.display = 'block'; //register
document.getElementById('loginform').style.display = 'none'; //login
}
// red is visible, blue invisible
else {
document.getElementById('registerform').style.display = 'none';//register
document.getElementById('loginform').style.display = 'block';//login
}
};
/**
* Create a new user with email and password and sign them into the application
*/
function Register() {
// Create a variable to hold all the data that the user inputs during registering
let data = {
email: document.getElementById('email').value,
password: document.getElementById('password').value,
};
// Use firebase createUser function using email and password
firebase.auth().createUserWithEmailAndPassword(data.email, data.password)
.then(function () {
//set the current auth to null
let auth = null;
// Once successfully registered, sign the new user in to firebase
firebase.auth().signInWithEmailAndPassword(data.email, data.password)
.then(function (user) {
sessionStorage.setItem("uid", user.user.uid);
// Print this in the console if successful
console.log("Successfully logged in", user);
// auth has changed from null to user, after sign in
auth = user;
// After successful registration and login, redirect to the main page
window.location.href = "./profile.html";
// If it did not work, catch the error
}).catch(function (error) {
console.log("registration failed!", error);
});
})
// If registration did not work, catch these errors
.catch(function (error) {
console.log("Failed to register ", error);
});
}
/**
* Create a function for logging in and after successful login, change to main page.
*/
function Login() {
// Create a variable for the email and password inputs called data
let data = {
email: document.getElementById('email2').value,
password: document.getElementById('password2').value,
};
//set the current auth to null
let auth = null;
// Use firebase sign in function with email and password
firebase.auth().signInWithEmailAndPassword(data.email, data.password)
.then(function (user) {
// If successful, print this in the console log
console.log("Successfully logged in", user);
// state change- auth from null to user
auth = user;
// If successful, redirect to the next page
window.location.href = "./profile.html";
}).catch(function (error) {
console.log("Login Failed!", error);
window.alert('Login Failed!');
});
};
</script>
</body>
</html>