mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 11:19:57 +00:00
Moved frontend stuff to main area
This commit is contained in:
2
AT_frontend/.gitignore
vendored
2
AT_frontend/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
venvs/
|
|
||||||
.__pychache__/
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
from flask import Flask, render_template, session, redirect, url_for, session
|
|
||||||
from flask_wtf import FlaskForm
|
|
||||||
from wtforms import (
|
|
||||||
StringField,
|
|
||||||
BooleanField,
|
|
||||||
RadioField,
|
|
||||||
SelectField,
|
|
||||||
TextAreaField,
|
|
||||||
SubmitField,
|
|
||||||
)
|
|
||||||
from wtforms.validators import DataRequired
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
app.config["SECRET_KEY"] = "mijngeheimesleutel"
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run(debug=True)
|
|
||||||
3
app.py
3
app.py
@@ -2,6 +2,7 @@ from application import app
|
|||||||
from application.api.views import api_blueprint
|
from application.api.views import api_blueprint
|
||||||
from application.auth.views import auth_blueprint
|
from application.auth.views import auth_blueprint
|
||||||
from application.dashboard.views import dash_blueprint
|
from application.dashboard.views import dash_blueprint
|
||||||
|
from flask import redirect, url_for
|
||||||
|
|
||||||
app.register_blueprint(api_blueprint, url_prefix="/api")
|
app.register_blueprint(api_blueprint, url_prefix="/api")
|
||||||
app.register_blueprint(auth_blueprint, url_prefix="/auth")
|
app.register_blueprint(auth_blueprint, url_prefix="/auth")
|
||||||
@@ -11,7 +12,7 @@ app.register_blueprint(dash_blueprint, url_prefix="/dash")
|
|||||||
# Default app route
|
# Default app route
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
return "Hello, World!"
|
return redirect(url_for("auth.demo"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from flask import Flask
|
|||||||
from flask_migrate import Migrate
|
from flask_migrate import Migrate
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from pyplatex import ANPR # type: ignore
|
from pyplatex import ANPR # type: ignore
|
||||||
|
from authlib.integrations.flask_client import OAuth
|
||||||
|
|
||||||
# Web Server
|
# Web Server
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -17,3 +18,25 @@ migrate = Migrate(app, db)
|
|||||||
|
|
||||||
# ANPR instance
|
# ANPR instance
|
||||||
anpr = ANPR()
|
anpr = ANPR()
|
||||||
|
|
||||||
|
# Keycloak
|
||||||
|
oauth = OAuth(app=app)
|
||||||
|
url = "http://192.168.69.1:8180"
|
||||||
|
keycloak: ... = oauth.register(
|
||||||
|
name="keycloak",
|
||||||
|
client_id="ProjectIOT",
|
||||||
|
client_secret="IWKfsx2aLHCMr0iUaZOuws6UwiYrVQ60",
|
||||||
|
authorize_url=(f"{url}/realms/ProjectIOT/protocol/openid-connect/auth"),
|
||||||
|
authorize_params=None,
|
||||||
|
access_token_url=(
|
||||||
|
f"{url}/realms/ProjectIOT/protocol/openid-connect/token"
|
||||||
|
),
|
||||||
|
refresh_token_url=(
|
||||||
|
f"{url}/realms/ProjectIOT/protocol/openid-connect/token"
|
||||||
|
),
|
||||||
|
api_base_url=(f"{url}/realms/ProjectIOT/protocol/openid-connect"),
|
||||||
|
client_kwargs={"scope": "openid profile email"},
|
||||||
|
server_metadata_url=(
|
||||||
|
"{url}/realms/ProjectIOT/.well-known/openid-configuration"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
from flask import Blueprint
|
from flask import Blueprint, session, redirect, url_for, render_template
|
||||||
|
from application import keycloak
|
||||||
|
|
||||||
auth_blueprint = Blueprint("auth", __name__, template_folder="templates")
|
auth_blueprint = Blueprint("auth", __name__, template_folder="templates")
|
||||||
|
|
||||||
|
|
||||||
|
@auth_blueprint.route("/demo")
|
||||||
|
def demo():
|
||||||
|
return render_template("login.html")
|
||||||
|
|
||||||
|
|
||||||
|
@auth_blueprint.route("/")
|
||||||
|
def home():
|
||||||
|
user = session.get("user")
|
||||||
|
if user:
|
||||||
|
return f'Hello, {user["name"]}'
|
||||||
|
return redirect(url_for("auth.login"))
|
||||||
|
|
||||||
|
|
||||||
|
@auth_blueprint.route("/login")
|
||||||
|
def login():
|
||||||
|
redirect_uri = url_for("auth.auth", _external=True)
|
||||||
|
return keycloak.authorize_redirect(redirect_uri)
|
||||||
|
|
||||||
|
|
||||||
|
@auth_blueprint.route("/auth")
|
||||||
|
def auth():
|
||||||
|
user = keycloak.userinfo()
|
||||||
|
session["user"] = user
|
||||||
|
return redirect(url_for("auth.home"))
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
Reference in New Issue
Block a user