Mercurial > kraina_muminkow
diff frontend/mfrontend/views/frontend.py @ 4:cf786ee26a22
MOŻNA SIĘ LOGOWAĆ I WYLOGOWAĆ jestem wspaniały
author | michalr |
---|---|
date | Tue, 22 Feb 2011 20:38:51 +0000 |
parents | 79fc37fe85a6 |
children | 3ba60dfc1d64 |
line wrap: on
line diff
--- a/frontend/mfrontend/views/frontend.py Tue Feb 22 19:25:10 2011 +0000 +++ b/frontend/mfrontend/views/frontend.py Tue Feb 22 20:38:51 2011 +0000 @@ -1,21 +1,34 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from flask import Module, render_template, request, url_for +from flask import Module, render_template, request, url_for, escape, session, redirect, flash 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'] + return render_template('hello.html') @frontend.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': + if db.user_can_login(request.form['username'], + request.form['password']) : + session['logged_in'] = True + session['logged_user'] = request.form['username'] + flash('Zalogowano') + return redirect(url_for('index')) return "Uname: {0}<br />Passwd: {1}<br />Hashpwd: {2}".format( request.form['username'], request.form['password'], utils.hashPassword(request.form['password'])) return render_template('login.html') +@frontend.route('/logout') +def logout(): + """Funkcja powoduje wyczyszczenie sesji użytkownika, + a w efekcie wylogowanie z systemu. + """ + session.clear() + flash('Wylogowano') + return redirect(url_for('index'))