add things
This commit is contained in:
8
web/Dockerfile
Normal file
8
web/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM python:3.11
|
||||
|
||||
WORKDIR /web
|
||||
COPY . /web
|
||||
|
||||
RUN pip install flask flask_sqlalchemy pymysql authlib requests
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
50
web/app.py
Normal file
50
web/app.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from flask import Flask, redirect, url_for, session, render_template
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://flaskuser:flaskpass@mariadb/flaskdb'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
app.secret_key = 'ninolabat'
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
# Configuration de Authlib
|
||||
oauth = OAuth(app)
|
||||
|
||||
keycloak = oauth.register(
|
||||
name='keycloak',
|
||||
client_id='flask-app',
|
||||
client_secret='jp4T3FnlpzHyc4Ch4zNoO8cAakXzHi50',
|
||||
server_metadata_url='http://keycloak:8080/realms/GestHub/.well-known/openid-configuration',
|
||||
client_kwargs={
|
||||
'scope': 'openid profile email',
|
||||
}
|
||||
)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
user = session.get('user')
|
||||
if user:
|
||||
return render_template('/view/index.html', user=user)
|
||||
return redirect(url_for('login'))
|
||||
|
||||
@app.route('/login')
|
||||
def login():
|
||||
redirect_uri = url_for('auth', _external=True)
|
||||
return keycloak.authorize_redirect(redirect_uri)
|
||||
|
||||
@app.route('/auth')
|
||||
def auth():
|
||||
token = keycloak.authorize_access_token()
|
||||
userinfo = keycloak.parse_id_token(token)
|
||||
session['user'] = userinfo
|
||||
return redirect('/')
|
||||
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
session.pop('user', None)
|
||||
return redirect('/')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0')
|
||||
3
web/assets/css/index.css
Normal file
3
web/assets/css/index.css
Normal file
@@ -0,0 +1,3 @@
|
||||
body{
|
||||
background-color: bisque;
|
||||
}
|
||||
0
web/assets/images/fakeimg.img
Normal file
0
web/assets/images/fakeimg.img
Normal file
12
web/view/index.html
Normal file
12
web/view/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
Hello World!
|
||||
<h1>Welcome to the GestHub Web Interface</h1>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user