randydev commited on
Commit
49e848d
1 Parent(s): d10dfb0

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +83 -0
main.py CHANGED
@@ -27,6 +27,7 @@ import shutil
27
  import random
28
  import tempfile
29
  import io
 
30
  import openai
31
  from io import BytesIO
32
  from datetime import datetime as dt
@@ -242,6 +243,88 @@ def get_profile_clone(user_id):
242
  else:
243
  return None
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  @app.post("/ryuzaki/profile-clone", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
246
  def profile_clone(
247
  item: ProfileClone,
 
27
  import random
28
  import tempfile
29
  import io
30
+ import string
31
  import openai
32
  from io import BytesIO
33
  from datetime import datetime as dt
 
243
  else:
244
  return None
245
 
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)
257
+
258
+ def get_verify_otp(user_id):
259
+ user = collection.find_one({"user_id": user_id})
260
+ if user:
261
+ otp_code = user.get("otp_code")
262
+ return otp_code
263
+ else:
264
+ return None
265
+
266
+ def generate_otp(length=6):
267
+ """Generate a random OTP"""
268
+ digits = string.digits
269
+ otp = ''.join(random.choice(digits) for i in range(length))
270
+ return otp
271
+
272
+ class OTPCallbackPayload(BaseModel):
273
+ user_id: str
274
+
275
+ @app.get("/api/verify", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
276
+ def get_verify_otp(user_id: int):
277
+ try:
278
+ get_otp_code = get_verify_otp(user_id)
279
+ if get_otp_code:
280
+ return SuccessResponse(
281
+ status="True",
282
+ randydev={
283
+ "otp_code": get_otp_code,
284
+ "auth_status": "verified",
285
+ }
286
+ )
287
+ else:
288
+ return SuccessResponse(
289
+ status="False",
290
+ randydev={
291
+ "otp_code": None,
292
+ "auth_status": "unverified",
293
+ }
294
+ )
295
+ except Exception:
296
+ return SuccessResponse(
297
+ status="False",
298
+ randydev={"message": "Failed unverified"}
299
+ )
300
+
301
+ @app.post("/api/verify", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
302
+ def verify_otp(payload: OTPCallbackPayload):
303
+ try:
304
+ otp = generate_otp()
305
+ new_verify_otp(
306
+ payload.user_id,
307
+ otp,
308
+ auth_status="verified"
309
+ )
310
+ return SuccessResponse(
311
+ status="True",
312
+ randydev={
313
+ "message": "successfully verified",
314
+ "otp_code": otp,
315
+ "auth_status": "verified",
316
+ }
317
+ )
318
+ except Exception:
319
+ return SuccessResponse(
320
+ status="False",
321
+ randydev={
322
+ "message": "Failed unverified",
323
+ "otp_code": None,
324
+ "auth_status": "unverified",
325
+ }
326
+ )
327
+
328
  @app.post("/ryuzaki/profile-clone", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
329
  def profile_clone(
330
  item: ProfileClone,