Commit 8137670d authored by Nicolas Joyard's avatar Nicolas Joyard

Ajout admin

parent 6f5068a6
# -*- coding: utf-8 -*-
from getpass import getpass
import hmac
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
......@@ -23,6 +26,15 @@ def runserver():
app.run()
@manager.command
def password():
"""Chiffre un mot de passe admin"""
h = hmac.new(bytes(app.config['SECRET_KEY'], encoding='ascii'))
h.update(bytes(getpass(), encoding='utf-8'))
print(h.hexdigest())
@manager.command
def import_etapes():
"""Crée ou met à jour la liste des étapes"""
......
......@@ -38,6 +38,9 @@ class DefaultConfig(object):
PIWIK_HOST = None
PIWIK_ID = None
ADMIN_EMAIL = 'none@example.com'
ADMIN_PASSWORD = None
class DebugConfig(DefaultConfig):
"""
......@@ -56,6 +59,8 @@ class EnvironmentConfig(DefaultConfig):
- IRFM_DATA_DIR: directory for data files
- IRFM_PIWIK_HOST: piwik hostname
- IRFM_PIWIK_ID: piwik site ID
- IRFM_ADMIN_EMAIL: admin email
- IRFM_ADMIN_PASSWORD: admin password as hashed by `irfm password`
"""
DEBUG = os.environ.get('IRFM_DEBUG', 'False') == 'True'
SQLALCHEMY_ECHO = os.environ.get('IRFM_DEBUG_SQL', 'False') == 'True'
......@@ -67,3 +72,7 @@ class EnvironmentConfig(DefaultConfig):
PIWIK_HOST = os.environ.get('IRFM_PIWIK_HOST', DefaultConfig.PIWIK_HOST)
PIWIK_ID = os.environ.get('IRFM_PIWIK_ID', DefaultConfig.PIWIK_ID)
ADMIN_EMAIL = os.environ.get('IRFM_ADMIN_EMAIL', DefaultConfig.ADMIN_EMAIL)
ADMIN_PASSWORD = os.environ.get('IRFM_ADMIN_PASSWORD',
DefaultConfig.ADMIN_PASSWORD)
# -*- coding: utf-8 -*-
import hmac
from flask import request, session
......@@ -10,7 +11,23 @@ def setup_routes(app):
@app.route('/login', methods=['POST'])
def login():
if app.config['ADMIN_PASSWORD'] and request.form['nick'] == '!rc':
h = hmac.new(bytes(app.config['SECRET_KEY'], encoding='ascii'))
h.update(bytes(request.form['email'], encoding='utf-8'))
digest = h.hexdigest()
if hmac.compare_digest(digest, app.config['ADMIN_PASSWORD']):
session['user'] = {
'nick': '!rc',
'email': app.config['ADMIN_EMAIL'],
'admin': True
}
return redirect_back()
nick = sanitize(request.form['nick'])
if nick != request.form['nick']:
msg = 'Seuls les caractères suivants sont autorisés: ' \
'a-z 0-9 _ - @ . '
......@@ -27,7 +44,8 @@ def setup_routes(app):
session['user'] = {
'nick': nick,
'email': request.form['email']
'email': request.form['email'],
'admin': False
}
return redirect_back()
......
......@@ -88,3 +88,8 @@ th.col-right {
border: 1px solid #ccc;
}
img.rc-small {
height: 1.5em;
vertical-align: top;
}
......@@ -31,7 +31,11 @@
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{% if session.user %}
{{ session.user.nick }}
{% if session.user.admin %}
<img class="rc-small" src="{{ url_for('static', filename='rc.png') }}">
{% else %}
{{ session.user.nick }}
{% endif %}
{% else %}
S'identifier
{% endif %}
......@@ -44,7 +48,7 @@
{% else %}
<form class="form-horizontal login-form" method="POST" action="{{ url_for('login') }}">
<input name="nick" type="text" class="form-control" placeholder="Pseudo">
<input name="email" type="email" class="form-control" placeholder="Adresse e-mail">
<input name="email" type="text" class="form-control" placeholder="Adresse e-mail">
<br>
<input type="submit" class="btn btn-primary" value="Valider">
</form>
......
......@@ -111,7 +111,13 @@
{% for act in parlementaire.actions %}
<tr>
<td>{{ act.etape|label_etape }}</td>
<td>{{ act.nick }}</td>
<td>
{% if act.nick == '!rc' %}
<img class="rc-small" src="{{ url_for('static', filename='rc.png') }}">
{% else %}
{{ act.nick }}
{% endif %}
</td>
<td>{{ act.date.strftime("%c") }}</td>
<td class="col-right">
{% if act.etape.ordre == ordres.ETAPE_A_CONFIRMER %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment