initial commit

This commit is contained in:
SowinskiBraeden committed 2023-09-28 21:46:42 -07:00
commit 9b29ac47c1
17 files changed
+216

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# Environment / Virtual Environment files
.env
.venv
bin
include/
lib/
lib64
lib64/
# Pycache
__pycache__
__pycache__/
*/__pycache__/
+9
View File
@@ -0,0 +1,9 @@
import os
from dotenv import load_dotenv
basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv()
class Config:
SECRET: str = os.environ.get("SECRET")
API_URL: str = os.environ.get("API_URL")
+5
View File
@@ -0,0 +1,5 @@
home = /usr/bin
include-system-site-packages = false
version = 3.11.4
executable = /usr/bin/python3.11
command = /usr/bin/python3.11 -m venv /home/flami/Desktop/Projects/DeviceBooking
+19
View File
@@ -0,0 +1,19 @@
from flask import Flask
from config import Config
def create_app(config_class=Config):
app: Flask = Flask(__name__)
app.config.from_object(config_class)
# Initialize flask extensions here
# Register blueprints here
from src.main import main_blueprint as main_bp
from src.errors import errors_blueprint as errors_bp
from src.auth import authentication_blueprint as auth_bp
app.register_blueprint(main_bp)
app.register_blueprint(errors_bp)
app.register_blueprint(auth_bp)
return app
+5
View File
@@ -0,0 +1,5 @@
from flask import Blueprint
authentication_blueprint: Blueprint = Blueprint('auth', __name__)
from src.auth import handlers
+27
View File
@@ -0,0 +1,27 @@
from src.auth import authentication_blueprint
from flask import render_template
@authentication_blueprint.post("/logout")
def logout():
session.pop('user_id', None)
return redirect(url_for('login'), code=200)
@authentication_blueprint.get('/dashboard')
def dashboard():
if 'user_id' not in session: return redirect(url_for("login"), code=401)
return render_template('dashboard.html', user_id=session['user_id'])
@authentication_blueprint.get('/login')
def login_get():
token = request.cookies.get('token')
if token == '123456': return redirect(url_for("dashboard"), code=200)
return render_template('login.html', error=None)
@authentication_blueprint.post('/login')
def login_post():
if valid_login(request.form['user_id'],
request.form['password']):
session['user_id'] = request.form['user_id']
return redirect(url_for("dashboard"), code=200)
return render_template('login.html', error='Invalid User ID or Password')
+5
View File
@@ -0,0 +1,5 @@
from flask import Blueprint
errors_blueprint = Blueprint('errors', __name__)
from src.errors import handlers
+14
View File
@@ -0,0 +1,14 @@
from flask import render_template
from src.errors import errors_blueprint
@errors_blueprint.app_errorhandler(404)
def error_404(error):
return render_template('errors/404.html'), 404
@errors_blueprint.app_errorhandler(403)
def error_403(error):
return render_template('errors/403.html'), 403
@errors_blueprint.app_errorhandler(500)
def error_500(error):
return render_template('errors/500.html'), 500
+5
View File
@@ -0,0 +1,5 @@
from flask import Blueprint
main_blueprint: Blueprint = Blueprint('main', __name__)
from src.main import routes
+6
View File
@@ -0,0 +1,6 @@
from src.main import main_blueprint
from flask import render_template
@main_blueprint.get("/")
def index():
return render_template('index.html')
+12
View File
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>DeviceBooking Dashboard</title>
</head>
<body>
<h3>Logged in as user {{ user_id }}</h3>
<form action="/logout" method="POST">
<button type="submit">Logout</button>
</form>
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
{% extends 'layout.html' %}
{% block content %}
<div class="content-section">
<h1>You don't have permission to do that(403)</h1>
<p>Please check your account and try again</p>
</div>
{% endblock %}
+7
View File
@@ -0,0 +1,7 @@
{% extends 'layout.html' %}
{% block content %}
<div class="content-section">
<h1>Oops. Page Not Found (404)</h1>
<p>That page does not exist. Please try a different location</p>
</div>
{% endblock %}
+7
View File
@@ -0,0 +1,7 @@
{% extends 'layout.html' %}
{% block content %}
<div class="content-section">
<h1>Oops. Something went wrong (500)</h1>
<p>We're experienceing some trouble on our end. Please try again in the near future</p>
</div>
{% endblock %}
+8
View File
@@ -0,0 +1,8 @@
{% extends 'layout.html' %}
{% block content %}
<span class="title"><h1>{% block title %} The Home Page of the Device Reservation System {% endblock %}</h1></span>
<div class="content">
<h2>Welcome to the Device Reservation System</h2>
</div>
{% endblock %}
+50
View File
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %} {% endblock %} - DRS</title>
<style>
h2 {
width: 100%;
}
.title {
margin: 5px;
width: 100%;
}
.content {
margin: 5px;
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.post {
flex: 20%;
padding: 10px;
margin: 5px;
background-color: #f3f3f3;
inline-size: 100%;
}
.title a {
color: #00a36f;
text-decoration: none;
}
nav a {
color: #d64161;
font-size: 3em;
margin-left: 50px;
text-decoration: none;
}
</style>
</head>
<body>
<nav>
<a href="{{ url_for('main.index') }}">DRS</a>
<a href="#">Login</a>
</nav>
<hr>
<div class="content">
{% block content %} {% endblock %}
</div>
</body>
</html>
+17
View File
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>DeviceBooking Login</title>
</head>
<body>
<h1>Login</h1>
{% if error %}
<h3>{{ error }}</h3>
{% endif %}
<form action="/login" method="POST">
<input type="text" name="user_id" id="user_id" placeholder="User ID">
<input type="text" name="password" id="password" placeholder="Password">
<button type="submit">Login</button>
</form>
</body>
</html>