Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
07007f09
authored
2024-09-30 11:01:33 +0800
by
冯轩
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
MOD:为了测试先恢复本地登录
1 parent
53a481dc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
30 deletions
src/apps/account/urls.py
src/apps/account/views.py
src/apps/account/urls.py
View file @
07007f0
...
...
@@ -3,7 +3,7 @@ from . import views
urlpatterns
=
[
#
path(r'login/', views.LoginView.as_view()),
path
(
r'login/'
,
views
.
LoginView
.
as_view
()),
path
(
r'iwalogin/'
,
views
.
IWALoginView
.
as_view
()),
path
(
r'iwaurl/'
,
views
.
IWAUrlView
.
as_view
()),
path
(
r'adminlogin/'
,
views
.
AdminLoginView
.
as_view
()),
...
...
src/apps/account/views.py
View file @
07007f0
...
...
@@ -28,35 +28,35 @@ client_id_base64 = base64.b64encode('{0}:{1}'.format(
conf
.
IWA_CLIENT_ID
,
conf
.
IWA_CLIENT_SECRET
)
.
encode
(
'utf-8'
))
.
decode
(
'utf-8'
)
#
class LoginView(ObtainJSONWebToken, GenericView):
#
def post(self, request, *args, **kwargs):
#
# 登录次数限制
#
remote_ip = request.META.get('HTTP_X_REAL_IP', '')
#
user_name = request.data.get('username', '')
#
times = rh.get_login_times(remote_ip)
#
if isinstance(times, str) and int(times) >= LOGIN_TIMES_LIMIT:
#
raise self.invalid_params(msg="重试次数限制")
#
res = super(LoginView, self).post(request, *args, **kwargs)
#
self.running_log.info('[users.login] username: {0}'.format(user_name))
#
if res.status_code == status.HTTP_400_BAD_REQUEST:
#
rh.set_login_times(remote_ip, LOGIN_TIMES_LIMIT_EXPIRES)
#
raise self.invalid_params(msg="用户名或密码错误")
#
serializer = self.get_serializer(data=request.data)
#
serializer.is_valid()
#
user = serializer.object.get('user')
#
user_role = UserRole.objects.filter(auth_user_id=user.id).first()
#
data = {
#
'user_id': user.id,
#
'user_name': user.username,
#
'token': res.data.get('token'),
#
'role': user_role.role if user_role else -1
#
}
#
rh.set_token(res.data.get('token')[-10:], user.username)
#
rh.set_token(res.data.get('token')[-11:], user_role.role if user_role else -1)
#
return response.ok(data=data)
class
LoginView
(
ObtainJSONWebToken
,
GenericView
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# 登录次数限制
remote_ip
=
request
.
META
.
get
(
'HTTP_X_REAL_IP'
,
''
)
user_name
=
request
.
data
.
get
(
'username'
,
''
)
times
=
rh
.
get_login_times
(
remote_ip
)
if
isinstance
(
times
,
str
)
and
int
(
times
)
>=
LOGIN_TIMES_LIMIT
:
raise
self
.
invalid_params
(
msg
=
"重试次数限制"
)
res
=
super
(
LoginView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
self
.
running_log
.
info
(
'[users.login] username: {0}'
.
format
(
user_name
))
if
res
.
status_code
==
status
.
HTTP_400_BAD_REQUEST
:
rh
.
set_login_times
(
remote_ip
,
LOGIN_TIMES_LIMIT_EXPIRES
)
raise
self
.
invalid_params
(
msg
=
"用户名或密码错误"
)
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
()
user
=
serializer
.
object
.
get
(
'user'
)
user_role
=
UserRole
.
objects
.
filter
(
auth_user_id
=
user
.
id
)
.
first
()
data
=
{
'user_id'
:
user
.
id
,
'user_name'
:
user
.
username
,
'token'
:
res
.
data
.
get
(
'token'
),
'role'
:
user_role
.
role
if
user_role
else
-
1
}
rh
.
set_token
(
res
.
data
.
get
(
'token'
)[
-
10
:],
user
.
username
)
rh
.
set_token
(
res
.
data
.
get
(
'token'
)[
-
11
:],
user_role
.
role
if
user_role
else
-
1
)
return
response
.
ok
(
data
=
data
)
class
IWALoginView
(
IWABaseView
,
GenericView
):
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment