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
02959d7c
Commit
02959d7c
authored
Feb 08, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户优化,公共方法封装
parent
adf27ab2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
9 deletions
+16
-9
crud.py
app/api/users/crud.py
+3
-2
schemas.py
app/api/users/schemas.py
+0
-1
functions.py
libs/functions.py
+6
-0
main.py
main.py
+3
-3
users.py
models/users.py
+4
-3
No files found.
app/api/users/crud.py
View file @
02959d7c
...
...
@@ -3,7 +3,7 @@ from datetime import datetime
from
sqlalchemy.orm
import
Session
from
app.api.users
import
schemas
from
libs.functions
import
md5
from
libs.functions
import
md5
,
uuid
from
models
import
users
as
models
...
...
@@ -21,7 +21,8 @@ def get_users(db: Session, skip: int = 0, limit: int = 100):
def
create_user
(
db
:
Session
,
user
:
schemas
.
UserCreate
):
db_user
=
models
.
User
(
username
=
user
.
username
,
description
=
user
.
description
,
unique
=
user
.
unique
,
config_key
=
user
.
config_key
,
hashed_password
=
md5
(
user
.
password
),
create_time
=
datetime
.
now
())
config_key
=
user
.
config_key
,
uuid
=
uuid
(),
hashed_password
=
md5
(
"123456"
),
create_time
=
datetime
.
now
())
db
.
add
(
db_user
)
db
.
commit
()
db
.
refresh
(
db_user
)
...
...
app/api/users/schemas.py
View file @
02959d7c
...
...
@@ -6,7 +6,6 @@ class UserBase(BaseModel):
class
UserCreate
(
UserBase
):
password
:
str
unique
:
str
description
:
str
config_key
:
str
...
...
libs/functions.py
View file @
02959d7c
import
hashlib
import
uuid
as
u
def
md5
(
s
):
...
...
@@ -6,3 +7,8 @@ def md5(s):
sign_str
=
hashlib
.
md5
()
sign_str
.
update
(
s
.
encode
(
'utf-8'
))
return
sign_str
.
hexdigest
()
def
uuid
():
"""生成uuid"""
return
str
(
u
.
uuid4
())
main.py
View file @
02959d7c
...
...
@@ -10,7 +10,7 @@ from core.storage.db import Base, engine
app
=
FastAPI
()
origins
=
[
'*'
]
# 可以设置为'*',即为所有。
# 设置跨域传参
# 设置跨域传参
app
.
add_middleware
(
CORSMiddleware
,
allow_origins
=
origins
,
# 设置允许的origins来源
...
...
@@ -18,8 +18,8 @@ app.add_middleware(
allow_methods
=
[
'*'
],
# 设置允许跨域的http方法,比如 get、post、put等。
allow_headers
=
[
'*'
])
# 允许跨域的headers,可以用来鉴别来源等作用。
app
.
include_router
(
api_router
,
prefix
=
"/api"
)
Base
.
metadata
.
create_all
(
bind
=
engine
)
app
.
include_router
(
api_router
,
prefix
=
"/api"
)
# 路由
Base
.
metadata
.
create_all
(
bind
=
engine
)
# 映射模型类
if
__name__
==
'__main__'
:
uvicorn
.
run
(
app
=
app
,
host
=
"127.0.0.1"
,
port
=
8001
)
models/users.py
View file @
02959d7c
...
...
@@ -16,8 +16,8 @@ class User(Base):
uuid
=
Column
(
String
(
50
))
authority
=
Column
(
Integer
)
remaining_sum
=
Column
(
Float
)
entry_account
=
ARRAY
(
Column
(
Integer
))
out_account
=
ARRAY
(
Column
(
Integer
))
entry_account
=
Column
(
String
(
255
))
out_account
=
Column
(
String
(
255
))
create_time
=
Column
(
DateTime
)
update_time
=
Column
(
DateTime
)
...
...
@@ -26,6 +26,7 @@ class Authority(Base):
__tablename__
=
"authority"
id
=
Column
(
Integer
,
primary_key
=
True
,
index
=
True
)
name
=
Column
(
String
(
50
),
unique
=
True
,
index
=
True
)
name
=
Column
(
String
(
50
),
index
=
True
)
up_one_level
=
Column
(
Integer
,
index
=
True
)
create_time
=
Column
(
DateTime
)
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