diff --git a/.gitignore b/.gitignore index f7275bb..691eef1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ +# venv's venv/ + +# DB stuff +migrations/ +instance/ + +# Byte-compiled / optimized / DLL files +__pycache__/ \ No newline at end of file diff --git a/app.py b/app.py index d5f03e8..06cdc0e 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,16 @@ from application import app -from flask import render_template +from flask import redirect, url_for +from flask_login import current_user, login_required # home route @app.route("/") +@login_required def index(): - return render_template("home.html") + if current_user.is_authenticated: + return redirect(url_for("application.dash")) + else: + return redirect(url_for("application.auth")) # App deployment diff --git a/application/__init__.py b/application/__init__.py index 8bb7f47..b3b5ada 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -17,8 +17,7 @@ migrate = Migrate(app, db) # bp import from application.auth.views import auth_blueprint - -# from application.strike.views import strike_blueprint +from application.dash.views import dash_blueprint # Login manager from application.auth.models import User @@ -35,5 +34,5 @@ def load_user(user_id): # type: ignore # Blueprint magic -# app.register_blueprint(strike_blueprint, url_prefix="/staking") +app.register_blueprint(dash_blueprint, url_prefix="/dash") app.register_blueprint(auth_blueprint, url_prefix="/auth") diff --git a/application/auth/views.py b/application/auth/views.py index 6fa467b..55b9b06 100644 --- a/application/auth/views.py +++ b/application/auth/views.py @@ -25,7 +25,7 @@ def login(): user.password, password # type: ignore ): login_user(user) # type: ignore - return redirect(url_for("staking.strikers")) + return redirect(url_for("application.dash")) else: feedback = "Foutieve login." diff --git a/application/dash/forms.py b/application/dash/forms.py new file mode 100644 index 0000000..57d8c19 --- /dev/null +++ b/application/dash/forms.py @@ -0,0 +1,9 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, URLField +from wtforms.validators import DataRequired + + +class ServiceForm(FlaskForm): + name = StringField("Service name:", validators=[DataRequired()]) + url = URLField("Service URL:", validators=[DataRequired()]) + submit = SubmitField("Add") diff --git a/application/dash/models.py b/application/dash/models.py new file mode 100644 index 0000000..b468005 --- /dev/null +++ b/application/dash/models.py @@ -0,0 +1,7 @@ +from application import db + + +class Service(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String, nullable=False) + url = db.Column(db.String, nullable=False) diff --git a/application/dash/templates/dash.html b/application/dash/templates/dash.html new file mode 100644 index 0000000..e69de29 diff --git a/application/dash/views.py b/application/dash/views.py new file mode 100644 index 0000000..4acb3be --- /dev/null +++ b/application/dash/views.py @@ -0,0 +1,61 @@ +from flask import ( + Blueprint, + render_template, + redirect, + url_for, + request, + flash, + session, + get_flashed_messages, +) +from application import db +from application.dash.models import Service +from application.dash.forms import ServiceForm +from flask_login import login_required, current_user + +dash_blueprint = Blueprint("dash", __name__, template_folder="templates") + +# Routes + +""" +@strike_blueprint.route("/bedankt", methods=["GET"]) +def thanks(): + return render_template("bedankt.html") +""" + + +@dash_blueprint.route("/", methods=["GET", "POST"]) +@login_required +def index(): + session["_flashes"] = [] + my_form = ServiceForm() + + if request.method == "POST": + if my_form.validate_on_submit(): + flash("Het formulier is succesvol gePOST") + + session["naam"] = my_form.name.data + session["url"] = my_form.url.data + flash("De gegevens zijn in de sessie opgeslagen") + + new_service = Service(name=my_form.name.data, url=my_form.url.data) + db.session.add(new_service) + db.session.commit() + flash("De gegevens zijn in de database opgeslagen") + + return redirect(url_for("application.dash")) + else: + flash("Het formulier is niet goed ingevuld") + + return render_template("dash.html", form=my_form) + + +""" +@strike_blueprint.route("/stakers") +@login_required +def strikers(): + rows = Striker.query.all() + return render_template( + "strikers.html", rows=rows, user=current_user.username + ) +""" diff --git a/application/templates/base.html b/application/templates/base.html index 3d081ec..731836a 100644 --- a/application/templates/base.html +++ b/application/templates/base.html @@ -7,7 +7,6 @@ {% block title %}{% endblock %} - diff --git a/application/templates/home.html b/application/templates/home.html index c602bf9..1c60278 100644 --- a/application/templates/home.html +++ b/application/templates/home.html @@ -1,9 +1,9 @@ {% extends 'base.html' %} {% block title %} -Staak-app +Idk applicatie {% endblock %} {% block content %} -

Welkom bij de staak-app!

+

Dit is de home page, hopelijk redirect de pagina

{% endblock %} \ No newline at end of file diff --git a/forms.py b/forms.py index 5e1e169..57d8c19 100644 --- a/forms.py +++ b/forms.py @@ -7,7 +7,3 @@ class ServiceForm(FlaskForm): name = StringField("Service name:", validators=[DataRequired()]) url = URLField("Service URL:", validators=[DataRequired()]) submit = SubmitField("Add") - - -class LoginForm(FlaskForm): - pass diff --git a/run.py b/run.py index 7ae4511..a29d891 100644 --- a/run.py +++ b/run.py @@ -12,6 +12,7 @@ def index(): # Return HTML content return "

This is the default page

" + @app.route("/dashboard") def dashboard(): # Return Dashboard.html