Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ import os
|
|
22 |
# Environment variables
|
23 |
GOOGLE_CLIENT_ID = os.getenv('GOOGLE_CLIENT_ID')
|
24 |
GOOGLE_CLIENT_SECRET = os.getenv('GOOGLE_CLIENT_SECRET')
|
25 |
-
SECRET_KEY = os.getenv
|
26 |
ALGORITHM = "HS256"
|
27 |
ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
28 |
|
@@ -125,6 +125,23 @@ def register_user(user_data: UserCreate, db: Session):
|
|
125 |
db.commit()
|
126 |
db.refresh(new_user)
|
127 |
return new_user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
def get_user_by_verification_token(db: Session, verification_token: str):
|
129 |
return db.query(User).filter(User.email_verification_token == verification_token).first()
|
130 |
|
|
|
22 |
# Environment variables
|
23 |
GOOGLE_CLIENT_ID = os.getenv('GOOGLE_CLIENT_ID')
|
24 |
GOOGLE_CLIENT_SECRET = os.getenv('GOOGLE_CLIENT_SECRET')
|
25 |
+
SECRET_KEY = os.getenv('SecretKey')
|
26 |
ALGORITHM = "HS256"
|
27 |
ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
28 |
|
|
|
125 |
db.commit()
|
126 |
db.refresh(new_user)
|
127 |
return new_user
|
128 |
+
|
129 |
+
def verify_email(verification_token: str, db: Session = Depends(get_db)):
|
130 |
+
# Verify the email using the token
|
131 |
+
user = get_user_by_verification_token(db, verification_token)
|
132 |
+
|
133 |
+
if not user:
|
134 |
+
raise HTTPException(status_code=400, detail="Invalid verification token")
|
135 |
+
|
136 |
+
if user.is_verified:
|
137 |
+
raise HTTPException(status_code=400, detail="Email already verified")
|
138 |
+
|
139 |
+
# Mark the email as verified
|
140 |
+
user.is_verified = True
|
141 |
+
user.email_verification_token = None # Optionally clear the verification token
|
142 |
+
db.commit()
|
143 |
+
return {"message": "Email verification successful"}
|
144 |
+
|
145 |
def get_user_by_verification_token(db: Session, verification_token: str):
|
146 |
return db.query(User).filter(User.email_verification_token == verification_token).first()
|
147 |
|