修复BUG(用户管理): 个人修改密码bug,UserProfile模型添加数据创建人
parent
85b1f74895
commit
f54d20d1e6
|
@ -52,7 +52,7 @@ class ApiLoggingMiddleware(MiddlewareMixin):
|
||||||
user = get_request_user(request)
|
user = get_request_user(request)
|
||||||
info = {
|
info = {
|
||||||
'request_ip': getattr(request, 'request_ip', 'unknown'),
|
'request_ip': getattr(request, 'request_ip', 'unknown'),
|
||||||
'creator': user if not isinstance(user, AnonymousUser) else '',
|
'creator': user if not isinstance(user, AnonymousUser) else None,
|
||||||
'dept_belong_id': getattr(request.user, 'dept_id', None),
|
'dept_belong_id': getattr(request.user, 'dept_id', None),
|
||||||
'request_method': request.method,
|
'request_method': request.method,
|
||||||
'request_path': request.request_path,
|
'request_path': request.request_path,
|
||||||
|
@ -70,7 +70,7 @@ class ApiLoggingMiddleware(MiddlewareMixin):
|
||||||
log.save()
|
log.save()
|
||||||
|
|
||||||
def process_view(self, request, view_func, view_args, view_kwargs):
|
def process_view(self, request, view_func, view_args, view_kwargs):
|
||||||
if view_func.cls and hasattr(view_func.cls, 'queryset'):
|
if hasattr(view_func,'cls') and hasattr(view_func.cls, 'queryset'):
|
||||||
request.session['model_name'] = get_verbose_name(view_func.cls.queryset)
|
request.session['model_name'] = get_verbose_name(view_func.cls.queryset)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ from django.contrib.auth.models import UserManager, AbstractUser
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.db.models import IntegerField, ForeignKey, CharField, TextField, ManyToManyField, CASCADE
|
from django.db.models import IntegerField, ForeignKey, CharField, TextField, ManyToManyField, CASCADE
|
||||||
|
|
||||||
from ...op_drf.fields import CreateDateTimeField, UpdateDateTimeField
|
from ...op_drf.models import CoreModel
|
||||||
|
|
||||||
|
|
||||||
class UserProfile(AbstractUser):
|
class UserProfile(AbstractUser, CoreModel):
|
||||||
USER_TYPE_CHOICES = (
|
USER_TYPE_CHOICES = (
|
||||||
(0, "后台用户"),
|
(0, "后台用户"),
|
||||||
(1, "前台用户"),
|
(1, "前台用户"),
|
||||||
|
@ -25,9 +25,6 @@ class UserProfile(AbstractUser):
|
||||||
post = ManyToManyField(to='Post', verbose_name='关联岗位', db_constraint=False)
|
post = ManyToManyField(to='Post', verbose_name='关联岗位', db_constraint=False)
|
||||||
role = ManyToManyField(to='Role', verbose_name='关联角色', db_constraint=False)
|
role = ManyToManyField(to='Role', verbose_name='关联角色', db_constraint=False)
|
||||||
dept = ForeignKey(to='Dept', verbose_name='归属部门', on_delete=CASCADE, db_constraint=False, null=True, blank=True)
|
dept = ForeignKey(to='Dept', verbose_name='归属部门', on_delete=CASCADE, db_constraint=False, null=True, blank=True)
|
||||||
dept_belong_id = CharField(max_length=64, verbose_name="数据归属部门", null=True, blank=True)
|
|
||||||
create_datetime = CreateDateTimeField()
|
|
||||||
update_datetime = UpdateDateTimeField()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def get_user_interface_dict(self):
|
def get_user_interface_dict(self):
|
||||||
|
@ -52,6 +49,7 @@ class UserProfile(AbstractUser):
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
return cache.delete(f'permission_interface_dict_{self.username}')
|
return cache.delete(f'permission_interface_dict_{self.username}')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '用户管理'
|
verbose_name = '用户管理'
|
||||||
verbose_name_plural = verbose_name
|
verbose_name_plural = verbose_name
|
||||||
|
|
|
@ -359,7 +359,7 @@ class UserProfileModelViewSet(CustomModelViewSet):
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
instance = self.queryset.get(id=request.user.id)
|
instance = self.queryset.get(id=request.user.id)
|
||||||
instance.mobile = request.data.get('newPassword', None)
|
instance.password = request.data.get('newPassword', None)
|
||||||
if not authenticate(username=request.user.username, password=request.data.get('oldPassword', None)):
|
if not authenticate(username=request.user.username, password=request.data.get('oldPassword', None)):
|
||||||
return ErrorResponse(msg='旧密码不正确!')
|
return ErrorResponse(msg='旧密码不正确!')
|
||||||
instance.set_password(request.data.get('newPassword'))
|
instance.set_password(request.data.get('newPassword'))
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Records of permission_userprofile
|
-- Records of permission_userprofile
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id) VALUES (1, 'pbkdf2_sha256$150000$OjTMSXJgkzrE$jEQCjWbIbXwpN4k2z0o8Yvou1UQGuoJALyL/kGDZFd4=', '2021-02-27 06:20:28.214775', 1, '', '', 1, 1, '2021-02-27 06:20:09.188689', 'admin', '3704adf3-380f-4c27-a8da-60420e8cb4ab', 'admin@qq.com', NULL, NULL, '管理员', '2', '1', 2, '2021-02-27 06:20:09.263192', '2021-02-27 09:14:30.009998', 8, 1);
|
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id, creator_id) VALUES (1, 'pbkdf2_sha256$150000$OjTMSXJgkzrE$jEQCjWbIbXwpN4k2z0o8Yvou1UQGuoJALyL/kGDZFd4=', '2021-02-27 06:20:28.214775', 1, '', '', 1, 1, '2021-02-27 06:20:09.188689', 'admin', '3704adf3-380f-4c27-a8da-60420e8cb4ab', 'admin@qq.com', NULL, NULL, '管理员', '2', '1', 2, '2021-02-27 06:20:09.263192', '2021-02-27 09:14:30.009998', 1, 1, 1);
|
||||||
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id) VALUES (2, 'pbkdf2_sha256$150000$5Z9LSi7LpNms$xVguE/dOEpI4D95LjSaKm0xzG7vNSopUolANr8f/6/E=', NULL, 0, '', '', 0, 1, '2021-03-03 15:38:27.009893', 'dvadmin', 'b4c5d79a-f01c-4244-92f8-b5288eca1d50', NULL, NULL, NULL, '普通用户', '2', NULL, 0, '2021-03-03 15:38:27.010771', '2021-03-03 15:38:27.086069', 8, 1);
|
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id, creator_id) VALUES (2, 'pbkdf2_sha256$150000$5Z9LSi7LpNms$xVguE/dOEpI4D95LjSaKm0xzG7vNSopUolANr8f/6/E=', NULL, 0, '', '', 0, 1, '2021-03-03 15:38:27.009893', 'dvadmin', 'b4c5d79a-f01c-4244-92f8-b5288eca1d50', NULL, NULL, NULL, '普通用户', '2', NULL, 0, '2021-03-03 15:38:27.010771', '2021-03-03 15:38:27.086069', 1, 1, 1);
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for permission_userprofile_post
|
-- Table structure for permission_userprofile_post
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
|
|
|
@ -12,8 +12,8 @@ from django.utils.translation import ugettext as _
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
from rest_framework_jwt.utils import jwt_decode_handler
|
from rest_framework_jwt.utils import jwt_decode_handler
|
||||||
|
|
||||||
from .decorators import exceptionHandler
|
|
||||||
from .jwt_util import jwt_get_session_id
|
from .jwt_util import jwt_get_session_id
|
||||||
|
from ..permission.models.users import UserProfile
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
@ -38,6 +38,8 @@ class OpAuthJwtAuthentication(object):
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
raise exceptions.AuthenticationFailed(msg)
|
||||||
except jwt.InvalidTokenError:
|
except jwt.InvalidTokenError:
|
||||||
raise exceptions.AuthenticationFailed()
|
raise exceptions.AuthenticationFailed()
|
||||||
|
except UserProfile.DoesNotExist:
|
||||||
|
raise exceptions.AuthenticationFailed()
|
||||||
|
|
||||||
username = payload.get('username', None)
|
username = payload.get('username', None)
|
||||||
if not username:
|
if not username:
|
||||||
|
|
|
@ -161,7 +161,7 @@
|
||||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||||
</span>
|
</span>
|
||||||
<el-dropdown-menu slot="dropdown">
|
<el-dropdown-menu slot="dropdown">
|
||||||
<el-dropdown-item v-for="role in scope.row.role">{{role.roleName}}</el-dropdown-item>
|
<el-dropdown-item v-for="(role,index) in scope.row.role" :key="index">{{role.roleName}}</el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</template>
|
</template>
|
||||||
|
@ -648,6 +648,7 @@
|
||||||
this.$refs['form'].validate(valid => {
|
this.$refs['form'].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (this.form.id != undefined) {
|
if (this.form.id != undefined) {
|
||||||
|
this.form.creator = undefined
|
||||||
updateUser(this.form).then(response => {
|
updateUser(this.form).then(response => {
|
||||||
this.msgSuccess('修改成功')
|
this.msgSuccess('修改成功')
|
||||||
this.open = false
|
this.open = false
|
||||||
|
|
Loading…
Reference in New Issue