-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.html
244 lines (202 loc) · 10.1 KB
/
home.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyPass</title>
<link rel="stylesheet" type="text/css" href="css/home_style.css" />
</head>
<body>
<div class="container-app">
<aside class="sideNav">
<h3>MyPass</h3>
<nav class="menuBar">
<a href="home.html" class="menu is-active">Edit Profile</a>
<a href="account.html" class="menu ">Accounts</a>
<a href="payment.html" class="menu">Payment Information</a>
<a href="identity.html" class="menu">Identity</a>
<a href="secure.html" class="menu">Secure Notes</a>
<a href="login.html" class="menu">Sign Out</a>
</nav>
</aside>
<main class="content">
<h1>Edit Profile</h1>
<!--username, password, account info edit - center-->
<form class="edit-profile-form">
<div class="form-group">
<label for="username">Username:</label>
<input type="password" id="username" name="username" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="security-question1">Security Question 1:</label>
<input type="text" id="security-question1" name="security-question1" required>
</div>
<div class="form-group">
<label for="security-question2">Security Question 2:</label>
<input type="text" id="security-question2" name="security-question2" required>
</div>
<div class="form-group">
<label for="security-question3">Security Question 3:</label>
<input type="text" id="security-question3" name="security-question3" required>
</div>
<div>
<button id="toggleSensitiveInfo" type="button">Unmask Sensitive Information</button>
</div>
<br>
<div>
<button type="submit">Save Information</button>
</div>
<script>
</script>
</form>
</main>
</div>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.6.0/firebase-app.js";
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/10.6.0/firebase-auth.js";
import { getDatabase, set, ref, update, onValue } from "https://www.gstatic.com/firebasejs/10.6.0/firebase-database.js";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAaJ0fhXXd_WEuTwUTQJpa211weqA7ZQ6w",
authDomain: "term-project-476.firebaseapp.com",
projectId: "term-project-476",
storageBucket: "term-project-476.appspot.com",
messagingSenderId: "276408407460",
appId: "1:276408407460:web:b05ec30e174fb0c3441d31"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize user authentication
const auth = getAuth(app);
// Initialize database
const database = getDatabase(app);
//code author: Zeinab Alrubaiee
onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in.
const user = auth.currentUser;
if (user) {
// The user object has basic properties such as display name, email, etc.
// Inside onAuthStateChanged function
const userRef = ref(database, 'Users/' + user.uid);
onValue(userRef, (snapshot) => {
const userData = snapshot.val();
if (userData) {
document.getElementById('username').value = userData.username || ''; // Set username
document.getElementById('password').value = userData.master_password || ''; // Set password
document.getElementById('security-question1').value = userData.question_one || ''; // Set security question 1
document.getElementById('security-question2').value = userData.question_two || ''; // Set security question 2
document.getElementById('security-question3').value = userData.question_three || ''; // Set security question 3
}
});
// Select the form element
const editProfileForm = document.querySelector('.edit-profile-form');
// Add event listener for form submission
editProfileForm.addEventListener('submit', (e) => {
e.preventDefault(); // Prevent the default form submission behavior
const updatedUsername = document.getElementById('username').value;
const updatedPassword = document.getElementById('password').value;
const updatedQuestion1 = document.getElementById('security-question1').value;
const updatedQuestion2 = document.getElementById('security-question2').value;
const updatedQuestion3 = document.getElementById('security-question3').value;
// Update user data in the database
update(userRef, {
username: updatedUsername,
master_password: updatedPassword,
question_one: updatedQuestion1,
question_two: updatedQuestion2,
question_three: updatedQuestion3,
// ... update other user properties in the database
}).then(() => {
alert('User information updated successfully.');
// Optionally, you can display a success message or perform other actions upon successful update
}).catch((error) => {
console.error('Error updating user information:', error);
// Handle errors or display an error message to the user
});
});
}
} else {
// No user is signed in.
console.error("User log in error.")
}
});
////-------------Data Mask and Unmask Segment-------------
//Subject
class Mask {
constructor() {
}
revealInformation() {
}
}
//Real Subject
class RealMask extends Mask {
constructor () {
super(); // Invoke the superclass constructor
console.log("RealMask Initialized")
}
revealInformation () {
const usernameField = document.getElementById('username');
const passwordField = document.getElementById('password');
const toggleSensitiveInfoButton = document.getElementById('toggleSensitiveInfo');
usernameField.setAttribute('type', 'text');
passwordField.setAttribute('type', 'text');
toggleSensitiveInfoButton.textContent = 'Mask Sensitive Information';
}
}
//Proxy
class ProtectionProxy extends Mask {
static sensitiveInfo;
static realMask;
constructor (isSensitiveInfoVisible) {
super(); // Invoke the superclass constructor
console.log("ProtectionProxy Initialized")
this.sensitiveInfo = isSensitiveInfoVisible;
this.realMask = new RealMask();
}
revealInformation () {
const usernameField = document.getElementById('username');
const passwordField = document.getElementById('password');
const toggleSensitiveInfoButton = document.getElementById('toggleSensitiveInfo');
if (this.sensitiveInfo) {
this.realMask.revealInformation();
}
else {
usernameField.setAttribute('type', 'password');
passwordField.setAttribute('type', 'password');
toggleSensitiveInfoButton.textContent = 'Unmask Sensitive Information';
}
}
}
const toggleButton = document.getElementById('toggleSensitiveInfo');
let isSensitiveInfoVisible = false;
toggleButton.addEventListener('click', function() {
isSensitiveInfoVisible = !isSensitiveInfoVisible;
console.log(isSensitiveInfoVisible.toString());
let informationProtector = new ProtectionProxy(isSensitiveInfoVisible);
informationProtector.revealInformation();
});
/*
const usernameField = document.getElementById('username');
const passwordField = document.getElementById('password');
const toggleSensitiveInfoButton = document.getElementById('toggleSensitiveInfo');
let isSensitiveInfoVisible = false;
toggleSensitiveInfoButton.addEventListener('click', function() {
isSensitiveInfoVisible = !isSensitiveInfoVisible;
if (isSensitiveInfoVisible) {
usernameField.setAttribute('type', 'text');
passwordField.setAttribute('type', 'text');
toggleSensitiveInfoButton.textContent = 'Mask Sensitive Information';
} else {
usernameField.setAttribute('type', 'password');
passwordField.setAttribute('type', 'password');
toggleSensitiveInfoButton.textContent = 'Unmask Sensitive Information';
}
});*/
</script>
</body>
</html>