vip11017 commited on
Commit
19ae61b
·
1 Parent(s): 1c96f76

Added update name email and delete account endpoints

Browse files
app/routers/__pycache__/user.cpython-311.pyc CHANGED
Binary files a/app/routers/__pycache__/user.cpython-311.pyc and b/app/routers/__pycache__/user.cpython-311.pyc differ
 
app/routers/user.py CHANGED
@@ -6,6 +6,7 @@ import uuid
6
  from app.auth import hash_password, verify_password, create_access_token
7
  from app.config import Settings
8
  from app.models.user import *
 
9
 
10
  settings = Settings()
11
 
@@ -119,4 +120,49 @@ async def reset_pass(payload: ForgotPasswordResetPayload):
119
  hashed = hash_password(new_password)
120
  await users.update_one({"email": email}, {"$set": {"hashed_password": hashed}})
121
 
122
- return {"message": "Password reset successfully"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  from app.auth import hash_password, verify_password, create_access_token
7
  from app.config import Settings
8
  from app.models.user import *
9
+ from app.get_current_users import get_current_user
10
 
11
  settings = Settings()
12
 
 
120
  hashed = hash_password(new_password)
121
  await users.update_one({"email": email}, {"$set": {"hashed_password": hashed}})
122
 
123
+ return {"message": "Password reset successfully"}
124
+
125
+ @router.post("/update-name")
126
+ async def update_name(user_id: str, new_name: str, curr_user = Depends(get_current_user)):
127
+ if curr_user['_id'] != user_id:
128
+ raise HTTPException(status_code=403, detail="User ID Mismatch")
129
+
130
+ user = await users.find_one({"_id": user_id})
131
+ if not user:
132
+ raise HTTPException(status_code=404, detail="User not Found")
133
+
134
+ result = await users.update_one({"_id": user_id}, {"$set": {"full_name": new_name}})
135
+
136
+ if result.modified_count == 0:
137
+ raise HTTPException(status_code=400, detail="Name not updated")
138
+
139
+ return {"message": "Name updated successfully", "new_name": new_name}
140
+
141
+ @router.post("/update-email")
142
+ async def update_email(user_id: str, new_email: str, curr_user = Depends(get_current_user)):
143
+ if curr_user['_id'] != user_id:
144
+ raise HTTPException(status_code=403, detail="User ID Mismatch")
145
+
146
+ user = await users.find_one({"_id": user_id})
147
+ if not user:
148
+ raise HTTPException(status_code=404, detail="User not Found")
149
+
150
+ result = await users.update_one({"_id": user_id}, {"$set": {"email": new_email}})
151
+
152
+ if result.modified_count == 0:
153
+ raise HTTPException(status_code=400, detail="Email not updated")
154
+
155
+ return {"message": "Email updated successfully", "new_email": new_email}
156
+
157
+ @router.delete("/delete-account")
158
+ async def delete_account(user_id: str, curr_user = Depends(get_current_user)):
159
+ if curr_user['_id'] != user_id:
160
+ raise HTTPException(status_code=403, detail="User ID Mismatch")
161
+
162
+ user = await users.find_one({"_id": user_id})
163
+ if not user:
164
+ raise HTTPException(status_code=404, detail="User not Found")
165
+
166
+ result = await users.delete_one({"_id": user_id})
167
+
168
+ return {"message": "Succesfully deleted account"}