Compare commits

..

3 Commits

Author SHA1 Message Date
82a506278b Basic login redirect
All checks were successful
continuous-integration/drone/push Build is passing
2021-06-11 14:23:13 +02:00
043eaff5fd Templates support 2021-06-11 14:14:04 +02:00
8ef45fd03e Simple dev target 2021-06-11 14:13:55 +02:00
8 changed files with 58 additions and 8 deletions

View File

@ -45,7 +45,5 @@ your technology stack.
It's a [FastAPI](https://fastapi.tiangolo.com/) application. It's a [FastAPI](https://fastapi.tiangolo.com/) application.
``` ```
$ python3 -m venv .venv && source .venv/bin/activate
$ pip install -e .
$ make $ make
``` ```

View File

@ -1,10 +1,27 @@
"""Community Keycloak SSO user management.""" """Community Keycloak SSO user management."""
from fastapi import FastAPI from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.templating import Jinja2Templates
from starlette.middleware.sessions import SessionMiddleware
app = FastAPI() app = FastAPI()
app.add_middleware(SessionMiddleware, secret_key="mysecretzkey")
templates = Jinja2Templates(directory="templates")
@app.get("/") @app.get("/", response_class=HTMLResponse)
def read_root(): async def home(request: Request):
return {"Hello": "World"} user = request.session.get("user")
if user:
return templates.TemplateResponse(
"index.html", context={"request": request}
)
return RedirectResponse("/login")
@app.get("/login", response_class=HTMLResponse)
async def login(request: Request):
return templates.TemplateResponse(
"login.html", context={"request": request}
)

View File

@ -2,4 +2,9 @@
.PHONY: run .PHONY: run
run: run:
@uvicorn keycloak_collective_portal:app --reload @if [ ! -d ".venv" ]; then \
python3 -m venv .venv && \
.venv/bin/pip install -U pip setuptools wheel poetry && \
.venv/bin/poetry install --dev; \
fi
.venv/bin/poetry run uvicorn keycloak_collective_portal:app --reload

14
poetry.lock generated
View File

@ -121,6 +121,14 @@ pipfile_deprecated_finder = ["pipreqs", "requirementslib"]
requirements_deprecated_finder = ["pipreqs", "pip-api"] requirements_deprecated_finder = ["pipreqs", "pip-api"]
colors = ["colorama (>=0.4.3,<0.5.0)"] colors = ["colorama (>=0.4.3,<0.5.0)"]
[[package]]
name = "itsdangerous"
version = "2.0.1"
description = "Safely pass data to untrusted environments and back."
category = "main"
optional = false
python-versions = ">=3.6"
[[package]] [[package]]
name = "jinja2" name = "jinja2"
version = "3.0.1" version = "3.0.1"
@ -324,7 +332,7 @@ python-versions = ">=3.6.1"
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = "^3.9" python-versions = "^3.9"
content-hash = "27448995033f96e0639ead7c435ba26b4758706f9e26ecb5ade3d29692959668" content-hash = "a3278c69c36a0390a247780ff0ad55c878d2e1ea028097bd46d8998d1c449ce1"
[metadata.files] [metadata.files]
appdirs = [ appdirs = [
@ -380,6 +388,10 @@ isort = [
{file = "isort-5.8.0-py3-none-any.whl", hash = "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d"}, {file = "isort-5.8.0-py3-none-any.whl", hash = "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d"},
{file = "isort-5.8.0.tar.gz", hash = "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6"}, {file = "isort-5.8.0.tar.gz", hash = "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6"},
] ]
itsdangerous = [
{file = "itsdangerous-2.0.1-py3-none-any.whl", hash = "sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c"},
{file = "itsdangerous-2.0.1.tar.gz", hash = "sha256:9e724d68fc22902a1435351f84c3fb8623f303fffcc566a4cb952df8c572cff0"},
]
jinja2 = [ jinja2 = [
{file = "Jinja2-3.0.1-py3-none-any.whl", hash = "sha256:1f06f2da51e7b56b8f238affdd6b4e2c61e39598a378cc49345bc1bd42a978a4"}, {file = "Jinja2-3.0.1-py3-none-any.whl", hash = "sha256:1f06f2da51e7b56b8f238affdd6b4e2c61e39598a378cc49345bc1bd42a978a4"},
{file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"}, {file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"},

View File

@ -10,6 +10,7 @@ python = "^3.9"
fastapi = "^0.65.2" fastapi = "^0.65.2"
uvicorn = {extras = ["standard"], version = "^0.14.0"} uvicorn = {extras = ["standard"], version = "^0.14.0"}
Jinja2 = "^3.0.1" Jinja2 = "^3.0.1"
itsdangerous = "^2.0.1"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
black = "^21.6b0" black = "^21.6b0"

1
styles.css Normal file
View File

@ -0,0 +1 @@
// TODO

8
templates/index.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
<title>Home</title>
</head>
<body>
<p>Hello, World</p>
</body>
</html>

8
templates/login.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
<title>Login</title>
</head>
<body>
<p>Please login</p>
</body>
</html>