From 6e1c2c1ed63414aab66aa6a9e1ba6bacea505a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raynel=20S=C3=A1nchez?= Date: Mon, 16 May 2022 01:31:01 -0400 Subject: [PATCH] Added method to create employee users for managers. --- api/auth.py | 14 ++- build/dashboard-chefprogress.html | 20 +---- build/dashboard-settings.html | 22 ++--- .../dashboard-settings-createAccount.js | 62 +++++++++++++ build/styles/chefprogress.css | 84 +----------------- build/styles/dashboard-layout.css | 6 +- build/styles/dashboard-settings.css | 15 +++- database/auth.py | 6 ++ database/database.db | Bin 69632 -> 69632 bytes 9 files changed, 111 insertions(+), 118 deletions(-) create mode 100644 build/scripts/dashboard-settings-createAccount.js diff --git a/api/auth.py b/api/auth.py index 07a3ea7..4bb91b6 100644 --- a/api/auth.py +++ b/api/auth.py @@ -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 @@ -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) diff --git a/build/dashboard-chefprogress.html b/build/dashboard-chefprogress.html index b8c8e10..34b2fba 100644 --- a/build/dashboard-chefprogress.html +++ b/build/dashboard-chefprogress.html @@ -11,25 +11,7 @@

Active Orders

{% if session.get('employeeType') == 'chef' %} -
- - -
+
{% else %} diff --git a/build/dashboard-settings.html b/build/dashboard-settings.html index 41f0eaa..7459a8f 100644 --- a/build/dashboard-settings.html +++ b/build/dashboard-settings.html @@ -21,11 +21,11 @@

Personal Info:

Password Change:

-

Enter current password:

+ -

Enter new password:

+ -

Confirm new password:

+
@@ -35,22 +35,22 @@

Password Change:

Create Employee Account:

Choose Employee Account Type:

-
-

Enter username:

+ -

Enter password:

+ - + + +

Passwords do not match

+ {% endif %} - - - - + {% if session.get('employeeType') == 'manager' %} {% endif %} {% endblock %} \ No newline at end of file diff --git a/build/scripts/dashboard-settings-createAccount.js b/build/scripts/dashboard-settings-createAccount.js new file mode 100644 index 0000000..e282da0 --- /dev/null +++ b/build/scripts/dashboard-settings-createAccount.js @@ -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']; +} \ No newline at end of file diff --git a/build/styles/chefprogress.css b/build/styles/chefprogress.css index 599384e..45b76c1 100644 --- a/build/styles/chefprogress.css +++ b/build/styles/chefprogress.css @@ -1,84 +1,3 @@ -/* .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; @@ -86,7 +5,7 @@ flex-wrap: wrap; justify-content: center; padding: 20px 80px; - + transition: 1s; } .orderdiv{ background-color: white; @@ -97,6 +16,7 @@ transition: 0.5s; text-decoration: none; color: black; + /* transition: 1s; */ } .orderdiv:hover{ diff --git a/build/styles/dashboard-layout.css b/build/styles/dashboard-layout.css index 1a600ed..749c157 100644 --- a/build/styles/dashboard-layout.css +++ b/build/styles/dashboard-layout.css @@ -248,5 +248,7 @@ input, textarea{ padding: 5px; } - - +label{ + display: inline-block; + margin: 10px; +} \ No newline at end of file diff --git a/build/styles/dashboard-settings.css b/build/styles/dashboard-settings.css index ce4f1e9..2a00ffa 100644 --- a/build/styles/dashboard-settings.css +++ b/build/styles/dashboard-settings.css @@ -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); @@ -34,3 +39,9 @@ button:hover{ background-color: rgb(255, 101, 181); color:white } + +.donotmatch{ + display : none; + font-size: 12px; + color : red; +} \ No newline at end of file diff --git a/database/auth.py b/database/auth.py index 0a03cec..d636702 100644 --- a/database/auth.py +++ b/database/auth.py @@ -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 diff --git a/database/database.db b/database/database.db index 90d81a93317b2e39a5b40e7a2dbbbe14b186031c..90384946b3fcb0829e0ac760ed095e2e19894df6 100644 GIT binary patch delta 293 zcmZozz|ydQWr8$g$V3@u)({50aIcLi0{V^>avMBiFqNZ1^E>!rYc4GrFkjEwx-6W1_lNy5#~9GMdsxe zDJEV%0sgt>D&dwT`mS!J=E1%O`j&dZX--**$v&xGeik|Ysa1Xkj=7GeiJ|V1Nk)z? zsksF?`IV`u>8xxFsz6&(QgbrPQj03R@{3c!7HyWbd(Ozg#=o9{{~7=K&0G$P`T2O6 zcF)uMawP^C$`Q|`n guNe6M@PFg~!2b%U>=ysz59?W&*jP4ySTB$O0BuNGga7~l delta 120 zcmZozz|ydQWr8$g@I)DB)?fxb|Jscy0{V>1lS}mj8CfSE*SFuW|VZA^C04`J}r~m)}