-
Notifications
You must be signed in to change notification settings - Fork 0
/
utenti_dao.py
67 lines (49 loc) · 1.63 KB
/
utenti_dao.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sqlite3
def check_secure(password):
if len(password) < 8:
return False
if len(password) > 30:
return False
if not any(char.isdigit() for char in password):
return False
if not any(char.isupper() for char in password):
return False
if not any(char.islower() for char in password):
return False
return True
def get_user_by_id(id_utente):
query = 'SELECT * FROM utenti WHERE id = ?'
connection = sqlite3.connect('db/fundraisin.db')
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute(query, (id_utente,))
result = cursor.fetchone()
cursor.close()
connection.close()
return result
def get_user_by_email(email_utente):
query = 'SELECT * FROM utenti WHERE email = ?'
connection = sqlite3.connect('db/fundraisin.db')
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute(query, (email_utente,))
result = cursor.fetchone()
cursor.close()
connection.close()
return result
def creare_utente(nuovo_utente):
query = 'INSERT INTO utenti(nome,cognome,email,password) VALUES (?,?,?,?)'
connection = sqlite3.connect('db/fundraisin.db')
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
success = False
try:
cursor.execute(query, (nuovo_utente['nome'],nuovo_utente['cognome'],nuovo_utente['email'], nuovo_utente['password']))
connection.commit()
success = True
except Exception as e:
print('Error', str(e))
connection.rollback()
cursor.close()
connection.close()
return success