main
Micke Nordin 10 months ago
parent c084b2c820
commit 1155e226ab
No known key found for this signature in database
GPG Key ID: F53C4CC83EDAB3BE

@ -1,2 +1,3 @@
# lotosa # LaToSa
LaToSa is a backend for [SaToSa](https://github.com/IdentityPython/SATOSA) and allows you to use local accounts for authentication

@ -6,7 +6,7 @@ from flask import (Flask, flash, redirect, render_template, request,
from flask_login import LoginManager, login_required, login_user, logout_user from flask_login import LoginManager, login_required, login_user, logout_user
from forms import LoginForm from forms import LoginForm
from lotosa import LoToSa from latosa import LaToSa
from user import User from user import User
app = Flask(__name__) app = Flask(__name__)
@ -19,12 +19,12 @@ app.config.update(
login_manager = LoginManager() login_manager = LoginManager()
login_manager.init_app(app) login_manager.init_app(app)
lotosa = LoToSa(app) latosa = LaToSa(app)
@login_manager.user_loader @login_manager.user_loader
def load_user(user_id) -> Union[User, None]: def load_user(user_id) -> Union[User, None]:
for user in lotosa.get_users(): for user in latosa.get_users():
if user.uid == user_id: if user.uid == user_id:
return user return user
return None return None
@ -32,24 +32,24 @@ def load_user(user_id) -> Union[User, None]:
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def index(): def index():
i18n = lotosa.get_i18n(request) i18n = latosa.get_i18n(request)
form = LoginForm() form = LoginForm()
if request.method == 'POST': if request.method == 'POST':
username = form.username.data username = form.username.data
password = form.password.data password = form.password.data
user = lotosa.login_user(username, password) user = latosa.login_user(username, password)
if user: if user:
login_user(user) login_user(user)
flash('Logged in successfully.') flash(i18n['login']['success'])
return redirect(url_for('admin')) return redirect(url_for('admin'))
flash('Logged in faled, please try again.') flash(i18n['login']['failed'])
return render_template('index.html', i18n=i18n, form=form) return render_template('index.html', i18n=i18n, form=form)
@app.route('/admin', methods=['GET']) @app.route('/admin', methods=['GET'])
@login_required @login_required
def admin(): def admin():
i18n = lotosa.get_i18n(request) i18n = latosa.get_i18n(request)
return render_template('admin.html', i18n=i18n) return render_template('admin.html', i18n=i18n)

@ -1,5 +1,9 @@
head: head:
title: LoToSA title: LaToSa
body: body:
h1: LoToSA h1: Local Auth to SAML
login:
failed: Login failed, please try again.
success: Login successful.

@ -7,7 +7,7 @@ from flask import Flask, request
from user import User from user import User
class LoToSa: class LaToSa:
def __init__(self, app: Flask): def __init__(self, app: Flask):
self.users = [ self.users = [

@ -0,0 +1,3 @@
ul {
list-style-type: none;
}

@ -13,6 +13,15 @@
</head> </head>
<body> <body>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li class="notice">{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
{% block content %} {% block content %}
<h1>{{i18n.body.h1}}</h1> <h1>{{i18n.body.h1}}</h1>
<form action="" method="post" novalidate> <form action="" method="post" novalidate>

Loading…
Cancel
Save