mirror of
https://github.com/StefBuwalda/WebTech.git
synced 2025-10-30 11:19:58 +00:00
Copied structure and files from Roos
This commit is contained in:
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"))
|
||||
Reference in New Issue
Block a user