Skip to content

Commit

Permalink
Added method to create employee users for managers.
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed May 16, 2022
1 parent b89676d commit 6e1c2c1
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 118 deletions.
14 changes: 12 additions & 2 deletions api/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from tkinter.tix import Tree
from passlib.hash import sha256_crypt
from flask import Blueprint, abort, request, session, redirect
from database import auth, customers, employees
Expand Down Expand Up @@ -65,8 +66,17 @@ def hire():
try:
data = request.json
passwordHash = sha256_crypt.encrypt(data['password']) # hashes password
employee = employees.createEmployee(data['username'], passwordHash, data['employeeType'])
return { 'response': employee }
userList = auth.getAllUsers()
exists = False

for i in userList:
if i['username'] == data['username']: exists = True;

if not exists:
employee = employees.createEmployee(data['username'], passwordHash, data['employeeType'])
return { 'response': employee }
else:
return { 'response' : 'exists'}
except Exception as e:
print('error: ', e, '\n')
abort(500)
Expand Down
20 changes: 1 addition & 19 deletions build/dashboard-chefprogress.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,7 @@ <h2>Active Orders</h2>
</div>

{% if session.get('employeeType') == 'chef' %}
<div class="orderlist" id="orderlist">
<!-- <div class ="progresscontainer">
<div class="progress" id="progress"></div>
<div class="circle active"><i class="fa-solid fa-circle-check"></i></div>
<div class="circle active"><i class="fa-solid fa-circle-check"></i></div>
<div class="circle active"><i class="fa-solid fa-circle-check"></i></div>
<div class="progresstext">
<h2>Incoming order.</h2>
<h2>Preparing order.</h2>
<h2>Order ready for delivery.</h2>
</div>
</div>
<button class="stepbtn" id="prev" disabled>Previous Step</button>
<button class="stepbtn" id="next" disabled>Next Step</button> -->

</div>
<div class="orderlist" id="orderlist"></div>


{% else %}
Expand Down
22 changes: 11 additions & 11 deletions build/dashboard-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ <h3>Personal Info:</h3>

<div class="item">
<h3>Password Change:</h3>
<p>Enter current password:</p>
<label for="current">Enter current password:</label>
<input type="password" id="current">
<p>Enter new password:</p>
<label for="new">Enter new password:</label>
<input type="password" id="new">
<p>Confirm new password:</p>
<label for="confirmnew">Confirm new password:</label>
<input type="password" id="confirmnew">
<button>Confirm new password</button>
</div>
Expand All @@ -35,22 +35,22 @@ <h3>Password Change:</h3>
<h3>Create Employee Account:</h3>
<div class="employeeselect">
<p>Choose Employee Account Type:</p>
<select>
<select onchange="selectHandler()" id="employeeselector">
<option value="0">Manager</option>
<option value="1">Chef</option>
<option value="2">Delivery</option>
</select>
</div>
<p>Enter username:</p>
<label for="username">Enter username:</label>
<input type="text" id="username">
<p>Enter password:</p>
<label for="unew">Enter password:</label>
<input type="password" id="unew">
<button>Create Employee Account</button>
<label for="unewconfirm">Confirm password:</label>
<input type="password" id="unewconfirm">
<p class="donotmatch">Passwords do not match</p>
<button = onclick="createUser()">Create Employee Account</button>
</div>
{% endif %}
</div>




{% if session.get('employeeType') == 'manager' %}<script src="/scripts/dashboard-settings-createAccount.js"></script> {% endif %}
{% endblock %}
62 changes: 62 additions & 0 deletions build/scripts/dashboard-settings-createAccount.js
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'];
}
84 changes: 2 additions & 82 deletions build/styles/chefprogress.css
Original file line number Diff line number Diff line change
@@ -1,92 +1,11 @@
/* .perinfo {
text-align: left;
font-size: 70%;
}
.fa-circle-check {
font-size:40px;
color:rgb(48, 48, 48);
max-width: 100%;
}
.circle {
background-color: white;
color:rgb(48, 48, 48);
border-radius: 50%;
height:50px;
width:50px;
border: 3px solid rgb(48, 48, 48);
display:flex;
align-items: center;
justify-content: center;
transition: .4s ease;
}
.circle.active {
border-color:rgb(255, 117, 193);
}
.progresscontainer {
text-align: center;
display:flex;
justify-content: space-between;
margin-bottom:30px;
margin-top: 30px;
margin-left: 50px;
margin-right: 50px;
max-width: 100%;
}
.progresscontainer::before {
content:"";
margin-left: 20px;
background-color: rgb(48, 48, 48);
position:absolute;
top:44%;
left:0;
transform: translateY(-50%);
height: 4px;
width:97%;
z-index:-1;
transition: 0.4s ease;
}
.progress {
margin-left: 20px;
background-color: rgb(255, 117, 193);
position:absolute;
top:44%;
left:0;
transform: translateY(-50%);
height: 4px;
width:50%;
z-index:-1;
transition: 0.4s ease;
}
.stepbtn {
background-color:rgb(255, 117, 193) ;
color:white;
border-radius: 4px;
border: none;
cursor:pointer;
padding:10px;
}
.stepbtn:hover {
background-color: rgb(179, 88, 138);
}
*/

.orderlist{
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
padding: 20px 80px;

transition: 1s;
}
.orderdiv{
background-color: white;
Expand All @@ -97,6 +16,7 @@
transition: 0.5s;
text-decoration: none;
color: black;
/* transition: 1s; */
}

.orderdiv:hover{
Expand Down
6 changes: 4 additions & 2 deletions build/styles/dashboard-layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,7 @@ input, textarea{
padding: 5px;
}



label{
display: inline-block;
margin: 10px;
}
15 changes: 13 additions & 2 deletions build/styles/dashboard-settings.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
.container {
display:flex;
justify-content: center;
flex-wrap: wrap;
/* margin-left:20%; */
padding: 20px;
padding: 20px;
margin-bottom: 40px;
}

.item {
display: flex;
flex-direction: column;
justify-content: center;
background-color: white;
width:200px;
margin: 10px 25px;
padding: 20px;
padding: 30px;
border-radius:24px;
box-shadow: 1px 1px 2px rgb(219, 179, 179), 0 0 25px rgb(255, 132, 152), 0 0 5px rgb(139, 0, 109);

Expand All @@ -34,3 +39,9 @@ button:hover{
background-color: rgb(255, 101, 181);
color:white
}

.donotmatch{
display : none;
font-size: 12px;
color : red;
}
6 changes: 6 additions & 0 deletions database/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def getUserByUsername(username): # looks for existing users
if users: return users[0] # returns a user's info based on the username
return ''

def getAllUsers():
with DatabaseConnection('./database/database.db') as cursor:
rows = cursor.execute("""SELECT * FROM AuthenticationTable""")
users = [listToDict(row) for row in rows]
if users: return users
return ''

# use createCustomer to register new customers
def addUser(username, password, role): # registers new users
Expand Down
Binary file modified database/database.db
Binary file not shown.

0 comments on commit 6e1c2c1

Please sign in to comment.