Gregniuki commited on
Commit
3ce2714
1 Parent(s): 8268a41

Update auth.py

Browse files
Files changed (1) hide show
  1. auth.py +15 -4
auth.py CHANGED
@@ -37,20 +37,31 @@ class UserCreate(BaseModel):
37
  email: str
38
  password: str
39
  confirm_password: str
40
-
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  from emailx import send_verification_email, generate_verification_token
43
 
44
- pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
45
 
46
- def register(user: UserCreate, db: Session):
47
  # Validate email format and check for existing users
48
  db_user = get_user_by_email(db, user.email)
49
  if db_user:
50
  raise HTTPException(status_code=400, detail="Email already registered")
51
 
52
  # Hash the password
53
- hashed_password = pwd_context.hash(user.password)
54
 
55
  # Generate a verification token
56
  verification_token = generate_verification_token(user.email)
 
37
  email: str
38
  password: str
39
  confirm_password: str
40
+
41
+ def authenticate_user(db: Session, email: str, password: str):
42
+ # Check if the user with the provided email exists in the database
43
+ user = get_user_by_email(db, email)
44
+ if user is None:
45
+ return None # User not found
46
+
47
+ # Check if the provided password is correct (You should verify the password)
48
+ if not pwd_context.verify(password, user.hashed_password):
49
+ return None # Incorrect password
50
+
51
+ return user # Authentication succeeded
52
 
53
  from emailx import send_verification_email, generate_verification_token
54
 
55
+ #pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
56
 
57
+ def register(self, user: UserCreate, db: Session):
58
  # Validate email format and check for existing users
59
  db_user = get_user_by_email(db, user.email)
60
  if db_user:
61
  raise HTTPException(status_code=400, detail="Email already registered")
62
 
63
  # Hash the password
64
+ hashed_password = self.pwd_context.hash(user.password)
65
 
66
  # Generate a verification token
67
  verification_token = generate_verification_token(user.email)