123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- from enum import Enum
- import time
- from datetime import datetime
- from typing import Optional
- from pydantic import BaseModel
- from fastapi import FastAPI, Query, UploadFile, File
- import dataset,json
- from fastapi import FastAPI
- from fastapi.middleware.cors import CORSMiddleware
- app = FastAPI()
- origins = [
- "https://hhh.com.tw"
- "http://172.105.205.52",
- "http://172.105.205.52:8001",
- "http://172.104.93.163",
- ]
- app.add_middleware(
- CORSMiddleware,
- # allow_origins=origins,
- allow_origins=["*"],
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
- class client_info(BaseModel):
- name:str
- organization:str
- position:str
- phone:str
- email:str
- cert_last5:str
- where_learn:str
- why_sign:str
-
- @app.post("/add_client_info")
- async def add_client_info(ci:client_info):
-
-
- statement = 'SELECT * FROM client_info WHERE email="'+ci.email+'"'
- email_cnt = 0
- for row in db.query(statement):
- email_cnt = email_cnt + 1
-
- statement = 'SELECT * FROM client_info WHERE phone="'+ci.phone+'"'
- phone_cnt = 0
- for row in db.query(statement):
- phone_cnt = phone_cnt + 1
-
- return_code = 0
- #return code 0=good, 1=email duplication, 2=phone duplication, 3= both duplicate
- if email_cnt>0 and phone_cnt==0:
- return_code = 1
- if email_cnt==0 and phone_cnt>0:
- return_code = 2
- if email_cnt>0 and phone_cnt>0:
- return_code = 3
-
- if return_code ==0 :
- request_table = db['client_info']
- time_stamp = datetime.fromtimestamp(time.time())
- time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
-
- pk = request_table.insert({'name':ci.name,'organization':ci.organization,'position':ci.position,'phone':ci.phone,'email':ci.email
- ,'cert_last5':ci.cert_last5,'where_learn':ci.where_learn,'why_sign':ci.why_sign,'time_stamp':time_stamp})
-
- return return_code
- else :
- return return_code
- return return_code
-
-
-
-
-
|