|
@@ -1,10 +1,8 @@
|
|
|
+from re import U
|
|
|
import uuid
|
|
|
import os
|
|
|
-import logging
|
|
|
-import dotenv
|
|
|
from typing import Optional
|
|
|
-from fastapi import FastAPI, Form
|
|
|
-from fastapi.params import Depends
|
|
|
+from fastapi import FastAPI, Form, Depends, HTTPException, status
|
|
|
from fastapi.templating import Jinja2Templates
|
|
|
from dotenv import load_dotenv
|
|
|
from os.path import join, dirname
|
|
@@ -13,18 +11,37 @@ from pydantic.networks import EmailStr
|
|
|
from starlette.responses import HTMLResponse
|
|
|
from sqlalchemy.orm import Session
|
|
|
from fastapi.encoders import jsonable_encoder
|
|
|
+from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
|
|
|
|
|
from sql.database import get_db_session
|
|
|
-from sql.crud import create_order, get_order, get_orders
|
|
|
+from sql.crud import create_order, get_user
|
|
|
from sql.models import order_info_linepay
|
|
|
from sql.schemas import order_info_linepay as orderSechmas
|
|
|
+from sql.schemas import User
|
|
|
+
|
|
|
+from jose import JWTError, jwt
|
|
|
+from passlib.context import CryptContext
|
|
|
+
|
|
|
+# TBD load_env
|
|
|
+SECRET_KEY = "df2f77bd544240801a048bd4293afd8eeb7fff3cb7050e42c791db4b83ebadcd"
|
|
|
+ALGORITHM = "HS256"
|
|
|
+ACCESS_TOKEN_EXPIRE_DAYS = 5
|
|
|
+pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
|
+oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
|
|
+
|
|
|
+
|
|
|
+def verify_password(plain_password, hashed_password):
|
|
|
+ return pwd_context.verify(plain_password, hashed_password)
|
|
|
+
|
|
|
+def get_password_hash(password):
|
|
|
+ return pwd_context.hash(password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# dotenv
|
|
|
-# dotenv_path = join(dirname(__file__),'./env/.env')
|
|
|
-dotenv_path = join(dirname(__file__),'./env/test.env') ## sandbox
|
|
|
+dotenv_path = join(dirname(__file__),'./env/.env')
|
|
|
+# dotenv_path = join(dirname(__file__),'./env/test.env') ## sandbox
|
|
|
load_dotenv(dotenv_path)
|
|
|
|
|
|
# logger (TBD)
|
|
@@ -36,18 +53,18 @@ templates = Jinja2Templates(directory="templates")
|
|
|
LINE_PAY_CHANNEL_ID = os.environ.get("LINE_PAY_CHANNEL_ID")
|
|
|
LINE_PAY_CHANNEL_SECRET = os.environ.get("LINE_PAY_CHANNEL_SECRET")
|
|
|
LINE_PAY_REQEST_BASE_URL = "https://{}".format(os.environ.get("HOST_NAME"))
|
|
|
-# line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=False)
|
|
|
-line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=True)
|
|
|
+line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=False)
|
|
|
+# line = LinePayApi(LINE_PAY_CHANNEL_ID, LINE_PAY_CHANNEL_SECRET, is_sandbox=True)
|
|
|
|
|
|
# CACHE
|
|
|
CACHE = {}
|
|
|
|
|
|
# Fastapi
|
|
|
app = FastAPI()
|
|
|
-
|
|
|
+oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
|
|
|
|
|
@app.get('/')
|
|
|
-def hello():
|
|
|
+def hello(token: str = Depends(oauth2_scheme)):
|
|
|
index = {}
|
|
|
index["product"] = "早鳥方案"
|
|
|
index["amount"] = 1200
|