From b26bd1a228adb9bbc58769f3f87bdc8bc7a3e882 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Mon, 1 Jan 2024 23:13:09 +0000 Subject: [PATCH] Signup page now populates database correctly --- controllers/web/endpoints.py | 13 +++++++++++-- models/users/customer.py | 7 +++++-- models/users/user.py | 25 +++++++++++++------------ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/controllers/web/endpoints.py b/controllers/web/endpoints.py index 03a9448..3661328 100644 --- a/controllers/web/endpoints.py +++ b/controllers/web/endpoints.py @@ -2,6 +2,7 @@ from . import blueprint from flask import render_template, redirect, request from controllers.database.user import UserController from models.users.customer import Customer +from hashlib import sha512 # Function responsible for displaying the main landing page of the site @@ -34,7 +35,15 @@ def display_signup(): @blueprint.post('/signup') def signup(): database = UserController() - database.create(Customer()) + database.create(Customer( + 0, + request.form['username'], + request.form['email'], + request.form['firstname'], + request.form['lastname'], + "123", + sha512(request.form['password'].encode()).hexdigest(), # Hashed as soon as it is recieved on the backend + "Customer" + )) - print("Tryin to signup as " + request.form['username']) return redirect("/") diff --git a/models/users/customer.py b/models/users/customer.py index 2f5448c..b7c874e 100644 --- a/models/users/customer.py +++ b/models/users/customer.py @@ -6,8 +6,11 @@ class Customer(User): No additional properties are assigned to the customer ''' - def __init__(self): - super().__init__() + def __init__(self, id: int, username: str, email: str, firstname: str, + lastname: str, phone: str, password: str, role: str): + super().__init__( + id, username, email, firstname, lastname, phone, password, role + ) def login(self): print("Logging in as Customer") diff --git a/models/users/user.py b/models/users/user.py index 4d5822f..e4d26f4 100644 --- a/models/users/user.py +++ b/models/users/user.py @@ -1,18 +1,19 @@ from abc import ABC, abstractmethod class User(ABC): - ''' - Class constructor to instatiate the base object - ''' - def __init__(self): - self.id = 0 - self.username = "" - self.email = "" - self.firstName = "" - self.lastName = "" - self.phone = "" - self.password = "" - self.role="" + """ Functional Class constructor to initialise all properties in the base object + with a value """ + def __init__(self, id: int, username: str, email: str, firstname: str, + lastname: str, phone: str, password: str, role: str): + self.id = id + self.username = username + self.email = email + self.firstName = firstname + self.lastName = lastname + self.phone = phone + self.password = password + self.role= role + @abstractmethod def login(self):