1.优化登录方式
This commit is contained in:
parent
24ffac825c
commit
5501e28b62
@ -15,6 +15,7 @@ from api import deps
|
|||||||
from core import security
|
from core import security
|
||||||
from core.config import settings
|
from core.config import settings
|
||||||
from core.security import get_password_hash
|
from core.security import get_password_hash
|
||||||
|
from schemas import ExtendendOAuth
|
||||||
from utils.dingding import *
|
from utils.dingding import *
|
||||||
from utils.jianli import get_resume
|
from utils.jianli import get_resume
|
||||||
from utils.func import get_uid
|
from utils.func import get_uid
|
||||||
@ -814,6 +815,7 @@ async def get_operate_log(
|
|||||||
@router.get("/get_dding_user")
|
@router.get("/get_dding_user")
|
||||||
async def get_dding_user(
|
async def get_dding_user(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
current_user: schemas.User = Depends(deps.get_current_user)
|
||||||
) -> schemas.Msg:
|
) -> schemas.Msg:
|
||||||
"""获取钉钉的用户id"""
|
"""获取钉钉的用户id"""
|
||||||
data = get_redis_alluid()
|
data = get_redis_alluid()
|
||||||
@ -921,6 +923,7 @@ async def update_mode(
|
|||||||
async def name(
|
async def name(
|
||||||
request: Request,
|
request: Request,
|
||||||
db: AsyncIOMotorDatabase = Depends(get_database),
|
db: AsyncIOMotorDatabase = Depends(get_database),
|
||||||
|
current_user: schemas.User = Depends(deps.get_current_user)
|
||||||
) -> schemas.Msg:
|
) -> schemas.Msg:
|
||||||
"""获取所有用户角色"""
|
"""获取所有用户角色"""
|
||||||
res = await crud.user.get_all_users(db, {})
|
res = await crud.user.get_all_users(db, {})
|
||||||
@ -1173,14 +1176,14 @@ async def up_hint(
|
|||||||
|
|
||||||
@router.post("/login")
|
@router.post("/login")
|
||||||
async def login(
|
async def login(
|
||||||
data_in: schemas.Login,
|
#data_in: schemas.Login,
|
||||||
data: OAuth2PasswordRequestForm = Depends(),
|
data: ExtendendOAuth = Depends(),
|
||||||
db: AsyncIOMotorDatabase = Depends(get_database)
|
db: AsyncIOMotorDatabase = Depends(get_database)
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""
|
"""
|
||||||
OAuth2兼容令牌登录,获取将来令牌的访问令牌
|
OAuth2兼容令牌登录,获取将来令牌的访问令牌
|
||||||
"""
|
"""
|
||||||
if data_in.unionid == '':
|
if data.unionid == None:
|
||||||
# 账号密码登录
|
# 账号密码登录
|
||||||
user = await crud.user.authenticate(db,
|
user = await crud.user.authenticate(db,
|
||||||
name=data.username, password=data.password
|
name=data.username, password=data.password
|
||||||
@ -1193,7 +1196,7 @@ async def login(
|
|||||||
await crud.user.update_login_time(db, data.username)
|
await crud.user.update_login_time(db, data.username)
|
||||||
else:
|
else:
|
||||||
# 钉钉扫码登录
|
# 钉钉扫码登录
|
||||||
user_id = Unionid(data_in.unionid)
|
user_id = Unionid(data.unionid)
|
||||||
user_list = get_alluid_list()
|
user_list = get_alluid_list()
|
||||||
if user_id not in user_list:
|
if user_id not in user_list:
|
||||||
return schemas.Msg(code=-1, msg='密码或用户名错误')
|
return schemas.Msg(code=-1, msg='密码或用户名错误')
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Union, Dict
|
from typing import List, Union, Dict
|
||||||
|
from fastapi.param_functions import Form
|
||||||
|
from fastapi.security import OAuth2PasswordRequestForm
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -122,3 +124,16 @@ class Ins_section(BaseModel):
|
|||||||
|
|
||||||
class Filenames(BaseModel):
|
class Filenames(BaseModel):
|
||||||
filenames: str
|
filenames: str
|
||||||
|
|
||||||
|
|
||||||
|
class ExtendendOAuth(OAuth2PasswordRequestForm):
|
||||||
|
def __init__(self, grant_type: str = Form(None, regex="password"),
|
||||||
|
username: str = Form(...),
|
||||||
|
password: str = Form(...),
|
||||||
|
scope: str = Form(""),
|
||||||
|
client_id: Optional[str] = Form(None),
|
||||||
|
client_secret: Optional[str] = Form(None),
|
||||||
|
unionid: str = Form(None)):
|
||||||
|
super().__init__(grant_type, username, password, scope, client_id, client_secret)
|
||||||
|
self.unionid = unionid # 通过钉钉扫码获取的unionid
|
||||||
|
# unionid :str # 通过钉钉扫码获取的unionid
|
||||||
|
Loading…
Reference in New Issue
Block a user