-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb.py
97 lines (87 loc) · 2.66 KB
/
db.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import pymysql
import credential
def user_signup(user_name,email,password):
conn=pymysql.connect(
host=credential.host,
port=credential.port,
user=credential.user,
password=credential.password,
db=credential.databasename
)
try:
with conn.cursor() as curr:
sql = "insert into usermaster (user_name,email,user_password,user_confirmation) value (%s,%s,%s,%s)"
curr.execute(sql,(user_name,email,password,"1"))
conn.commit()
except Exception as e:
print(e)
def login(email,password):
conn=pymysql.connect(
host=credential.host,
port=credential.port,
user=credential.user,
password=credential.password,
db=credential.databasename
)
try:
with conn.cursor() as curr:
sql = "select user_password from usermaster where email=(%s)"
curr.execute(sql,email)
output = curr.fetchone()
if (output):
if password==output[0]:
return "correct_password"
else:
return "wrong_password"
return 'username_dosenot_exist'
except Exception as e:
print(e)
def update(email):
conn=pymysql.connect(
host=credential.host,
port=credential.port,
user=credential.user,
password=credential.password,
db=credential.databasename
)
try:
with conn.cursor() as curr:
sql="update usermaster set email_confirmation=(%s) where email=(%s)"
temp=2
curr.execute(sql,(temp,email))
conn.commit()
except Exception as e:
print(e)
def mail_confirm(email):
conn=pymysql.connect(
host=credential.host,
port=credential.port,
user=credential.user,
password=credential.password,
db=credential.databasename
)
try:
with conn.cursor() as curr:
sql="select email_confirmation from usermaster where email=(%s)"
curr.execute(sql,(email))
output=curr.fetchone()
if(output[0]=="2"): return True
return False
# conn.commit()
except Exception as e:
print(e)
def delete(email):
conn=pymysql.connect(
host=credential.host,
port=credential.port,
user=credential.user,
password=credential.password,
db=credential.databasename
)
try:
with conn.cursor() as curr:
sql="delete from usermaster where email=(%s)"
curr.execute(sql,(email))
conn.commit()
except Exception as e:
print(e)