forked from CodecoolBase/ask-mate-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_data_manager.py
More file actions
67 lines (55 loc) · 1.72 KB
/
user_data_manager.py
File metadata and controls
67 lines (55 loc) · 1.72 KB
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 connection
@connection.connection_handler
def insert_new_user(cursor, submission_time, username, h_password, user_reputation):
cursor.execute("""
insert into "user" (submission_time, user_name,hashed_password, reputation)
values (%(submission_time)s, %(username)s, %(h_password)s, %(user_reputation)s)
""",
{'submission_time': submission_time, 'username': username, 'h_password': h_password, 'user_reputation': user_reputation})
@connection.connection_handler
def find_user(cursor, username):
cursor.execute("""
select user_name
from "user"
where user_name=%(username)s""",
{'username': username})
result = cursor.fetchone()
if result == None:
result = {'user_name':None}
return result
@connection.connection_handler
def get_user_id(cursor, username):
cursor.execute("""
select id from "user"
where user_name = %(username)s
""",
{'username': username})
result = cursor.fetchone()
return result
@connection.connection_handler
def get_hashed_password(cursor, user_name):
cursor.execute("""
SELECT hashed_password
FROM "user"
WHERE user_name = %(user_name)s
""",
{'user_name' : user_name})
result = cursor.fetchone()
return result
@connection.connection_handler
def select_all_user(cursor):
cursor.execute("""
select * from "user"
ORDER BY id
""")
result=cursor.fetchall()
return result
@connection.connection_handler
def get_user_data(cursor, u_id):
cursor.execute("""
select id, user_name, submission_time, reputation from "user"
where id = %(u_id)s
""",
{'u_id': u_id})
result= cursor.fetchone()
return result