Merge branch 'feature/CHINARPA-3528'
Showing
5 changed files
with
24 additions
and
1 deletions
| ... | @@ -18,6 +18,7 @@ from django.utils.translation import gettext, gettext_lazy as _ | ... | @@ -18,6 +18,7 @@ from django.utils.translation import gettext, gettext_lazy as _ |
| 18 | from django.views.decorators.csrf import csrf_protect | 18 | from django.views.decorators.csrf import csrf_protect |
| 19 | from django.views.decorators.debug import sensitive_post_parameters | 19 | from django.views.decorators.debug import sensitive_post_parameters |
| 20 | from apps.myadmin.admin import admin_site | 20 | from apps.myadmin.admin import admin_site |
| 21 | from apps.account.models import UserRole | ||
| 21 | 22 | ||
| 22 | csrf_protect_m = method_decorator(csrf_protect) | 23 | csrf_protect_m = method_decorator(csrf_protect) |
| 23 | sensitive_post_parameters_m = method_decorator(sensitive_post_parameters()) | 24 | sensitive_post_parameters_m = method_decorator(sensitive_post_parameters()) |
| ... | @@ -203,6 +204,11 @@ class UserAdmin(admin.ModelAdmin): | ... | @@ -203,6 +204,11 @@ class UserAdmin(admin.ModelAdmin): |
| 203 | request.POST['_continue'] = 1 | 204 | request.POST['_continue'] = 1 |
| 204 | return super().response_add(request, obj, post_url_continue) | 205 | return super().response_add(request, obj, post_url_continue) |
| 205 | 206 | ||
| 207 | # Register your models here. | ||
| 208 | class UserRoleAdmin(admin.ModelAdmin): | ||
| 209 | list_display = ('id', 'auth_user_id', 'role') | ||
| 210 | |||
| 206 | 211 | ||
| 207 | admin_site.register(Group, GroupAdmin) | 212 | admin_site.register(Group, GroupAdmin) |
| 208 | admin_site.register(User, UserAdmin) | 213 | admin_site.register(User, UserAdmin) |
| 214 | admin_site.register(UserRole, UserRoleAdmin) | ... | ... |
| 1 | from django.db import models | 1 | from django.db import models |
| 2 | 2 | ||
| 3 | # Create your models here. | 3 | # Create your models here. |
| 4 | class UserRole(models.Model): | ||
| 5 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
| 6 | auth_user_id = models.SmallIntegerField(null=False, default=0, verbose_name="auth_user_id") | ||
| 7 | role = models.SmallIntegerField(null=False, default=0, verbose_name="role") | ||
| 8 | menu_list = models.CharField(max_length=64, verbose_name="menu_list", blank=True) | ||
| 9 | |||
| 10 | class Meta: | ||
| 11 | managed = False | ||
| 12 | db_table = 'user_role' | ||
| 13 | verbose_name = '用户权限管理' | ||
| 14 | verbose_name_plural = verbose_name | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -9,6 +9,7 @@ from settings import conf | ... | @@ -9,6 +9,7 @@ from settings import conf |
| 9 | from django.urls import reverse | 9 | from django.urls import reverse |
| 10 | from django.http import HttpResponseRedirect | 10 | from django.http import HttpResponseRedirect |
| 11 | from django.contrib.auth import login as auth_login | 11 | from django.contrib.auth import login as auth_login |
| 12 | from apps.account.models import UserRole | ||
| 12 | # from django.conf import settings | 13 | # from django.conf import settings |
| 13 | # from django.shortcuts import resolve_url, redirect | 14 | # from django.shortcuts import resolve_url, redirect |
| 14 | 15 | ||
| ... | @@ -46,10 +47,12 @@ class LoginView(ObtainJSONWebToken, GenericView): | ... | @@ -46,10 +47,12 @@ class LoginView(ObtainJSONWebToken, GenericView): |
| 46 | serializer = self.get_serializer(data=request.data) | 47 | serializer = self.get_serializer(data=request.data) |
| 47 | serializer.is_valid() | 48 | serializer.is_valid() |
| 48 | user = serializer.object.get('user') | 49 | user = serializer.object.get('user') |
| 50 | user_role = UserRole.objects.filter(auth_user_id=user.id).first() | ||
| 49 | data = { | 51 | data = { |
| 50 | 'user_id': user.id, | 52 | 'user_id': user.id, |
| 51 | 'user_name': user.username, | 53 | 'user_name': user.username, |
| 52 | 'token': res.data.get('token'), | 54 | 'token': res.data.get('token'), |
| 55 | 'role': user_role.role if user_role else -1 | ||
| 53 | } | 56 | } |
| 54 | rh.set_token(res.data.get('token')[-10:], user.username) | 57 | rh.set_token(res.data.get('token')[-10:], user.username) |
| 55 | return response.ok(data=data) | 58 | return response.ok(data=data) |
| ... | @@ -83,6 +86,8 @@ class IWALoginView(IWABaseView, GenericView): | ... | @@ -83,6 +86,8 @@ class IWALoginView(IWABaseView, GenericView): |
| 83 | 86 | ||
| 84 | if is_valid: | 87 | if is_valid: |
| 85 | rh.set_token(data.get('token')[-10:], data.get('user_name')) | 88 | rh.set_token(data.get('token')[-10:], data.get('user_name')) |
| 89 | user_role = UserRole.objects.filter(auth_user_id=data.get('user_id')).first() | ||
| 90 | data['role'] = user_role.role if user_role else -1 | ||
| 86 | return response.ok(data=data) | 91 | return response.ok(data=data) |
| 87 | else: | 92 | else: |
| 88 | self.no_permission(data) | 93 | self.no_permission(data) | ... | ... |
| ... | @@ -1102,4 +1102,4 @@ class HILCmsStatusInfo(models.Model): | ... | @@ -1102,4 +1102,4 @@ class HILCmsStatusInfo(models.Model): |
| 1102 | 1102 | ||
| 1103 | class Meta: | 1103 | class Meta: |
| 1104 | managed = False | 1104 | managed = False |
| 1105 | db_table = 'hil_cms_status_info' | 1105 | db_table = 'hil_cms_status_info' |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment