comparison frontend/mfrontend/db.py @ 4:cf786ee26a22

MOŻNA SIĘ LOGOWAĆ I WYLOGOWAĆ jestem wspaniały
author michalr
date Tue, 22 Feb 2011 20:38:51 +0000
parents c3fb1e9fc1f7
children 3ba60dfc1d64
comparison
equal deleted inserted replaced
3:79fc37fe85a6 4:cf786ee26a22
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 import sqlite3 4 import sqlite3
5 from flask import g 5 from flask import g
6 import ConfigParser 6 import ConfigParser
7 from mfrontend import utils
7 8
8 config = ConfigParser.SafeConfigParser() 9 config = ConfigParser.SafeConfigParser()
9 config.read('config.ini') 10 config.read('config.ini')
10 11
11 def connect_db(): 12 def connect_db():
22 """ 23 """
23 cur = g.db.execute(query, args) 24 cur = g.db.execute(query, args)
24 rv = [dict((cur.description[idx][0], value) 25 rv = [dict((cur.description[idx][0], value)
25 for idx, value in enumerate(row)) for row in cur.fetchall()] 26 for idx, value in enumerate(row)) for row in cur.fetchall()]
26 return (rv[0] if rv else None) if one else rv 27 return (rv[0] if rv else None) if one else rv
28
29 def user_can_login(username, password):
30 """Funkcja sprawdzająca, czy podany użytkownik może sie zalogować
31 po podaniu danego w argumencie hasła.
32 @param username Nazwa użytkownika
33 @param password Hasło
34 @return Prawda, jeśli podane dane są akceptowalne, w przeciwnym
35 razie fałsz.
36 """
37 user = query_db('select * from users where username = ?',
38 [username], one=True)
39 if user is None: # Brak użytkownika o takiej nazwie
40 return False
41 if user['password'] == utils.hashPassword(password):
42 return True # Jeśli mamy takiego użytkownika, i hasło się zgadza
43 # Najwyraźniej jest taki użytkownik, ale hasło się nie zgadza
44 return False