Skip to content

Commit 354100d

Browse files
committed
chore(a2): use single quotes
1 parent 2e2713f commit 354100d

File tree

4 files changed

+254
-254
lines changed

4 files changed

+254
-254
lines changed

a2/actions.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use strict";
1+
'use strict';
22

33
/*****************************************************************************
44
* This is the JavaScript file that students need to modify to implement the
@@ -14,7 +14,7 @@
1414
*
1515
* Most of the functions in this file handle a form submission. These
1616
* are passed as arguments the input/output DOM elements of the form that was
17-
* submitted. The "this" keyword for these functions is the form element
17+
* submitted. The 'this' keyword for these functions is the form element
1818
* itself. The functions that handle form submissions are:
1919
* - login
2020
* - signup
@@ -92,8 +92,8 @@ async function credentials(username) {
9292
var idResult;
9393

9494
// get any information needed to log in
95-
idResult = await serverRequest("identify", {
96-
"username": username
95+
idResult = await serverRequest('identify', {
96+
'username': username
9797
});
9898
// bail if something went wrong
9999
if (!idResult.response.ok) {
@@ -124,9 +124,9 @@ async function login(userInput, passInput) {
124124
hashedPassword = await hashMessage(hashedPassword + idJson['challenge']);
125125

126126
// Send a login request to the server.
127-
const result = await serverRequest("login", {
128-
"username": username,
129-
"password": hashedPassword
127+
const result = await serverRequest('login', {
128+
'username': username,
129+
'password': hashedPassword
130130
});
131131

132132
// If the login was successful, show the dashboard.
@@ -136,7 +136,7 @@ async function login(userInput, passInput) {
136136
sessionStorage.setItem('encryption_key', encryptionKey);
137137
clearInputs();
138138

139-
showContent("dashboard");
139+
showContent('dashboard');
140140
} else {
141141
// If the login failed, show the login page with an error message.
142142
serverStatus(result);
@@ -158,16 +158,16 @@ async function signup(userInput, passInput, passInput2, emailInput) {
158158
password = await hashMessage(username + password);
159159

160160
// send the signup form to the server
161-
const result = await serverRequest("signup", {
162-
"username": username,
163-
"password": password,
164-
"email": email
161+
const result = await serverRequest('signup', {
162+
'username': username,
163+
'password': password,
164+
'email': email
165165
});
166166

167167
if (result.response.ok) {
168168
clearInputs();
169169
// go to the login page
170-
showContent("login");
170+
showContent('login');
171171
}
172172
// show the status message from the server
173173
serverStatus(result);
@@ -190,19 +190,19 @@ async function save(siteInput, userInput, passInput) {
190190
} = await encryptMessage(sitepasswd, key);
191191

192192
// send the data, along with the encrypted password, to the server
193-
const result = await serverRequest("save", {
194-
"site": site,
195-
"siteuser": siteuser,
196-
"sitepasswd": encryptedMessage,
197-
"siteiv": iv
193+
const result = await serverRequest('save', {
194+
'site': site,
195+
'siteuser': siteuser,
196+
'sitepasswd': encryptedMessage,
197+
'siteiv': iv
198198
});
199199

200200
if (result.response.ok) {
201201
// any work after a successful save should be done here
202202
clearInputs();
203203

204204
// update the sites list
205-
sites("save");
205+
sites('save');
206206
}
207207
// show any server status messages
208208
serverStatus(result);
@@ -217,8 +217,8 @@ async function save(siteInput, userInput, passInput) {
217217
*/
218218
async function loadSite(siteName, siteElement, userElement, passElement) {
219219
const isDecryptionRequired = passElement.tagName === 'INPUT';
220-
const result = await serverRequest("load", {
221-
"site": siteName
220+
const result = await serverRequest('load', {
221+
'site': siteName
222222
});
223223

224224
if (result.response.ok) {
@@ -238,7 +238,7 @@ async function loadSite(siteName, siteElement, userElement, passElement) {
238238
}
239239
} else {
240240
// on failure, show the login page and display any server status
241-
showContent("login");
241+
showContent('login');
242242
serverStatus(result);
243243
}
244244
}
@@ -264,15 +264,15 @@ async function load(siteInput, userInput, passInput) {
264264
* Called when the logout link is clicked.
265265
*/
266266
async function logout() {
267-
const result = await serverRequest("logout", {});
267+
const result = await serverRequest('logout', {});
268268

269269
if (result.response.ok) {
270270
sessionStorage.removeItem('encryption_key');
271271
sessionStorage.removeItem('hexiv');
272272

273273
clearInputs();
274274

275-
showContent("login");
275+
showContent('login');
276276
}
277277

278278
serverStatus(result);
@@ -282,78 +282,78 @@ async function logout() {
282282
* Called when the value in password2 is changed.
283283
*/
284284
function validatePasswordsMatching() {
285-
const password = document.querySelector("#signup form .field input[name=password]");
286-
const password2 = document.querySelector("#signup form .field input[name=password2]");
285+
const password = document.querySelector('#signup form .field input[name=password]');
286+
const password2 = document.querySelector('#signup form .field input[name=password2]');
287287

288-
if (password2.value === "") {
289-
password2.setCustomValidity("Please confirm password!");
288+
if (password2.value === '') {
289+
password2.setCustomValidity('Please confirm password!');
290290
} else if (password.value !== password2.value) {
291-
password2.setCustomValidity("Passwords do not match!");
291+
password2.setCustomValidity('Passwords do not match!');
292292
} else {
293-
password2.setCustomValidity("");
293+
password2.setCustomValidity('');
294294
}
295295
}
296296

297297
/**
298298
* Called when the value in email is changed.
299299
*/
300300
function validateEmail() {
301-
const email = document.querySelector("#signup form .field input[name=email]");
302-
const emailRegex = new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
301+
const email = document.querySelector('#signup form .field input[name=email]');
302+
const emailRegex = new RegExp(/^(([^<>()\[\]\\.,;:\s@']+(\.[^<>()\[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
303303

304-
if (email.value === "") {
305-
email.setCustomValidity("Please enter email!");
304+
if (email.value === '') {
305+
email.setCustomValidity('Please enter email!');
306306
} else if (!emailRegex.test(email.value)) {
307-
email.setCustomValidity("Must be a valid email address!");
307+
email.setCustomValidity('Must be a valid email address!');
308308
} else {
309-
email.setCustomValidity("");
309+
email.setCustomValidity('');
310310
}
311311
}
312312

313313
/**
314314
* Called when the sign up submit button is clicked.
315315
*/
316316
function validateSignupInfo() {
317-
const username = document.querySelector("#signup form .field input[name=username]");
318-
const password = document.querySelector("#signup form .field input[name=password]");
319-
const password2 = document.querySelector("#signup form .field input[name=password2]");
320-
const email = document.querySelector("#signup form .field input[name=email]");
317+
const username = document.querySelector('#signup form .field input[name=username]');
318+
const password = document.querySelector('#signup form .field input[name=password]');
319+
const password2 = document.querySelector('#signup form .field input[name=password2]');
320+
const email = document.querySelector('#signup form .field input[name=email]');
321321
const usernameRegex = new RegExp(/^[a-zA-Z0-9][a-zA-Z0-9-_]{2,20}$/);
322322
const passwordRegex = new RegExp(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,16}/);
323-
const emailRegex = new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
323+
const emailRegex = new RegExp(/^(([^<>()\[\]\\.,;:\s@']+(\.[^<>()\[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
324324

325325
if (!usernameRegex.test(username.value)) {
326-
console.log("Username is invalid! You can use letters, numbers, - and _. Must start with a letter or a number, and at least 3 and at most 20 characters.");
326+
console.log('Username is invalid! You can use letters, numbers, - and _. Must start with a letter or a number, and at least 3 and at most 20 characters.');
327327

328328
return false;
329329
}
330330

331331
if (!passwordRegex.test(password.value)) {
332-
console.log("Password is invalid! Must contain at least one number, one uppercase and one lowercase letter, and at least 6 and at most 16 characters.");
332+
console.log('Password is invalid! Must contain at least one number, one uppercase and one lowercase letter, and at least 6 and at most 16 characters.');
333333

334334
return false;
335335
}
336336

337-
if (password2.value === "") {
338-
console.log("Please confirm password!");
337+
if (password2.value === '') {
338+
console.log('Please confirm password!');
339339

340340
return false;
341341
}
342342

343343
if (password.value !== password2.value) {
344-
console.log("Passwords do not match!");
344+
console.log('Passwords do not match!');
345345

346346
return false;
347347
}
348348

349-
if (email.value === "") {
350-
console.log("Please enter email!");
349+
if (email.value === '') {
350+
console.log('Please enter email!');
351351

352352
return false;
353353
}
354354

355355
if (!emailRegex.test(email.value)) {
356-
console.log("Must be a valid email address!");
356+
console.log('Must be a valid email address!');
357357

358358
return false;
359359
}

0 commit comments

Comments
 (0)