-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.html
329 lines (248 loc) · 13 KB
/
profile.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/stylenew.css" type="text/css" media="all">
<link rel="stylesheet" href="css/profile.css" type="text/css" media="all">
<!-- //Custom-Stylesheet-Links -->
<!--fonts -->
<!-- //fonts -->
<!--<link rel="stylesheet" href="css/font-awesome.min.css" type="text/css" media="all">-->
<!-- //Font-Awesome-File-Links -->
<!-- Google fonts -->
<link href="//fonts.googleapis.com/css?family=Quattrocento+Sans:400,400i,700,700i" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Mukta:200,300,400,500,600,700,800" rel="stylesheet">
<meta charset="UTF-8">
<link rel="apple-touch-icon" type="image/png" href="https://static.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png">
<meta name="apple-mobile-web-app-title" content="CodePen">
<link rel="shortcut icon" type="image/x-icon" href="https://static.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico">
<link rel="mask-icon" type="" href="https://static.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg" color="#111">
<title>CodePen - Sample User Settings Form</title>
<script src="https://www.gstatic.com/firebasejs/7.21.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.21.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.21.0/firebase-storage.js"></script>
<script>
window.console = window.console || function(t) {};
</script>
<script>
if (document.location.search.match(/type=embed/gi)) {
window.parent.postMessage("resize", "*");
}
</script>
<script>
firebase.initializeApp({
apiKey: "AIzaSyDwbvS5gMt-dAGIJJs_iuvxjfgSIsWsZW0",
authDomain: "mvf2-e0e2e.firebaseapp.com",
databaseURL: "https://mvf2-e0e2e.firebaseio.com",
projectId: "mvf2-e0e2e",
storageBucket: "mvf2-e0e2e.appspot.com",
messagingSenderId: "845407842102",
appId: "1:845407842102:web:c55bfab8f766b90c69cd97"
});
var db = firebase.firestore();
var cid ;
</script>
<script>
function insertProf() {
var serviceNo = document.forms["editProf"]["serviceNo"].value;
var name = document.forms["editProf"]["name"].value;
var troop = document.forms["editProf"]["troop"].value;
var pass = document.forms["editProf"]["conpass"].value;
var cpass = document.forms["editProf"]["Cpw"].value;
var cImg = "";
var nImg = "";
var files = [];
var docRef = db.collection("cadet").where("serviceNum", "==", serviceNo.toString());
docRef.get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
var realPass = doc.data().password;
console.log(realPass);
if (realPass == cpass) {
cid = serviceNo;
db.collection('cadet').doc(serviceNo.toString()).update({
name: name.toString(),
troop: troop.toString(),
password: pass.toString()
});
uploadImage();
} else {
console.log("pass word match wenne na");
}
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
}
</script>
</head>
<body>
<section class="main">
<div class="layer">
<div class="bottom-grid">
<div class="logo">
<h1> <a href="index.html"><span class=""><img src="images/logo.png" style="width: 200px ;height: auto" class="logo"></span></a></h1>
</div>
<div class="links">
<ul class="links-unordered-list">
<li class="">
<a href="homenew.html" class="active">Home</a>
</li>
<li class="">
<a href="testresults.html" class="">Test Results</a>
</li>
<li class="">
<a href="yourweak.html" class="">Your Weakness</a>
</li>
<li class="active">
<a href="profile.html" class="">Profile</a>
</li>
<li class="">
<a href="index.html" class="">Logout</a>
</li>
</ul>
</div>
</div>
</div>
<div class="in_form">
<h1>Cadet Profile</h1>
<div class="settings-message" id="js-message"></div>
<form name="editProf" onsubmit="insertProf()" method="post">
<input id="js-file-uploader" class="hidden" name="profile-picture" type="file" accept="image/png, image/jpeg">
<div id="js-profile-pic" class="profile-pic__container">Upload Profile Pic
<div id="js-profile-trigger" class="profile-pic__foreground">Upload Profile Pic</div>
</div>
<div class="input__container">
<div class="input-container__single">
<label for="name">Service Number:</label>
<input type="text" required="" name="serviceNo" id="serviceNo" value="" readonly>
</div>
<div class="input-container__single">
<label for="name">Name:</label>
<input type="text" required="" name="name" id="name">
</div>
<div class="input-container__single">
<label for="name">Troop:</label>
<div class="custom-select">
<select name="troop" class="selec">
<option value="alpha">Alpha</option>
<option value="bravo">Bravo</option>
<option value="charlie">Charlie</option>
<option value="delta">Delta</option>
<option value="echo">Echo</option>
</select>
</div>
</div>
<div class="input-container__single">
<label for="name">Current Password:</label>
<input type="text" required="" name="Cpw" id="Cpw">
</div>
<div class="input-container__single">
<label for="js-password">Password:</label>
<input type="password" required="" id="js-password" name="pass">
<span id="js-toggle-password" class="input-action">Display Password</span>
</div>
<div class="input-container__single">
<label for="js-password-confirm">Confirm Password:</label>
<input type="password" required="" id="js-password-confirm" name="conpass">
<span class="input-action" id="js-suggest-password">Suggest Password</span>
</div>
</div>
<input type="submit" value="Save Profile">
</form>
</div>
<script>
var x = sessionStorage.getItem("x");
var y = sessionStorage.getItem("y");
if (x == 0) {
window.location.href = "index.html";
}
document.getElementById("serviceNo").value = x.toString();
console.log(x);
</script>
<script src="https://static.codepen.io/assets/common/stopExecutionOnTimeout-157cd5b220a5c80d4ff8e0e70ac069bffd87a61252088146915e8726e5d9f147.js"></script>
<script id="rendered-js">
const messageElement = document.querySelector('#js-message');
// Image elements
const fileUpload = document.querySelector('#js-file-uploader');
const profileTrigger = document.querySelector('#js-profile-trigger');
const profileBackground = document.querySelector('#js-profile-pic');
// Password objects
const password = document.querySelector('#js-password');
const passwordConfirm = document.querySelector('#js-password-confirm');
const passwordToggle = document.querySelector('#js-toggle-password');
const passwordSuggest = document.querySelector('#js-suggest-password');
let passwordDisplayed = false;
// On form submission, check the passwords match and display a message if the password (would have) been saved.
document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault();
if (password.value != passwordConfirm.value) {
messageElement.innerText = 'The passwords don\'t match!';
messageElement.classList.add('settings-message--error');
messageElement.classList.remove('settings-message--success');
} else {
messageElement.innerText = 'Settings successfully saved!';
messageElement.classList.add('settings-message--success');
messageElement.classList.remove('settings-message--error');
}
});
// Trigger the file upload to set the profile picture
profileTrigger.addEventListener('click', function(event) {
event.preventDefault();
fileUpload.click();
});
// new profile pic added, display it
fileUpload.addEventListener("change", function(event) {
if (fileUpload.files && fileUpload.files[0]) {
let reader = new FileReader();
reader.onload = function(event) {
// Remove the initial 'set picture image' text
profileBackground.childNodes[0].nodeValue = "";
// Set the new image src as the background
profileBackground.style.backgroundImage = "url('" + event.target.result + "')";
};
reader.readAsDataURL(fileUpload.files[0]);
}
});
// Add a suggested password for the user (to both password & confirm password inputs)
passwordSuggest.addEventListener('click', function(event) {
let newPassword = btoa(Math.random().toString(36).substring(2));
password.value = newPassword;
passwordConfirm.value = newPassword;
});
// Toggle the type of input the password field is (for user visibility)
passwordToggle.addEventListener('click', function(event) {
passwordDisplayed = !passwordDisplayed;
if (passwordDisplayed) {
passwordToggle.innerText = "Hide Password";
passwordConfirm.type = 'text';
password.type = 'text';
} else {
passwordToggle.innerText = "Display Password";
passwordConfirm.type = 'password';
password.type = 'password';
}
});
</script>
<script>
function uploadImage() {
var ref = firebase.storage().ref();
var file = document.querySelector("#js-file-uploader").files[0];
var name = file.name;
var metadata = {
contentType: file.type
};
var task = ref.child(name).put(file, metadata);
task
.then(snapshot => snapshot.ref.getDownloadURL())
.then(url => {
console.log(url);
db.collection('cadet').doc(cid.toString()).update({
image: url.toString()
});
})
.catch(console.error);
}
</script>
</body>
</html>