Update auth.py
Browse files
auth.py
CHANGED
@@ -34,6 +34,10 @@ class UserCreate(BaseModel):
|
|
34 |
password: str
|
35 |
email: str
|
36 |
|
|
|
|
|
|
|
|
|
37 |
def register(self, user: UserCreate, db: Session = Depends(get_db)):
|
38 |
# Validate email format and check for existing users
|
39 |
db_user = database.get_user_by_email(db, user.email)
|
@@ -41,15 +45,16 @@ def register(self, user: UserCreate, db: Session = Depends(get_db)):
|
|
41 |
raise HTTPException(status_code=400, detail="Email already registered")
|
42 |
|
43 |
# Hash the password
|
44 |
-
hashed_password =
|
45 |
|
46 |
-
# Generate a verification token
|
47 |
verification_token = generate_verification_token(user.email)
|
48 |
|
49 |
-
# Send a verification email
|
|
|
50 |
|
51 |
# Create the user in the database
|
52 |
-
user_in_db = User(email=user.email, hashed_password=hashed_password)
|
53 |
db.add(user_in_db)
|
54 |
db.commit()
|
55 |
db.refresh(user_in_db)
|
|
|
34 |
password: str
|
35 |
email: str
|
36 |
|
37 |
+
from email import send_verification_email, generate_verification_token
|
38 |
+
|
39 |
+
# ...
|
40 |
+
|
41 |
def register(self, user: UserCreate, db: Session = Depends(get_db)):
|
42 |
# Validate email format and check for existing users
|
43 |
db_user = database.get_user_by_email(db, user.email)
|
|
|
45 |
raise HTTPException(status_code=400, detail="Email already registered")
|
46 |
|
47 |
# Hash the password
|
48 |
+
hashed_password = self.pwd_context.hash(user.password)
|
49 |
|
50 |
+
# Generate a verification token
|
51 |
verification_token = generate_verification_token(user.email)
|
52 |
|
53 |
+
# Send a verification email
|
54 |
+
send_verification_email(user.email, verification_token)
|
55 |
|
56 |
# Create the user in the database
|
57 |
+
user_in_db = models.User(email=user.email, hashed_password=hashed_password)
|
58 |
db.add(user_in_db)
|
59 |
db.commit()
|
60 |
db.refresh(user_in_db)
|