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
ea0d9f79
Commit
ea0d9f79
authored
Mar 21, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化用户登录
parent
ad7340ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
6 deletions
+17
-6
login_verification.py
app/api/users/login_verification.py
+6
-2
schemas.py
app/api/users/schemas.py
+9
-2
views.py
app/api/users/views.py
+2
-2
No files found.
app/api/users/login_verification.py
View file @
ea0d9f79
...
...
@@ -7,6 +7,7 @@ from core.config.env import env
from
libs.functions
import
md5
from
libs.img_code
import
session
from
models
import
users
as
users
from
app.api.role
import
crud
as
role_crud
def
get_user
(
db
,
username
:
str
):
...
...
@@ -51,13 +52,16 @@ def authenticate_user(db: Session, form_data: UserLoginForm):
# 如果获取为空,返回False
if
not
user_data
:
return
{
"result"
:
False
,
"msg"
:
"用户不存在"
}
if
not
user_data
.
role_id
:
return
{
"result"
:
False
,
"msg"
:
"用户没有权限,请先添加角色"
}
role_info
=
role_crud
.
get_id_to_authority
(
db
,
user_data
.
role_id
)
if
not
role_info
.
authority
:
return
{
"result"
:
False
,
"msg"
:
"用户无权限!请先添加权限"
}
# 如果密码不正确,也是返回False
md5_password
=
md5
(
form_data
.
password
)
if
md5_password
!=
user_data
.
hashed_password
:
return
{
"result"
:
False
,
"msg"
:
"密码错误"
}
# 验证码检查
print
(
form_data
.
verify
)
print
(
session
.
headers
)
# if form_data.verify.lower() != session.headers.get("verify").lower():
# return {"result": False, "msg": "验证码错误"}
if
user_data
.
google_key
:
...
...
app/api/users/schemas.py
View file @
ea0d9f79
from
pydantic
import
BaseModel
from
fastapi
import
HTTPException
from
pydantic
import
BaseModel
,
validator
from
typing
import
Optional
class
UserBase
(
BaseModel
):
username
:
str
@
validator
(
'username'
)
def
username_must_contain_space
(
cls
,
v
):
if
len
(
v
)
>
50
:
raise
HTTPException
(
status_code
=
500
,
detail
=
"用户名太长"
)
return
v
class
UserCreate
(
UserBase
):
remark
:
str
remark
:
Optional
[
str
]
=
""
role_id
:
int
...
...
app/api/users/views.py
View file @
ea0d9f79
...
...
@@ -34,7 +34,7 @@ def login(form_data: UserLoginForm, db: Session = Depends(get_db)):
if
form_data
.
verify
.
lower
()
!=
code
.
lower
():
return
HttpResultResponse
(
code
=
500
,
msg
=
"验证码错误"
)
if
not
user_info
.
get
(
"result"
):
return
HttpResultResponse
(
code
=
500
,
msg
=
user_info
.
get
(
"msg"
)
,
data
=
{}
)
return
HttpResultResponse
(
code
=
500
,
msg
=
user_info
.
get
(
"msg"
))
return
HttpResultResponse
(
msg
=
HttpMessage
.
LOGIN_SUCCESS
,
data
=
{
"google_key"
:
user_info
.
get
(
"google_key"
)})
...
...
@@ -79,7 +79,7 @@ def create_user(data: schemas.UserCreate, token=Depends(login_required), db: Ses
return
HttpResultResponse
(
code
=
400
,
msg
=
HttpMessage
.
USER_EXIST
)
res
=
crud
.
create_user
(
db
=
db
,
user
=
data
)
if
not
res
:
return
HttpResultResponse
(
code
=
500
,
msg
=
res
)
return
HttpResultResponse
(
code
=
500
,
msg
=
HttpMessage
.
LOSE
)
return
HttpResultResponse
(
data
=
res
.
id
)
...
...
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