login user

This commit is contained in:
2023-11-04 15:12:27 +09:00
parent f60f97380f
commit 617b060869
8 changed files with 141 additions and 136 deletions

View File

@@ -3,7 +3,7 @@ from fastapi import Depends, HTTPException, status
from jwt import PyJWTError
from app.db import models, schemas, session
from app.db.crud import get_user_by_email, create_user
from app.db.crud import get_user_by_email, create_user,get_user
from app.core import security
@@ -19,14 +19,14 @@ async def get_current_user(
payload = jwt.decode(
token, security.SECRET_KEY, algorithms=[security.ALGORITHM]
)
email: str = payload.get("sub")
if email is None:
id: int = payload.get("sub")
if id is None:
raise credentials_exception
permissions: str = payload.get("permissions")
token_data = schemas.TokenData(email=email, permissions=permissions)
token_data = schemas.TokenData(id = id, permissions=permissions)
except PyJWTError:
raise credentials_exception
user = get_user_by_email(db, token_data.email)
user = get_user(db, token_data.id)
if user is None:
raise credentials_exception
return user

View File

@@ -1,18 +1,25 @@
import os
import base64
PROJECT_NAME = "KintoneAppBuilder"
SQLALCHEMY_DATABASE_URI = "postgres://maxz64:m@xz1205@alicornkintone.postgres.database.azure.com/postgres"
BASE_URL = "https://mfu07rkgnb7c.cybozu.com"
API_V1_STR = "/k/v1"
API_V1_AUTH_KEY = "X-Cybozu-Authorization"
API_V1_AUTH_VALUE = "TVhaOm1heHoxMjA1"
KINTONE_USER = "MXZ"
KINTONE_FIELD_TYPE=["GROUP","GROUP_SELECT","CHECK_BOX","SUBTABLE","DROP_DOWN","USER_SELECT","RADIO_BUTTON","RICH_TEXT","LINK","REFERENCE_TABLE","CALC","TIME","NUMBER","ORGANIZATION_SELECT","FILE","DATETIME","DATE","MULTI_SELECT","SINGLE_LINE_TEXT","MULTI_LINE_TEXT"]
class KINTONE_ENV:
BASE_URL = ""
API_V1_AUTH_VALUE = ""
KINTONE_USER = ""
def __init__(self,domain) -> None:
self.BASE_URL = domain.url
self.KINTONE_USER = domain.kintoneuser
self.API_V1_AUTH_VALUE = base64.b64encode(bytes(f"{domain.kintoneuser}:{domain.kintonepwd}","utf-8"))