-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_service.py
59 lines (53 loc) · 2.07 KB
/
user_service.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
import os, sqlite3
from unittest import result
def adduser(username,password):
database_filename = os.environ.get('DATABASE_FILENAME')
connection = sqlite3.connect(database_filename, check_same_thread=False)
cur = connection.cursor()
cur.execute(
"INSERT INTO USER (USERNAME,PASSWORD) VALUES (?,?);",(username,password,))
connection.commit()
def verifyUser(username,password):
database_filename = os.environ.get('DATABASE_FILENAME')
connection = sqlite3.connect(database_filename, check_same_thread=False)
cur = connection.cursor()
user=cur.execute("SELECT * FROM USER WHERE USERNAME=?;", (username,)).fetchone()
connection.commit()
if(user==None):
error="User not registered in database"
return False,error
if(user[2]!=password):
error="Wrong password"
return False,error
return True,""
def fetch_user_by_username(username):
database_filename = os.environ.get('DATABASE_FILENAME')
connection = sqlite3.connect(database_filename, check_same_thread=False)
cur = connection.cursor()
user=cur.execute("SELECT * FROM USER WHERE USERNAME=?;", (username,)).fetchone()
connection.commit()
if(user==None):
error="User not registered in database"
return False,error
return user
def fetch_allusers():
database_filename = os.environ.get('DATABASE_FILENAME')
connection = sqlite3.connect(database_filename, check_same_thread=False)
cur = connection.cursor()
users=cur.execute("SELECT * FROM USER ;",).fetchall()
connection.commit()
return users
def deleteUser(username):
database_filename = os.environ.get('DATABASE_FILENAME')
connection = sqlite3.connect(database_filename)
connection.execute(
"DELETE FROM USER WHERE USERNAME LIKE ?;", (username,))
connection.commit()
connection.close()
def deleteUserTest(username):
database_filename = 'teste2e.db'
connection = sqlite3.connect(database_filename)
connection.execute(
"DELETE FROM USER WHERE USERNAME LIKE ?;", (username,))
connection.commit()
connection.close()