1
0
mirror of https://github.com/moepman/bk-dss synced 2024-12-22 12:44:27 +01:00

Use ldap/redis. Use external configuration file (example provided). Prepare login.

This commit is contained in:
Markus 2015-06-17 20:13:55 +02:00
parent 67117ebf3c
commit a26eb822c6
6 changed files with 45 additions and 4 deletions

View File

@ -8,6 +8,8 @@ TBA
* py-flask >= 0.10
* py-flask-wtf >= 0.10
* py-ldap >= 2.4.15
* py-redis >= 2.10
## Misc

5
config.cfg.example Normal file
View File

@ -0,0 +1,5 @@
DEBUG = True
SECRET_KEY = "CHANGE!ME"
LDAP_URI = "ldaps://ldap.example.com"
LDAP_BASE = "ou=people,dc=example,dc=com"

View File

@ -2,19 +2,36 @@
from flask import Flask, render_template, redirect, url_for, session
from flask_wtf import Form
import ldap
from redis import Redis
from wtforms.fields import PasswordField, SelectField, StringField, SubmitField
from wtforms.validators import Required
app = Flask(__name__)
app.config['SECRET_KEY'] = 'CHANGE!ME'
app.config.from_pyfile('index.cfg')
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
rdb = Redis(host='127.0.0.1', password='foobared')
class LoginForm(Form):
user = StringField('Username', validators=[Required()])
pswd = PasswordField('Password', validators=[Required()])
submit = SubmitField('Login')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
if form.validate_on_submit():
# TODO implement login with LDAP
return redirect(url_for('index'))
return render_template('login.html', form=form)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
app.run(host='0.0.0.0', port=5000)

3
templates/_helpers.html Normal file
View File

@ -0,0 +1,3 @@
{% macro render_field(field) %}
<div class="form-group {% if field.errors %}has-error{% endif %}">{{ field.label(class_="control-label") }}{{ field(class_="form-control") }}{% for error in field.errors %}[ {{ error }} ]{% endfor %}</div>
{%- endmacro %}

View File

@ -4,7 +4,6 @@
{% endblock %}
{% block navigation %}
<ul>
<li><a href="#">Foo</a></li>
<li><a href="#">Bar</a></li>
<li><a href="{{ url_for('login') }}">Login</a></li>
</ul>
{% endblock %}

15
templates/login.html Normal file
View File

@ -0,0 +1,15 @@
{% from "_helpers.html" import render_field %}
{% extends "base.html" %}
{% block content %}
<form method="POST">
{{ form.hidden_tag() }}
{{ render_field(form.user) }}
{{ render_field(form.pswd) }}
<div class="form-group">{{ form.submit(class_="btn btn-default") }}</div>
</form>
{% endblock %}
{% block navigation %}
<ul>
<li><a href="{{ url_for('login') }}">Login</a></li>
</ul>
{% endblock %}