Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
financial-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xianyang
financial-system
Commits
44328aeb
Commit
44328aeb
authored
Feb 09, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
dd27929f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
25 deletions
+6
-25
views.py
app/api/users/views.py
+3
-20
img_code.py
libs/img_code.py
+2
-4
main.py
main.py
+1
-1
DejaVuSans-BoldOblique.ttf
static/DejaVuSans-BoldOblique.ttf
+0
-0
No files found.
app/api/users/views.py
View file @
44328aeb
from
typing
import
List
from
fastapi
import
Depends
,
APIRouter
from
datetime
import
datetime
,
timedelta
from
datetime
import
timedelta
from
sqlalchemy.orm
import
Session
from
app
import
get_db
from
app.api.users
import
crud
,
schemas
from
app.api.users.login_verification
import
authenticate_user
,
create_access_token
,
get_user
from
app.api.users.schemas
import
UserLoginForm
,
GoogleCode
,
GoogleLogin
from
core.storage.db
import
SessionLocal
from
libs.google_code
import
get_qrcode
,
google_verify_result
from
libs.img_code
import
imageCode
from
libs.result_format
import
HttpResultResponse
,
HttpMessage
...
...
@@ -13,32 +13,15 @@ from libs.result_format import HttpResultResponse, HttpMessage
router
=
APIRouter
()
def
get_db
():
db
=
SessionLocal
()
try
:
yield
db
finally
:
db
.
close
()
# @router.post("/", response_model=schemas.User)
# def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):
# db_user = crud.get_user_by_email(db, email=user.email)
# if db_user:
# raise HTTPException(status_code=400, detail="Email already registered")
# return crud.create_user(db=db, user=user)
@
router
.
get
(
"/"
,
response_model
=
List
[
schemas
.
User
])
def
read_users
(
skip
:
int
=
0
,
limit
:
int
=
100
,
db
:
Session
=
Depends
(
get_db
)):
users
=
crud
.
get_users
(
db
,
skip
=
skip
,
limit
=
limit
)
return
users
@
router
.
get
(
"/imgCode"
)
def
imgCode
():
return
imageCode
()
.
getImgCode
(
)
return
HttpResultResponse
(
data
=
imageCode
()
.
getImgCode
()
)
@
router
.
post
(
"/login"
)
...
...
libs/img_code.py
View file @
44328aeb
...
...
@@ -2,10 +2,8 @@ import base64
import
os.path
import
random
import
string
import
requests
from
PIL
import
Image
,
ImageFont
,
ImageDraw
from
six
import
BytesIO
session
=
requests
.
session
()
...
...
@@ -41,7 +39,7 @@ class imageCode():
# 新图片对象
im
=
Image
.
new
(
'RGB'
,
(
width
,
height
),
'white'
)
# 字体
font_file
=
os
.
path
.
join
(
os
.
getcwd
(),
"
libs
"
,
"DejaVuSans-BoldOblique.ttf"
)
font_file
=
os
.
path
.
join
(
os
.
getcwd
(),
"
static
"
,
"DejaVuSans-BoldOblique.ttf"
)
font
=
ImageFont
.
truetype
(
font_file
,
40
)
# draw对象
draw
=
ImageDraw
.
Draw
(
im
)
...
...
@@ -62,4 +60,4 @@ class imageCode():
img
=
b
"data:image/png;base64,"
+
base64
.
b64encode
(
buf_str
)
session
.
headers
[
'verify'
]
=
code
print
(
code
)
return
img
return
img
.
decode
(
'utf-8'
)
main.py
View file @
44328aeb
...
...
@@ -19,4 +19,4 @@ app.include_router(api_router, prefix="/api") # 路由
if
__name__
==
'__main__'
:
uvicorn
.
run
(
app
=
app
,
host
=
"
127.0.0.1
"
,
port
=
8001
)
uvicorn
.
run
(
app
=
app
,
host
=
"
0.0.0.0
"
,
port
=
8001
)
static/DejaVuSans-BoldOblique.ttf
0 → 100644
View file @
44328aeb
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment