Commit d379da40 authored by Davve's avatar Davve

完成用户密码重置

parent 049937f2
...@@ -79,8 +79,6 @@ class LoginView(APIView): ...@@ -79,8 +79,6 @@ class LoginView(APIView):
raise e raise e
return {'data': data} return {'data': data}
def post(self, request): def post(self, request):
""" """
登陆 登陆
...@@ -116,10 +114,21 @@ class LoginView(APIView): ...@@ -116,10 +114,21 @@ class LoginView(APIView):
class LogoutView(APIView): class LogoutView(APIView):
def post(self, request): def post(self, request):
print(request.POST)
self.rpc['venus/sun/account/logout']().unwrap() self.rpc['venus/sun/account/logout']().unwrap()
return { return {
'session_key': '' 'session_key': ''
} }
class ResetPasswordView(APIView):
def post(self, request):
id = request.POST.get('id')
password = make_password(settings.OPERATOR_PASSWORD)
try:
self.rpc['venus/sun/account/reset_password'](id=id, password=password).unwrap()
except Exception as e:
raise e
return {
'message': '操作成功'
}
...@@ -23,6 +23,7 @@ urlpatterns = [ ...@@ -23,6 +23,7 @@ urlpatterns = [
url(r'^account/login$', LoginView.as_view()), url(r'^account/login$', LoginView.as_view()),
url(r'^account/logout$', LogoutView.as_view()), url(r'^account/logout$', LogoutView.as_view()),
url(r'^account/get$', LoginView.as_view()), url(r'^account/get$', LoginView.as_view()),
url(r'^account/reset_password', ResetPasswordView.as_view()),
url(r'^account/list$', AccountList.as_view()), url(r'^account/list$', AccountList.as_view()),
url(r'^account/list/update$', AccountList.as_view()), url(r'^account/list/update$', AccountList.as_view()),
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
# Date: 2018/11/15 # Date: 2018/11/15
import json import json
from django.conf import settings
from utils.base import APIView from utils.base import APIView
from utils.time_utils import generate_id from utils.time_utils import generate_id
from django.contrib.auth.hashers import make_password
class UserListView(APIView): class UserListView(APIView):
...@@ -36,10 +38,12 @@ class UserUpdateOrCreate(APIView): ...@@ -36,10 +38,12 @@ class UserUpdateOrCreate(APIView):
id = request.POST.get('id', '') id = request.POST.get('id', '')
user_id = request.POST.get('user_id', '') user_id = request.POST.get('user_id', '')
tag_ids = list(map(lambda x: x.split(":")[0], json.loads(request.POST.get('tags', '[]')))) tag_ids = list(map(lambda x: x.split(":")[0], json.loads(request.POST.get('tags', '[]'))))
password = make_password(settings.PUPPET_PASSWORD, None, 'pbkdf2_sha256')
if not user_id: if not user_id:
user_id = generate_id() user_id = generate_id()
data = { data = {
'user_id': user_id, 'user_id': user_id,
'password': password,
'is_recommend': request.POST.get('is_recommend'), 'is_recommend': request.POST.get('is_recommend'),
'profile_pic': request.POST.get('avatar')[:-2], 'profile_pic': request.POST.get('avatar')[:-2],
'nick_name': request.POST.get('nick_name'), 'nick_name': request.POST.get('nick_name'),
......
...@@ -144,4 +144,10 @@ USERNAME = 'admin' ...@@ -144,4 +144,10 @@ USERNAME = 'admin'
PASSWORD = 'admin' PASSWORD = 'admin'
# 管理员头像 # 管理员头像
AVATAR = 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif' AVATAR = 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif'
\ No newline at end of file
# 马甲用户密码
PUPPET_PASSWORD = 123456
# 重置运营管理登陆密码
OPERATOR_PASSWORD = 123456
\ No newline at end of file
...@@ -31,3 +31,11 @@ export function fetchAccountDetail(id) { ...@@ -31,3 +31,11 @@ export function fetchAccountDetail(id) {
params: { id } params: { id }
}) })
} }
export function resetPassword(data) {
return request({
url: '/api/account/reset_password',
method: 'post',
data
})
}
<template> <template>
<div class="app-container"> <div class="app-container">
<div class="filter-container"> <div class="filter-container">
<el-input :placeholder="'搜素'" v-model="listQuery.filter.value" style="width: 180px;" class="filter-item" @keyup.enter.native="handleFilter"/> <el-input :placeholder="'搜素'" v-model="listQuery.filter.value" style="width: 180px;" class="filter-item"
<el-select v-model="listQuery.filter.key" :placeholder="'搜索字段'" clearable class="filter-item" style="width: 110px"> @keyup.enter.native="handleFilter"/>
<el-select v-model="listQuery.filter.key" :placeholder="'搜索字段'" clearable class="filter-item"
style="width: 110px">
<el-option v-for="item in SearchTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/> <el-option v-for="item in SearchTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
</el-select> </el-select>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button> <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">创建</el-button> <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('offline')">下线</el-button> @click="handleCreate">创建
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('online')">上线</el-button> </el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
@click="handleOfflineOrOnline('offline')">下线
</el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
@click="handleOfflineOrOnline('online')">上线
</el-button>
</div> </div>
<el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange"> <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%"
<el-table-column type="selection" align="center"></el-table-column> ref="multipleTable" @selection-change="handleSelectionChange">
<el-table-column align="center" label="账号ID" > <el-table-column type="selection" align="center"></el-table-column>
<el-table-column align="center" label="账号ID">
<template slot-scope="scope"> <template slot-scope="scope">
<router-link :to="'/account/edit/'+scope.row.id" class="link-type"> <router-link :to="'/account/edit/'+scope.row.id" class="link-type">
<span>{{ scope.row.id }}</span> <span>{{ scope.row.id }}</span>
</router-link> </router-link>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="用户名"> <el-table-column align="center" label="用户名">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.username }}</span> <span>{{ scope.row.username }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="邮箱"> <el-table-column align="center" label="邮箱">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.email }}</span> <span>{{ scope.row.email }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="是否在线"> <el-table-column align="center" label="是否在线">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="scope.row.is_online | isOnlineFilter">{{ scope.row.is_online==1 ? '是' : '否' }}</el-tag> <el-tag :type="scope.row.is_online | isOnlineFilter">{{ scope.row.is_online==1 ? '是' : '否' }}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="操作">
<template slot-scope="scope">
<el-button class="filter-item" type="primary" icon="el-icon-edit" @click="reset(scope.row)">重置密码</el-button>
</template>
</el-table-column>
</el-table> </el-table>
<pagination v-show="total>0" :total="total" :page="listQuery.page" :limit="listQuery.limit" style="margin-left: 250px;" @pagination="getList" /> <pagination v-show="total>0" :total="total" :page="listQuery.page" :limit="listQuery.limit"
style="margin-left: 250px;" @pagination="getList"/>
</div> </div>
</template> </template>
<script> <script>
import { fetchList, OffLineOrOnLine } from '@/api/account' import {fetchList, OffLineOrOnLine, resetPassword} from '@/api/account'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import waves from '@/directive/waves' import waves from '@/directive/waves'
export default { export default {
name: 'UserList', name: 'UserList',
components: { Pagination }, components: {Pagination},
directives: { waves }, directives: {waves},
filters: { filters: {
isOnlineFilter(status) { isOnlineFilter(status) {
const statusMap = { const statusMap = {
1: 'success', 1: 'success',
0: 'info', 0: 'info',
}
return statusMap[status]
} }
return statusMap[status] },
} data() {
}, return {
data() { list: null,
return { total: 0,
list: null, listLoading: true,
total: 0, multipleSelection: [],
listLoading: true, del_list: [],
multipleSelection: [],
del_list: [],
listQuery: { listQuery: {
page: 0, page: 0,
limit: 10, limit: 10,
filter: { filter: {
value: '', value: '',
key: '', key: '',
is_online: '', is_online: '',
},
}, },
}, BooleanTypeOptions: [
BooleanTypeOptions: [ {'key': 1, 'display_name': '是'},
{'key': 1, 'display_name': '是'}, {'key': 0, 'display_name': '否'}
{'key': 0, 'display_name': '否'} ],
], SearchTypeOptions: [
SearchTypeOptions:[ {'key': 'user__username', 'display_name': '用户名'},
{'key': 'user__username', 'display_name': '用户名'}, ]
] }
}
},
created() {
this.getList()
},
methods: {
getList() {
this.listLoading = true
fetchList(this.listQuery).then(response => {
this.list = response.data.data.data
this.total = response.data.data.total
this.listLoading = false
})
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.limit = val
this.getList()
},
handleCurrentChange(val) {
this.listQuery.page = val
this.getList()
}, },
handleFilter() { created() {
this.listQuery.page = 1
this.getList() this.getList()
}, },
handleCreate() { methods: {
this.$router.push('/account/create') getList() {
}, this.listLoading = true
handleOfflineOrOnline(val){ fetchList(this.listQuery).then(response => {
const length = this.multipleSelection.length; this.list = response.data.data.data
let str = ''; this.total = response.data.data.total
this.del_list = this.del_list.concat(this.multipleSelection); this.listLoading = false
for (let i = 0; i < length; i++) { })
if (val === 'offline'){ },
handleSelectionChange(val) {
this.multipleSelection = val;
},
handleSizeChange(val) {
this.listQuery.limit = val
this.getList()
},
handleCurrentChange(val) {
this.listQuery.page = val
this.getList()
},
handleFilter() {
this.listQuery.page = 1
this.getList()
},
handleCreate() {
this.$router.push('/account/create')
},
handleOfflineOrOnline(val) {
const length = this.multipleSelection.length;
let str = '';
this.del_list = this.del_list.concat(this.multipleSelection);
for (let i = 0; i < length; i++) {
if (val === 'offline') {
this.multipleSelection[i].is_online = 0 this.multipleSelection[i].is_online = 0
}else{ } else {
this.multipleSelection[i].is_online = 1 this.multipleSelection[i].is_online = 1
} }
str += this.multipleSelection[i].id + ' '; str += this.multipleSelection[i].id + ' ';
}
OffLineOrOnLine({type: val, ids: str}).then(response => {
this.multipleSelection = [];
this.$message.success(response.data.data.message);
this.$router.go(0)
})
},
reset(data){
resetPassword(data).then(response =>{
this.$message.success('重置成功')
})
} }
OffLineOrOnLine({type:val, ids:str}).then(response => { }
this.multipleSelection = [];
this.$message.success(response.data.data.message);
this.$router.go(0)
})
},
} }
}
</script> </script>
<style scoped> <style scoped>
.edit-input { .edit-input {
padding-right: 100px; padding-right: 100px;
} }
.cancel-btn {
position: absolute; .cancel-btn {
right: 15px; position: absolute;
top: 10px; right: 15px;
} top: 10px;
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment