Update auth.py
Browse files
auth.py
CHANGED
@@ -47,23 +47,21 @@ class UserCreate(BaseModel):
|
|
47 |
email: str
|
48 |
password: str
|
49 |
confirm_password: str
|
50 |
-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
51 |
|
|
|
|
|
52 |
def authenticate_user(db: Session, email: str, password: str):
|
53 |
-
# Check if the user with the provided email exists in the database
|
54 |
user = get_user_by_email(db, email)
|
55 |
if user is None:
|
56 |
raise HTTPException(status_code=400, detail="User not found")
|
57 |
-
# return None # User not found
|
58 |
|
59 |
-
#
|
60 |
-
if not pwd_context.verify(password, user.hashed_password):
|
61 |
-
print("Stored Password:", user.hashed_password)
|
62 |
-
print("Provided Password:", password)
|
63 |
raise HTTPException(status_code=400, detail="Incorrect password")
|
64 |
-
# return None # Incorrect password
|
65 |
|
66 |
-
return user
|
|
|
|
|
67 |
|
68 |
from emailx import send_verification_email, generate_verification_token
|
69 |
|
@@ -95,7 +93,7 @@ def register(user: UserCreate, db: Session):
|
|
95 |
raise HTTPException(status_code=400, detail="Email already registered")
|
96 |
|
97 |
# Hash the password
|
98 |
-
hashed_password = pwd_context.hash(user.password)
|
99 |
|
100 |
# Generate a verification token
|
101 |
verification_token = generate_verification_token(user.email)
|
|
|
47 |
email: str
|
48 |
password: str
|
49 |
confirm_password: str
|
|
|
50 |
|
51 |
+
|
52 |
+
# Use auth_views.pwd_context to access the password context from the AuthViews instance
|
53 |
def authenticate_user(db: Session, email: str, password: str):
|
|
|
54 |
user = get_user_by_email(db, email)
|
55 |
if user is None:
|
56 |
raise HTTPException(status_code=400, detail="User not found")
|
|
|
57 |
|
58 |
+
# Use the pwd_context from the auth_views instance
|
59 |
+
if not auth_views.pwd_context.verify(password, user.hashed_password):
|
|
|
|
|
60 |
raise HTTPException(status_code=400, detail="Incorrect password")
|
|
|
61 |
|
62 |
+
return user
|
63 |
+
|
64 |
+
|
65 |
|
66 |
from emailx import send_verification_email, generate_verification_token
|
67 |
|
|
|
93 |
raise HTTPException(status_code=400, detail="Email already registered")
|
94 |
|
95 |
# Hash the password
|
96 |
+
hashed_password = auth_views.pwd_context.hash(user.password)
|
97 |
|
98 |
# Generate a verification token
|
99 |
verification_token = generate_verification_token(user.email)
|