-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added method to create employee users for managers.
- Loading branch information
Showing
9 changed files
with
111 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
async function createUser() { | ||
let data = parseData(); | ||
//console.log(data); | ||
if (data != false) { | ||
if (confirm(`Are you sure you want to create the following employee user?\nUsername: ${data['username']}\nEmployee type: ${data['employeeType']}`)) { | ||
response = await postUser(data); | ||
if (response == 'exists') { | ||
alert("User was not created due to existing username."); | ||
} | ||
else { | ||
alert("User was created successfully!"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function parseData() { // Returns dict with user data | ||
let username = document.getElementById("username").value; | ||
let password = getPassword(); | ||
let employeeType = getEmployeeType(); | ||
if (password == false) { | ||
return false; | ||
} | ||
|
||
return {username, password, employeeType} | ||
} | ||
|
||
function getPassword() { // gets the password from document | ||
let pass = document.getElementById("unew").value; | ||
let conf = document.getElementById("unewconfirm").value; | ||
let donotmatch = document.getElementsByClassName("donotmatch")[0]; | ||
|
||
if (pass == conf) { | ||
donotmatch.style.display = "none"; | ||
return pass; | ||
} | ||
else { | ||
donotmatch.style.display = "block"; | ||
return false; | ||
} | ||
} | ||
|
||
function getEmployeeType() { // gets employeetype from options. | ||
let number = document.getElementById("employeeselector").value; | ||
let employeeTypes = ["manager", "chef", "deliveryPerson"]; | ||
return employeeTypes[number]; | ||
} | ||
|
||
async function postUser(user){ | ||
const response = await fetch("/api/auth/hire", { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(user), | ||
}); | ||
const data = await response.json(); | ||
console.log(data['response']); | ||
return data['response']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,5 +248,7 @@ input, textarea{ | |
padding: 5px; | ||
} | ||
|
||
|
||
|
||
label{ | ||
display: inline-block; | ||
margin: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.