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
a8dad649
authored
2023-07-20 16:55:19 +0800
by
冯轩
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'feature/CHINARPA-3528'
2 parents
f4ea862e
c1a76eef
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
0 deletions
src/apps/account/admin.py
src/apps/account/apps.py
src/apps/account/models.py
src/apps/account/views.py
src/apps/doc/models.py
src/apps/account/admin.py
View file @
a8dad64
...
...
@@ -18,6 +18,7 @@ from django.utils.translation import gettext, gettext_lazy as _
from
django.views.decorators.csrf
import
csrf_protect
from
django.views.decorators.debug
import
sensitive_post_parameters
from
apps.myadmin.admin
import
admin_site
from
apps.account.models
import
UserRole
csrf_protect_m
=
method_decorator
(
csrf_protect
)
sensitive_post_parameters_m
=
method_decorator
(
sensitive_post_parameters
())
...
...
@@ -203,6 +204,11 @@ class UserAdmin(admin.ModelAdmin):
request
.
POST
[
'_continue'
]
=
1
return
super
()
.
response_add
(
request
,
obj
,
post_url_continue
)
# Register your models here.
class
UserRoleAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'id'
,
'auth_user_id'
,
'role'
)
admin_site
.
register
(
Group
,
GroupAdmin
)
admin_site
.
register
(
User
,
UserAdmin
)
admin_site
.
register
(
UserRole
,
UserRoleAdmin
)
...
...
src/apps/account/apps.py
View file @
a8dad64
...
...
@@ -3,3 +3,4 @@ from django.apps import AppConfig
class
AccountConfig
(
AppConfig
):
name
=
'apps.account'
verbose_name
=
'权限'
...
...
src/apps/account/models.py
View file @
a8dad64
from
django.db
import
models
# Create your models here.
class
UserRole
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
auth_user_id
=
models
.
SmallIntegerField
(
null
=
False
,
default
=
0
,
verbose_name
=
"auth_user_id"
)
role
=
models
.
SmallIntegerField
(
null
=
False
,
default
=
0
,
verbose_name
=
"role"
)
menu_list
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"menu_list"
,
blank
=
True
)
class
Meta
:
managed
=
False
db_table
=
'user_role'
verbose_name
=
'用户权限管理'
verbose_name_plural
=
verbose_name
\ No newline at end of file
...
...
src/apps/account/views.py
View file @
a8dad64
...
...
@@ -9,6 +9,7 @@ from settings import conf
from
django.urls
import
reverse
from
django.http
import
HttpResponseRedirect
from
django.contrib.auth
import
login
as
auth_login
from
apps.account.models
import
UserRole
# from django.conf import settings
# from django.shortcuts import resolve_url, redirect
...
...
@@ -46,10 +47,12 @@ class LoginView(ObtainJSONWebToken, GenericView):
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
)
return
response
.
ok
(
data
=
data
)
...
...
@@ -83,6 +86,8 @@ class IWALoginView(IWABaseView, GenericView):
if
is_valid
:
rh
.
set_token
(
data
.
get
(
'token'
)[
-
10
:],
data
.
get
(
'user_name'
))
user_role
=
UserRole
.
objects
.
filter
(
auth_user_id
=
data
.
get
(
'user_id'
))
.
first
()
data
[
'role'
]
=
user_role
.
role
if
user_role
else
-
1
return
response
.
ok
(
data
=
data
)
else
:
self
.
no_permission
(
data
)
...
...
src/apps/doc/models.py
View file @
a8dad64
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