# @Time : 2020/12/20 10:40 # @Author : Xiaoyunlong from fastapi import Header, Request from datetime import datetime, timedelta from typing import Any, Union, Optional from jose import jwt # from passlib.context import CryptContext from app.setting import main_init from fastapi.responses import JSONResponse from fastapi import Depends, FastAPI, HTTPException from starlette import status from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm import time oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/user/login") config = main_init.Init_Config('81.69.29.78', 'cdbd', 'root', '111') # pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") ALGORITHM = "HS256" def create_access_token(subject: Union[str, Any], expires_delta: timedelta = None) -> str: if expires_delta: expire = datetime.utcnow() + expires_delta else: expire = datetime.utcnow() + timedelta( minutes=config.ACCESS_TOKEN_EXPIRE_MINUTES) to_encode = {"exp": expire, "username": str(subject)} encoded_jwt = jwt.encode(to_encode, config.SECRET_KEY, algorithm=config.JWT_ALGORITHM)
# -*- coding: utf-8 -*- # @Time : 2020/12/20 10:40 # @Author : Xiaoyunlong from app.setting import main_init from database.db_con import Db_Connection import time, json from fastapi import Header import pandas as pd config = main_init.Init_Config('192.168.4.131', 'app.exam', 'root', '123456!@#') config_user = main_init.Init_Config('192.168.4.131', 'app.user', 'root', '123456!@#') mysql_db = Db_Connection(config.msqusername, config.msqpassword, config.msqlserver, config.msqdb, config.msqcoding) mysql_db_user = Db_Connection(config_user.msqusername, config_user.msqpassword, config_user.msqlserver, config_user.msqdb, config_user.msqcoding) class CRUDCategory(object): def add_test(self, parames: dict) -> bool: class_type = '1' itime = int(time.time()) utime = 0 dtime = 0 uadmin_id = 0 datastatus = 1 client = parames['user-agent'].headers['user-agent'] try: params = [ class_type, parames['class_name'], itime, utime, dtime,