2023-12-27 21:36:53 +00:00
|
|
|
from . import blueprint
|
2024-01-01 20:19:57 +00:00
|
|
|
from flask import render_template, redirect, request
|
|
|
|
from controllers.database.user import UserController
|
|
|
|
from models.users.customer import Customer
|
2024-01-01 23:13:09 +00:00
|
|
|
from hashlib import sha512
|
2023-12-27 21:36:53 +00:00
|
|
|
|
2023-12-31 19:03:29 +00:00
|
|
|
|
|
|
|
# Function responsible for displaying the main landing page of the site
|
2023-12-27 21:36:53 +00:00
|
|
|
@blueprint.route('/')
|
|
|
|
def welcome_page():
|
2023-12-31 19:03:29 +00:00
|
|
|
return render_template('index.html', content="content.html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### LOGIN FUNCTIONALITY
|
|
|
|
# Function responsible for delivering the Login page for the site
|
|
|
|
@blueprint.route('/login')
|
|
|
|
def display_login():
|
|
|
|
return render_template('index.html', content="login.html")
|
|
|
|
|
|
|
|
# Function responsible for handling logins to the site
|
|
|
|
@blueprint.post('/login')
|
|
|
|
def login():
|
|
|
|
print("Tryin to login as " + request.form['username'])
|
|
|
|
return redirect("/")
|
|
|
|
|
|
|
|
|
|
|
|
### SIGNUP FUNCTIONALITY
|
|
|
|
# Function responsible for delivering the Signup page for the site
|
|
|
|
@blueprint.route('/signup')
|
|
|
|
def display_signup():
|
|
|
|
return render_template('index.html', content="signup.html")
|
|
|
|
|
|
|
|
# Function responsible for handling signups to the site
|
|
|
|
@blueprint.post('/signup')
|
|
|
|
def signup():
|
2024-01-01 20:19:57 +00:00
|
|
|
database = UserController()
|
2024-01-01 23:13:09 +00:00
|
|
|
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"
|
|
|
|
))
|
2024-01-01 20:19:57 +00:00
|
|
|
|
2023-12-31 19:03:29 +00:00
|
|
|
return redirect("/")
|