管理后台增加重置密码功能

pull/47/merge
isummer 2 years ago
parent 35b64d74de
commit 8fc1d353c9
  1. 8
      fir_admin/src/api/user.js
  2. 58
      fir_admin/src/views/userinfos/UserDetail.vue
  3. 2
      fir_client/src/components/FirLogin.vue
  4. 14
      fir_ser/admin/views/login.py

@ -53,3 +53,11 @@ export function updateCertificationInfo(data) {
data data
}) })
} }
export function resetPassword(data) {
return request({
url: '/user/info',
method: 'post',
data
})
}

@ -28,7 +28,9 @@
<el-row :gutter="12"> <el-row :gutter="12">
<el-col :span="16"> <el-col :span="16">
<el-select v-model="postForm.gender" class="filter-item" placeholder="Please select"> <el-select v-model="postForm.gender" class="filter-item" placeholder="Please select">
<el-option v-for="item in postForm.gender_choices" :key="item.id" :label="item.name" :value="item.id" /> <el-option v-for="item in postForm.gender_choices" :key="item.id" :label="item.name"
:value="item.id"
/>
</el-select> </el-select>
</el-col> </el-col>
</el-row> </el-row>
@ -82,7 +84,9 @@
<el-form-item label="备注"> <el-form-item label="备注">
<el-row :gutter="12"> <el-row :gutter="12">
<el-col :span="16"> <el-col :span="16">
<el-input v-model="postForm.memo" :autosize="{ minRows: 4, maxRows: 6}" type="textarea" placeholder="Please input" /> <el-input v-model="postForm.memo" :autosize="{ minRows: 4, maxRows: 6}" type="textarea"
placeholder="Please input"
/>
</el-col> </el-col>
</el-row> </el-row>
</el-form-item> </el-form-item>
@ -91,7 +95,9 @@
<el-form-item label="用户头像"> <el-form-item label="用户头像">
<el-row :gutter="12"> <el-row :gutter="12">
<el-col :span="16"> <el-col :span="16">
<el-image :src="postForm.head_img" :preview-src-list="[postForm.head_img]" fit="contain" style="width: 100px; height: 100px" /> <el-image :src="postForm.head_img" :preview-src-list="[postForm.head_img]" fit="contain"
style="width: 100px; height: 100px"
/>
</el-col> </el-col>
</el-row> </el-row>
</el-form-item> </el-form-item>
@ -177,10 +183,16 @@
<el-form-item label="实名认证"> <el-form-item label="实名认证">
<el-row :gutter="12"> <el-row :gutter="12">
<el-col :span="16"> <el-col :span="16">
<el-select v-model="postForm.certification" class="filter-item" placeholder="Please select" :disabled="postForm.certification === -1"> <el-select v-model="postForm.certification" class="filter-item" placeholder="Please select"
<el-option v-for="item in postForm.certification_status_choices" :key="item.id" :label="item.name" :value="item.id" /> :disabled="postForm.certification === -1"
>
<el-option v-for="item in postForm.certification_status_choices" :key="item.id" :label="item.name"
:value="item.id"
/>
</el-select> </el-select>
<router-link v-if="postForm.certification_id" :to="{name: 'user_authentication_info_edit',params:{id:postForm.certification_id.id}}"> <router-link v-if="postForm.certification_id"
:to="{name: 'user_authentication_info_edit',params:{id:postForm.certification_id.id}}"
>
<el-button type="primary"> <el-button type="primary">
审核认证信息 审核认证信息
</el-button> </el-button>
@ -234,6 +246,9 @@
<el-col :span="8"> <el-col :span="8">
<el-button @click="add_amount_download_times(postForm.id)">下载次数充值</el-button> <el-button @click="add_amount_download_times(postForm.id)">下载次数充值</el-button>
</el-col> </el-col>
<el-col :span="8">
<el-button @click="reset_password(postForm.id)">重置密码</el-button>
</el-col>
<el-button v-if="!is_edit" type="primary" @click="is_edit=true">修改</el-button> <el-button v-if="!is_edit" type="primary" @click="is_edit=true">修改</el-button>
<div v-else> <div v-else>
<el-button type="primary" @click="is_edit=false">取消</el-button> <el-button type="primary" @click="is_edit=false">取消</el-button>
@ -245,7 +260,7 @@
<script> <script>
import { validURL } from '@/utils/validate' import { validURL } from '@/utils/validate'
import { getUserInfos, updateUserInfo } from '@/api/user' import { getUserInfos, resetPassword, updateUserInfo } from '@/api/user'
import { createOrderInfo } from '@/api/order' import { createOrderInfo } from '@/api/order'
import { changeStorageInfo, getStorageList } from '@/api/storage' import { changeStorageInfo, getStorageList } from '@/api/storage'
@ -341,8 +356,7 @@ export default {
storage_selection: [] storage_selection: []
} }
}, },
computed: { computed: {},
},
created() { created() {
if (this.isEdit) { if (this.isEdit) {
const id = this.$route.params && this.$route.params.id const id = this.$route.params && this.$route.params.id
@ -369,9 +383,33 @@ export default {
message: '取消充值' message: '取消充值'
}) })
}) })
}, reset_password(user_id) {
this.$prompt('请输入新密码,密码至少6位', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(({ value }) => {
resetPassword({ user_id: user_id, password: value }).then(res => {
if (res.code === 1000) {
this.$message.success('密码重置成功')
this.fetchData(user_id)
} else {
this.$message.error(res.msg)
}
})
}).catch((e) => {
console.log(e)
this.$message({
type: 'info',
message: '取消充值'
})
})
}, },
changeStorageData(force) { changeStorageData(force) {
changeStorageInfo({ id: this.postForm.id, use_storage_id: this.postForm.storage, force: force }).then(response => { changeStorageInfo({
id: this.postForm.id,
use_storage_id: this.postForm.storage,
force: force
}).then(response => {
this.$message.success('存储数据迁移并设置刷新成功') this.$message.success('存储数据迁移并设置刷新成功')
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)

@ -290,7 +290,7 @@ export default {
}); });
return return
} }
if (password.length > 6) { if (password.length >= 6) {
let params = { let params = {
"username": email, "username": email,
"password": password, "password": password,

@ -9,6 +9,7 @@ import logging
from django.contrib import auth from django.contrib import auth
from rest_framework.views import APIView from rest_framework.views import APIView
from api.models import UserInfo
from api.utils.auth.util import AuthInfo from api.utils.auth.util import AuthInfo
from api.utils.serializer import UserInfoSerializer from api.utils.serializer import UserInfoSerializer
from api.utils.utils import set_user_token from api.utils.utils import set_user_token
@ -81,3 +82,16 @@ class LoginUserView(APIView):
def get(self, request): def get(self, request):
serializer = UserInfoSerializer(request.user, ) serializer = UserInfoSerializer(request.user, )
return ApiResponse(data=serializer.data) return ApiResponse(data=serializer.data)
def post(self, request):
data = request.data
user_id = data.get('user_id')
password = data.get('password')
if user_id and password and len(password) >= 6:
user_obj = UserInfo.objects.filter(pk=user_id).first()
if user_obj:
user_obj.set_password(password)
user_obj.save(update_fields=['password'])
serializer = UserInfoSerializer(user_obj, )
return ApiResponse(data=serializer.data)
return ApiResponse(code=1001, msg='重置密码失败,用户不存在')

Loading…
Cancel
Save