Update auth.py
Browse files
auth.py
CHANGED
@@ -41,16 +41,15 @@ class UserCreate(BaseModel):
|
|
41 |
|
42 |
from emailx import send_verification_email, generate_verification_token
|
43 |
|
44 |
-
# ...
|
45 |
|
46 |
-
def register(
|
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 =
|
54 |
|
55 |
# Generate a verification token
|
56 |
verification_token = generate_verification_token(user.email)
|
@@ -59,7 +58,7 @@ def register(self, user: UserCreate, db: Session = Depends(get_db)):
|
|
59 |
send_verification_email(user.email, verification_token)
|
60 |
|
61 |
# Create the user in the database
|
62 |
-
user_in_db =
|
63 |
db.add(user_in_db)
|
64 |
db.commit()
|
65 |
db.refresh(user_in_db)
|
|
|
41 |
|
42 |
from emailx import send_verification_email, generate_verification_token
|
43 |
|
|
|
44 |
|
45 |
+
def register(user: UserCreate, db: Session):
|
46 |
# Validate email format and check for existing users
|
47 |
db_user = get_user_by_email(db, user.email)
|
48 |
if db_user:
|
49 |
raise HTTPException(status_code=400, detail="Email already registered")
|
50 |
|
51 |
# Hash the password
|
52 |
+
hashed_password = pwd_context.hash(user.password)
|
53 |
|
54 |
# Generate a verification token
|
55 |
verification_token = generate_verification_token(user.email)
|
|
|
58 |
send_verification_email(user.email, verification_token)
|
59 |
|
60 |
# Create the user in the database
|
61 |
+
user_in_db = User(email=user.email, hashed_password=hashed_password)
|
62 |
db.add(user_in_db)
|
63 |
db.commit()
|
64 |
db.refresh(user_in_db)
|