Pārlūkot izejas kodu

verify by email

ming 3 gadi atpakaļ
vecāks
revīzija
a4ce3d67a7
1 mainītis faili ar 19 papildinājumiem un 0 dzēšanām
  1. 19 0
      api/main.py

+ 19 - 0
api/main.py

@@ -209,6 +209,11 @@ async def register_old(request: Request):
     user_obj = first(db.query('SELECT * FROM users where username ="'+str(user.username)+'"'))
     if user_obj == None:
         user_register(user)
+        user_obj = first(db.query('SELECT * FROM users where username ="'+str(request.username)+'"'))
+        veri_table = db['register_veri_code']
+        code = str(time.time()).replace('.','')
+        veri_table.insert({'code':code,'user_id':user_obj['id']})
+        mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, user_obj['email'])
         return '註冊成功! 請回到上頁登入帳號'
         #return templates.TemplateResponse("make_video.html", {"request": request, "success": True},status_code=status.HTTP_302_FOUND)
         #return templates.TemplateResponse("login.html", {'request': request,"success": True}, status_code=status.HTTP_302_FOUND)
@@ -219,8 +224,14 @@ async def register_old(request: Request):
 async def register(request: models.register_req):
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     user_obj = first(db.query('SELECT * FROM users where username ="'+str(request.username)+'"'))
+    
     if user_obj == None:
         if user_register(request):
+            user_obj = first(db.query('SELECT * FROM users where username ="'+str(request.username)+'"'))
+            veri_table = db['register_veri_code']
+            code = str(time.time()).replace('.','')
+            veri_table.insert({'code':code,'user_id':user_obj['id']})
+            mailer.register_verify('請至點擊網址驗證 : https://www.choozmo.com:8887/verify_email?code='+code, user_obj['email'])
             return {'msg':'ok'}
         else:
             return {'msg': '內部錯誤'}
@@ -234,6 +245,14 @@ def logout(request: Request, Authorize: AuthJWT = Depends()):
     Authorize.unset_jwt_cookies()
     return {"msg": "ok"}
 
+@app.get('/verify_email')
+async def logout(code):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
+    veri_obj = first(db.query('SELECT * FROM register_veri_code where code ="'+str(code)+'"'))
+    if veri_obj != None:
+        db['register_veri_code'].delete(code=code)
+    return {"msg": "ok"}
+
 @app.get("/gen_avatar")
 async def avatar():
     return FileResponse('static/gen_avatar.html')