mirror of
https://github.com/StefBuwalda/WebTech.git
synced 2025-10-29 19:00:00 +00:00
Copied structure and files from Roos
This commit is contained in:
13
app.py
Normal file
13
app.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from application import app
|
||||||
|
from flask import render_template
|
||||||
|
|
||||||
|
|
||||||
|
# home route
|
||||||
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
return render_template("home.html")
|
||||||
|
|
||||||
|
|
||||||
|
# App deployment
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(debug=True, port=5000)
|
||||||
39
application/__init__.py
Normal file
39
application/__init__.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from flask import Flask
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
from flask_migrate import Migrate
|
||||||
|
from flask_login import LoginManager # type: ignore
|
||||||
|
|
||||||
|
# App Config
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///services.sqlite"
|
||||||
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False # Wat is dit?
|
||||||
|
app.config["SECRET_KEY"] = "bvjchsygvduycgsyugc" # Andere secret key
|
||||||
|
|
||||||
|
# Object Relational Management
|
||||||
|
db = SQLAlchemy()
|
||||||
|
db.init_app(app)
|
||||||
|
|
||||||
|
migrate = Migrate(app, db)
|
||||||
|
|
||||||
|
# bp import
|
||||||
|
from application.auth.views import auth_blueprint
|
||||||
|
|
||||||
|
# from application.strike.views import strike_blueprint
|
||||||
|
|
||||||
|
# Login manager
|
||||||
|
from application.auth.models import User
|
||||||
|
|
||||||
|
login_manager = LoginManager()
|
||||||
|
login_manager.init_app(app) # type: ignore
|
||||||
|
login_manager.login_view = "auth.login" # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
@login_manager.user_loader # type: ignore
|
||||||
|
def load_user(user_id): # type: ignore
|
||||||
|
return User.query.get(int(user_id)) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
# Blueprint magic
|
||||||
|
|
||||||
|
# app.register_blueprint(strike_blueprint, url_prefix="/staking")
|
||||||
|
app.register_blueprint(auth_blueprint, url_prefix="/auth")
|
||||||
BIN
application/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
application/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
application/auth/__pycache__/forms.cpython-312.pyc
Normal file
BIN
application/auth/__pycache__/forms.cpython-312.pyc
Normal file
Binary file not shown.
BIN
application/auth/__pycache__/models.cpython-312.pyc
Normal file
BIN
application/auth/__pycache__/models.cpython-312.pyc
Normal file
Binary file not shown.
BIN
application/auth/__pycache__/views.cpython-312.pyc
Normal file
BIN
application/auth/__pycache__/views.cpython-312.pyc
Normal file
Binary file not shown.
8
application/auth/forms.py
Normal file
8
application/auth/forms.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from flask_wtf import FlaskForm # type: ignore
|
||||||
|
from wtforms import StringField, SubmitField, PasswordField, validators
|
||||||
|
|
||||||
|
|
||||||
|
class LoginForm(FlaskForm):
|
||||||
|
username = StringField("Username", validators=[validators.DataRequired()])
|
||||||
|
password = PasswordField("Password")
|
||||||
|
submit = SubmitField("Login")
|
||||||
8
application/auth/models.py
Normal file
8
application/auth/models.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from application import db
|
||||||
|
from flask_login import UserMixin # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
class User(db.Model, UserMixin):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
username = db.Column(db.String(150), unique=True, nullable=False)
|
||||||
|
password = db.Column(db.String(150), nullable=False)
|
||||||
18
application/auth/templates/login.html
Normal file
18
application/auth/templates/login.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Login
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if feedback %}
|
||||||
|
<p>{{feedback}}</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ form.username.label }} {{ form.username() }}<br>
|
||||||
|
{{ form.password.label }} {{ form.password() }}<br>
|
||||||
|
{{ form.submit() }}
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
40
application/auth/views.py
Normal file
40
application/auth/views.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from flask import Blueprint, render_template, redirect, url_for, flash
|
||||||
|
|
||||||
|
# from application import db
|
||||||
|
from application.auth.models import User
|
||||||
|
from application.auth.forms import LoginForm
|
||||||
|
from flask_login import login_required, login_user, logout_user # type: ignore
|
||||||
|
from werkzeug.security import check_password_hash
|
||||||
|
|
||||||
|
auth_blueprint = Blueprint("auth", __name__, template_folder="templates")
|
||||||
|
|
||||||
|
# Routes
|
||||||
|
|
||||||
|
|
||||||
|
@auth_blueprint.route("/login", methods=["GET", "POST"])
|
||||||
|
def login():
|
||||||
|
login_form = LoginForm()
|
||||||
|
feedback = None
|
||||||
|
|
||||||
|
if login_form.validate_on_submit(): # type: ignore
|
||||||
|
username = login_form.username.data
|
||||||
|
password = login_form.password.data
|
||||||
|
user = User.query.filter_by(username=username).first() # type: ignore
|
||||||
|
|
||||||
|
if user and check_password_hash(
|
||||||
|
user.password, password # type: ignore
|
||||||
|
):
|
||||||
|
login_user(user) # type: ignore
|
||||||
|
return redirect(url_for("staking.strikers"))
|
||||||
|
else:
|
||||||
|
feedback = "Foutieve login."
|
||||||
|
|
||||||
|
return render_template("login.html", form=login_form, feedback=feedback)
|
||||||
|
|
||||||
|
|
||||||
|
@auth_blueprint.route("/logout")
|
||||||
|
@login_required
|
||||||
|
def logout():
|
||||||
|
logout_user()
|
||||||
|
flash("Je bent nu uitgelogd.")
|
||||||
|
return redirect(url_for("index"))
|
||||||
41
application/templates/base.html
Normal file
41
application/templates/base.html
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||||
|
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||||
|
<link rel="stylesheet" href="{{url_for('static', filename='my.css')}}">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="#">Staak-app</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup"
|
||||||
|
aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||||
|
<div class="navbar-nav">
|
||||||
|
<a class="nav-link" href="{{url_for('index')}}">Home</a>
|
||||||
|
{% if current_user.is_authenticated %}
|
||||||
|
<a class="nav-link" href="{{url_for('auth.logout')}}">Uitloggen</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
||||||
|
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
9
application/templates/home.html
Normal file
9
application/templates/home.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Staak-app
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Welkom bij de staak-app!</h1>
|
||||||
|
{% endblock %}
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
|
alembic==1.15.2
|
||||||
blinker==1.9.0
|
blinker==1.9.0
|
||||||
click==8.1.8
|
click==8.1.8
|
||||||
colorama==0.4.6
|
colorama==0.4.6
|
||||||
Flask==3.1.0
|
Flask==3.1.0
|
||||||
Flask-Login==0.6.3
|
Flask-Login==0.6.3
|
||||||
|
Flask-Migrate==4.1.0
|
||||||
|
Flask-SQLAlchemy==3.1.1
|
||||||
Flask-WTF==1.2.2
|
Flask-WTF==1.2.2
|
||||||
|
greenlet==3.1.1
|
||||||
itsdangerous==2.2.0
|
itsdangerous==2.2.0
|
||||||
Jinja2==3.1.6
|
Jinja2==3.1.6
|
||||||
|
Mako==1.3.9
|
||||||
MarkupSafe==3.0.2
|
MarkupSafe==3.0.2
|
||||||
pillow==11.1.0
|
pillow==11.1.0
|
||||||
|
SQLAlchemy==2.0.40
|
||||||
|
typing_extensions==4.13.0
|
||||||
Werkzeug==3.1.3
|
Werkzeug==3.1.3
|
||||||
WTForms==3.2.1
|
WTForms==3.2.1
|
||||||
|
|||||||
Reference in New Issue
Block a user