# HG changeset patch # User michalr # Date 1298402710 0 # Node ID 79fc37fe85a6f0241857c610f17aeb505d089f13 # Parent e0061735c32721bf896316f97654dc4fe8e931ee Zabawy z Flaskiem ciąg dalszy, zaczyna to jakoś wyglądać diff -r e0061735c327 -r 79fc37fe85a6 frontend/config.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontend/config.ini Tue Feb 22 19:25:10 2011 +0000 @@ -0,0 +1,9 @@ +[Basic] +# W przypadku sqlite, ścieżka do pliku bazy +Database = ../baza.sqlite +# Wygenerować losowy dla każdej instalacji bazy +Secret_Key = TakBardzoTajne +# Dla poważnej instalacji ustawić na 0 +Debug = 1 +# Algorytm wyliczający hashe dla haseł +HashCrypto = sha1 diff -r e0061735c327 -r 79fc37fe85a6 frontend/mfrontend/templates/layout.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontend/mfrontend/templates/layout.html Tue Feb 22 19:25:10 2011 +0000 @@ -0,0 +1,16 @@ + +Flaskr +
+

NO HEJ

+
+ {% if not session.logged_in %} + log in + {% else %} + log out + {% endif %} +
+ {% for message in get_flashed_messages() %} +
{{ message }}
+ {% endfor %} + {% block body %}{% endblock %} +
diff -r e0061735c327 -r 79fc37fe85a6 frontend/mfrontend/templates/login.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontend/mfrontend/templates/login.html Tue Feb 22 19:25:10 2011 +0000 @@ -0,0 +1,14 @@ +{% extends "layout.html" %} +{% block body %} +

Login

+ {% if error %}

Error: {{ error }}{% endif %} +

+
+
Username: +
+
Password: +
+
+
+
+{% endblock %} diff -r e0061735c327 -r 79fc37fe85a6 frontend/mfrontend/utils.py --- a/frontend/mfrontend/utils.py Tue Feb 22 18:37:32 2011 +0000 +++ b/frontend/mfrontend/utils.py Tue Feb 22 19:25:10 2011 +0000 @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -import random, string +import random, string, hashlib from ConfigParser import SafeConfigParser def randomString(n): @@ -16,9 +16,19 @@ """Funkcja tworząca domyślny plik .ini z ustawieniami aplikacji""" config = SafeConfigParser() config.add_section('Basic') - config.set('Basic', 'Database', '../baza.sqlite') + config.set('Basic', 'Database', 'baza.sqlite') config.set('Basic', 'Debug', '0') config.set('Basic', 'Secret_Key', randomString(10)) + config.set('Basic', 'HashCrypto', 'sha512') with open('config.ini', 'wb') as configfile: config.write(configfile) +def hashPassword(password): + """Funkcja hashuje hasła.""" + config = SafeConfigParser() + config.read('config.ini') + m = hashlib.new(config.get('Basic', 'HashCrypto')) + m.update(config.get('Basic', 'Secret_Key')) + m.update(password) + return m.hexdigest() + diff -r e0061735c327 -r 79fc37fe85a6 frontend/mfrontend/views/frontend.py --- a/frontend/mfrontend/views/frontend.py Tue Feb 22 18:37:32 2011 +0000 +++ b/frontend/mfrontend/views/frontend.py Tue Feb 22 19:25:10 2011 +0000 @@ -1,8 +1,21 @@ -from flask import Module -from mfrontend import db +#!/usr/bin/python +# -*- coding: utf-8 -*- + +from flask import Module, render_template, request, url_for +from mfrontend import db, utils frontend = Module(__name__) @frontend.route('/') def index(): lol = db.query_db('select id, username, password from users') return lol[0]['username'] + +@frontend.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + return "Uname: {0}
Passwd: {1}
Hashpwd: {2}".format( + request.form['username'], + request.form['password'], + utils.hashPassword(request.form['password'])) + return render_template('login.html') +