Skip to content

Commit 834b488

Browse files
committed
feat(a2): implement signup frontend request
1 parent 60a4c16 commit 834b488

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

a2/actions.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,24 @@ function signup(userInput, passInput, passInput2, emailInput) {
147147
password2 = passInput2.value,
148148
email = emailInput.value;
149149

150-
// do any preprocessing on the user input here before sending to the server
150+
// checking is done with HTML and functions at the end of the file
151+
// hash password with username
152+
digestMessage(username + password).then(digestValue => {
153+
password = bufferToHexString(digestValue);
151154

152-
// send the signup form to the server
153-
serverRequest("signup", // resource to call
154-
{
155+
// send the signup form to the server
156+
serverRequest("signup", {
155157
"username": username,
156158
"password": password,
157159
"email": email
158-
} // this should be populated with needed parameters
159-
).then(function (result) {
160-
// if everything was good
161-
if (result.response.ok) {
162-
// do any work needed if the signup request succeeded
163-
164-
// go to the login page
165-
showContent("login");
166-
}
167-
// show the status message from the server
168-
serverStatus(result);
160+
}).then(result => {
161+
if (result.response.ok) {
162+
// go to the login page
163+
showContent("login");
164+
}
165+
// show the status message from the server
166+
serverStatus(result);
167+
});
169168
});
170169
}
171170

@@ -328,3 +327,8 @@ function validateSignupInfo() {
328327

329328
return true;
330329
}
330+
331+
function digestMessage(message) {
332+
const data = utf8ToUint8Array(message);
333+
return window.crypto.subtle.digest('SHA-256', data);
334+
}

0 commit comments

Comments
 (0)