修复BUG:
1.密码重置; 2.个人中心密码修改
This commit is contained in:
@@ -320,15 +320,17 @@ class UserViewSet(CustomModelViewSet):
|
||||
"""密码修改"""
|
||||
data = request.data
|
||||
old_pwd = data.get("oldPassword")
|
||||
print(old_pwd)
|
||||
new_pwd = data.get("newPassword")
|
||||
new_pwd2 = data.get("newPassword2")
|
||||
if old_pwd is None or new_pwd is None or new_pwd2 is None:
|
||||
return ErrorResponse(msg="参数不能为空")
|
||||
if new_pwd != new_pwd2:
|
||||
return ErrorResponse(msg="两次密码不匹配")
|
||||
verify_password = check_password(old_pwd, self.request.user.password)
|
||||
verify_password = check_password(old_pwd, request.user.password)
|
||||
if not verify_password:
|
||||
verify_password = check_password(hashlib.md5(old_pwd.encode(encoding='UTF-8')).hexdigest(), self.request.user.password)
|
||||
old_pwd_md5 = hashlib.md5(old_pwd.encode(encoding='UTF-8')).hexdigest()
|
||||
verify_password = check_password(str(old_pwd_md5), request.user.password)
|
||||
if verify_password:
|
||||
request.user.password = make_password(hashlib.md5(new_pwd.encode(encoding='UTF-8')).hexdigest())
|
||||
request.user.save()
|
||||
@@ -337,11 +339,15 @@ class UserViewSet(CustomModelViewSet):
|
||||
return ErrorResponse(msg="旧密码不正确")
|
||||
|
||||
@action(methods=["PUT"], detail=True, permission_classes=[IsAuthenticated])
|
||||
def reset_to_default_password(self, request, *args, **kwargs):
|
||||
def reset_to_default_password(self, request,pk):
|
||||
"""恢复默认密码"""
|
||||
instance = Users.objects.filter(id=kwargs.get("pk")).first()
|
||||
if not self.request.user.is_superuser:
|
||||
return ErrorResponse(msg="只允许超级管理员对其进行密码重置")
|
||||
instance = Users.objects.filter(id=pk).first()
|
||||
if instance:
|
||||
instance.set_password(dispatch.get_system_config_values("base.default_password"))
|
||||
default_password = dispatch.get_system_config_values("base.default_password")
|
||||
md5_pwd = hashlib.md5(default_password.encode(encoding='UTF-8')).hexdigest()
|
||||
instance.password = make_password(md5_pwd)
|
||||
instance.save()
|
||||
return DetailResponse(data=None, msg="密码重置成功")
|
||||
else:
|
||||
|
||||
@@ -182,6 +182,7 @@ import { useRouter } from 'vue-router';
|
||||
import { useUserInfo } from '/@/stores/userInfo';
|
||||
import { successMessage } from '/@/utils/message';
|
||||
import {dictionary} from "/@/utils/dictionary";
|
||||
import {Md5} from "ts-md5";
|
||||
const router = useRouter();
|
||||
|
||||
// 头像裁剪组件
|
||||
@@ -330,6 +331,7 @@ const passwordRules = reactive({
|
||||
* 重新设置密码
|
||||
*/
|
||||
const settingPassword = () => {
|
||||
console.log(Md5.hashStr('admin123456'))
|
||||
userPasswordFormRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
api.UpdatePassword(userPasswordInfo).then((res: any) => {
|
||||
|
||||
@@ -56,3 +56,11 @@ export function exportData(params:any){
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function resetToDefaultPassword(id:any){
|
||||
return request({
|
||||
url: apiPrefix + id + '/reset_to_default_password/',
|
||||
method: 'put'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,10 +37,15 @@ export const createCrudOptions = function ({crudExpose}: CreateCrudOptionsProps)
|
||||
return await api.exportData(query)
|
||||
}
|
||||
|
||||
const resetToDefaultPasswordRequest = async (row:EditReq)=>{
|
||||
await api.resetToDefaultPassword(row.id)
|
||||
successMessage("重置密码成功")
|
||||
}
|
||||
|
||||
const systemConfigStore = SystemConfigStore()
|
||||
const {systemConfig} = storeToRefs(systemConfigStore)
|
||||
const getSystemConfig = computed(() => {
|
||||
console.log(systemConfig.value)
|
||||
// console.log(systemConfig.value)
|
||||
return systemConfig.value
|
||||
})
|
||||
|
||||
@@ -108,6 +113,7 @@ export const createCrudOptions = function ({crudExpose}: CreateCrudOptionsProps)
|
||||
//@ts-ignore
|
||||
click: (ctx: any) => {
|
||||
const {row} = ctx;
|
||||
resetToDefaultPasswordRequest(row)
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user