Springboardmen commited on
Commit
90baad2
·
verified ·
1 Parent(s): 56751ce

Update database.py

Browse files
Files changed (1) hide show
  1. database.py +32 -6
database.py CHANGED
@@ -1,12 +1,15 @@
1
  import sqlite3
2
- from datetime import date
3
 
 
 
4
  def get_connection():
5
- conn = sqlite3.connect("fitplan.db", check_same_thread=False)
6
  return conn
7
 
8
 
 
9
  def create_tables():
 
10
  conn = get_connection()
11
  cur = conn.cursor()
12
 
@@ -23,8 +26,9 @@ def create_tables():
23
  conn.close()
24
 
25
 
26
- # Register user
27
  def register_user(email, password):
 
28
  conn = get_connection()
29
  cur = conn.cursor()
30
 
@@ -35,14 +39,35 @@ def register_user(email, password):
35
  )
36
  conn.commit()
37
  return True
 
38
  except:
39
  return False
 
40
  finally:
41
  conn.close()
42
 
43
 
44
- # Save OTP
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  def save_otp(email, otp):
 
46
  conn = get_connection()
47
  cur = conn.cursor()
48
 
@@ -55,8 +80,9 @@ def save_otp(email, otp):
55
  conn.close()
56
 
57
 
58
- # Verify OTP
59
- def verify_otp(email, otp):
 
60
  conn = get_connection()
61
  cur = conn.cursor()
62
 
 
1
  import sqlite3
 
2
 
3
+
4
+ # ---------------- DB CONNECTION ----------------
5
  def get_connection():
6
+ conn = sqlite3.connect("users.db", check_same_thread=False)
7
  return conn
8
 
9
 
10
+ # ---------------- CREATE TABLE ----------------
11
  def create_tables():
12
+
13
  conn = get_connection()
14
  cur = conn.cursor()
15
 
 
26
  conn.close()
27
 
28
 
29
+ # ---------------- REGISTER USER ----------------
30
  def register_user(email, password):
31
+
32
  conn = get_connection()
33
  cur = conn.cursor()
34
 
 
39
  )
40
  conn.commit()
41
  return True
42
+
43
  except:
44
  return False
45
+
46
  finally:
47
  conn.close()
48
 
49
 
50
+ # ---------------- LOGIN USER ----------------
51
+ def login_user_db(email, password):
52
+
53
+ conn = get_connection()
54
+ cur = conn.cursor()
55
+
56
+ cur.execute(
57
+ "SELECT * FROM users WHERE email=? AND password=?",
58
+ (email, password)
59
+ )
60
+
61
+ user = cur.fetchone()
62
+
63
+ conn.close()
64
+
65
+ return user
66
+
67
+
68
+ # ---------------- SAVE OTP ----------------
69
  def save_otp(email, otp):
70
+
71
  conn = get_connection()
72
  cur = conn.cursor()
73
 
 
80
  conn.close()
81
 
82
 
83
+ # ---------------- VERIFY OTP ----------------
84
+ def verify_otp_db(email, otp):
85
+
86
  conn = get_connection()
87
  cur = conn.cursor()
88