Skip to content

Commit c5957bb

Browse files
Revert "First iteration of Cursor chat."
This reverts commit 5f1d4b7.
1 parent a2f1d8c commit c5957bb

File tree

2 files changed

+10
-43
lines changed

2 files changed

+10
-43
lines changed

routers/authentication.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ async def as_form(
118118

119119
class UserResetPassword(BaseModel):
120120
email: EmailStr
121-
token: Optional[str]
121+
token: str
122122
new_password: str
123123
confirm_new_password: str
124124

125+
# Use the factory with a different field name
125126
validate_password_strength = create_password_validator("new_password")
126127
validate_passwords_match = create_passwords_match_validator(
127128
"new_password", "confirm_new_password")
@@ -130,16 +131,12 @@ class UserResetPassword(BaseModel):
130131
async def as_form(
131132
cls,
132133
email: EmailStr = Form(...),
133-
token: str = Form(None),
134+
token: str = Form(...),
134135
new_password: str = Form(...),
135136
confirm_new_password: str = Form(...)
136137
):
137-
return cls(
138-
email=email,
139-
token=token,
140-
new_password=new_password,
141-
confirm_new_password=confirm_new_password
142-
)
138+
return cls(email=email, token=token,
139+
new_password=new_password, confirm_new_password=confirm_new_password)
143140

144141

145142
class UpdateEmail(BaseModel):
@@ -318,39 +315,8 @@ async def forgot_password(
318315
@router.post("/reset_password")
319316
async def reset_password(
320317
user: UserResetPassword = Depends(UserResetPassword.as_form),
321-
tokens: tuple[Optional[str], Optional[str]] = Depends(oauth2_scheme_cookie),
322318
session: Session = Depends(get_session)
323319
):
324-
access_token, _ = tokens
325-
326-
# Handle authenticated user
327-
if access_token:
328-
try:
329-
decoded_token = validate_token(access_token)
330-
if decoded_token and decoded_token.get("sub") == user.email:
331-
# User is authenticated and changing their own password
332-
db_user = session.exec(select(User).where(
333-
User.email == user.email)).first()
334-
if not db_user:
335-
raise HTTPException(status_code=404, detail="User not found")
336-
337-
# Update password
338-
if db_user.password:
339-
db_user.password.hashed_password = get_password_hash(user.new_password)
340-
else:
341-
db_user.password = UserPassword(
342-
hashed_password=get_password_hash(user.new_password)
343-
)
344-
session.commit()
345-
return RedirectResponse(url="/settings", status_code=303)
346-
347-
except Exception as e:
348-
logger.error(f"Error validating token: {e}")
349-
350-
# Handle unauthenticated user with reset token
351-
if not user.token:
352-
raise HTTPException(status_code=400, detail="Reset token required for unauthenticated password reset")
353-
354320
authorized_user, reset_token = get_user_from_reset_token(
355321
user.email, user.token, session)
356322

@@ -363,13 +329,16 @@ async def reset_password(
363329
user.new_password
364330
)
365331
else:
332+
logger.warning(
333+
"User password not found during password reset; creating new password for user")
366334
authorized_user.password = UserPassword(
367335
hashed_password=get_password_hash(user.new_password)
368336
)
369337

370338
reset_token.used = True
371339
session.commit()
372-
340+
session.refresh(authorized_user)
341+
373342
return RedirectResponse(url="/login", status_code=303)
374343

375344

templates/authentication/reset_password.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
<!-- Hidden Email Input -->
1111
<input type="hidden" name="email" value="{{ email }}" autocomplete="email">
1212

13-
<!-- Hidden Token Input (only if provided) -->
14-
{% if token %}
13+
<!-- Hidden Token Input -->
1514
<input type="hidden" name="token" value="{{ token }}">
16-
{% endif %}
1715

1816
<!-- New Password Input -->
1917
<div class="mb-3">

0 commit comments

Comments
 (0)