randydev commited on
Commit
0eb771c
1 Parent(s): 2701f80

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -3
main.py CHANGED
@@ -49,7 +49,7 @@ from telegraph import Telegraph, upload_file
49
  from pathlib import Path
50
  from serpapi import GoogleSearch
51
 
52
- from fastapi import FastAPI, UploadFile, File, Response
53
  from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
54
  from fastapi import Depends, HTTPException, status
55
  from fastapi.openapi.utils import get_openapi
@@ -246,11 +246,13 @@ def get_profile_clone(user_id):
246
  def new_verify_otp(
247
  user_id,
248
  otp_code,
 
249
  auth_status
250
  ):
251
  update_doc = {
252
  "user_id": user_id,
253
  "otp_code": otp_code,
 
254
  "auth_status": auth_status,
255
  }
256
  collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
@@ -272,14 +274,16 @@ class OTPCallbackPayload(BaseModel):
272
  user_id: int
273
 
274
  @app.get("/api/get-verify", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
275
- def get_verify_otp(user_id: int):
276
  try:
 
277
  get_otp_code = get_stored_otp(user_id)
278
  if get_otp_code:
279
  return SuccessResponse(
280
  status="True",
281
  randydev={
282
  "otp_code": get_otp_code,
 
283
  "auth_status": "verified",
284
  }
285
  )
@@ -288,6 +292,7 @@ def get_verify_otp(user_id: int):
288
  status="False",
289
  randydev={
290
  "otp_code": None,
 
291
  "auth_status": "unverified",
292
  }
293
  )
@@ -298,12 +303,14 @@ def get_verify_otp(user_id: int):
298
  )
299
 
300
  @app.post("/api/verify", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
301
- def verify_otp(payload: OTPCallbackPayload):
302
  try:
 
303
  otp = generate_otp()
304
  new_verify_otp(
305
  payload.user_id,
306
  otp,
 
307
  auth_status="verified"
308
  )
309
  return SuccessResponse(
@@ -311,6 +318,7 @@ def verify_otp(payload: OTPCallbackPayload):
311
  randydev={
312
  "message": "successfully verified",
313
  "otp_code": otp,
 
314
  "auth_status": "verified",
315
  }
316
  )
@@ -320,6 +328,7 @@ def verify_otp(payload: OTPCallbackPayload):
320
  randydev={
321
  "message": "Failed unverified",
322
  "otp_code": None,
 
323
  "auth_status": "unverified",
324
  }
325
  )
 
49
  from pathlib import Path
50
  from serpapi import GoogleSearch
51
 
52
+ from fastapi import FastAPI, UploadFile, File, Response, Request
53
  from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
54
  from fastapi import Depends, HTTPException, status
55
  from fastapi.openapi.utils import get_openapi
 
246
  def new_verify_otp(
247
  user_id,
248
  otp_code,
249
+ ip_addres,
250
  auth_status
251
  ):
252
  update_doc = {
253
  "user_id": user_id,
254
  "otp_code": otp_code,
255
+ "ip_addres": ip_addres,
256
  "auth_status": auth_status,
257
  }
258
  collection.update_one({"user_id": user_id}, {"$set": update_doc}, upsert=True)
 
274
  user_id: int
275
 
276
  @app.get("/api/get-verify", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
277
+ def get_verify_otp(user_id: int, request: Request):
278
  try:
279
+ client_host = request.client.host
280
  get_otp_code = get_stored_otp(user_id)
281
  if get_otp_code:
282
  return SuccessResponse(
283
  status="True",
284
  randydev={
285
  "otp_code": get_otp_code,
286
+ "ip_addres": client_host,
287
  "auth_status": "verified",
288
  }
289
  )
 
292
  status="False",
293
  randydev={
294
  "otp_code": None,
295
+ "ip_addres": client_host,
296
  "auth_status": "unverified",
297
  }
298
  )
 
303
  )
304
 
305
  @app.post("/api/verify", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
306
+ def verify_otp(payload: OTPCallbackPayload, request: Request):
307
  try:
308
+ client_host = request.client.host
309
  otp = generate_otp()
310
  new_verify_otp(
311
  payload.user_id,
312
  otp,
313
+ ip_addres=client_host,
314
  auth_status="verified"
315
  )
316
  return SuccessResponse(
 
318
  randydev={
319
  "message": "successfully verified",
320
  "otp_code": otp,
321
+ "ip_addres": client_host,
322
  "auth_status": "verified",
323
  }
324
  )
 
328
  randydev={
329
  "message": "Failed unverified",
330
  "otp_code": None,
331
+ "ip_addres": client_host,
332
  "auth_status": "unverified",
333
  }
334
  )