Springboardmen commited on
Commit
56751ce
·
verified ·
1 Parent(s): 4cff9d6

Update auth.py

Browse files
Files changed (1) hide show
  1. auth.py +27 -3
auth.py CHANGED
@@ -3,28 +3,52 @@ import jwt
3
  import datetime
4
  import os
5
  from dotenv import load_dotenv
 
6
 
7
  load_dotenv()
8
 
9
  SECRET_KEY = os.getenv("JWT_SECRET", "fallback_secret")
10
 
11
- # Generate OTP
 
12
  def generate_otp():
13
  return str(random.randint(100000, 999999))
14
 
15
- # Create JWT Token
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def create_jwt(email):
 
17
  payload = {
18
  "email": email,
19
  "exp": datetime.datetime.utcnow() + datetime.timedelta(hours=1)
20
  }
 
21
  token = jwt.encode(payload, SECRET_KEY, algorithm="HS256")
 
22
  return token
23
 
24
- # Verify JWT
 
25
  def verify_jwt(token):
 
26
  try:
27
  decoded = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
28
  return decoded
 
29
  except:
30
  return None
 
3
  import datetime
4
  import os
5
  from dotenv import load_dotenv
6
+ from database import register_user, login_user_db, save_otp, verify_otp_db
7
 
8
  load_dotenv()
9
 
10
  SECRET_KEY = os.getenv("JWT_SECRET", "fallback_secret")
11
 
12
+
13
+ # ---------------- OTP ----------------
14
  def generate_otp():
15
  return str(random.randint(100000, 999999))
16
 
17
+
18
+ # ---------------- SIGNUP ----------------
19
+ def signup_user(email, password):
20
+ return register_user(email, password)
21
+
22
+
23
+ # ---------------- LOGIN ----------------
24
+ def login_user(email, password):
25
+ return login_user_db(email, password)
26
+
27
+
28
+ # ---------------- OTP VERIFY ----------------
29
+ def verify_user_otp(email, otp):
30
+ return verify_otp_db(email, otp)
31
+
32
+
33
+ # ---------------- JWT ----------------
34
  def create_jwt(email):
35
+
36
  payload = {
37
  "email": email,
38
  "exp": datetime.datetime.utcnow() + datetime.timedelta(hours=1)
39
  }
40
+
41
  token = jwt.encode(payload, SECRET_KEY, algorithm="HS256")
42
+
43
  return token
44
 
45
+
46
+ # ---------------- VERIFY TOKEN ----------------
47
  def verify_jwt(token):
48
+
49
  try:
50
  decoded = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
51
  return decoded
52
+
53
  except:
54
  return None