login msg

This commit is contained in:
caoqianming 2020-09-24 14:09:01 +08:00
parent 2f39a1882b
commit 592dcfcbe8
6 changed files with 322 additions and 270 deletions

View File

@ -1,112 +1,130 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<div> <el-row :gutter="6">
<el-input <el-col :xs="24" :md="16">
v-model="listQuery.search" <el-input
placeholder="项目/标准/编号/中心" v-model="listQuery.search"
style="width: 600px;" placeholder="项目/标准/编号/中心"
class="filter-item" style="width: 100%"
@keyup.enter.native="handleFilter" class="filter-item"
/> @keyup.enter.native="handleFilter"
<el-button />
class="filter-item" </el-col>
type="primary" <el-col :xs="24" :md="8" >
icon="el-icon-search" <el-button
@click="handleFilter" class="filter-item"
>搜索</el-button> type="primary"
<el-button icon="el-icon-search"
class="filter-item" @click="handleFilter"
style="margin-left: 10px;" >搜索</el-button
type="primary" >
icon="el-icon-refresh-left" <el-button
@click="resetFilter" class="filter-item"
>刷新重置</el-button> type="primary"
</div> icon="el-icon-refresh-left"
<div style="margin-top:10px"> @click="resetFilter"
<!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['cma_create'])">新增</el-button> --> >刷新重置</el-button
<el-popover >
placement="top" </el-col>
width="160" </el-row>
v-if="checkPermission(['ability_import'])" <div style="margin-top: 10px">
v-model="popovervisible" <!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['cma_create'])">新增</el-button> -->
> <el-popover
<p>导入能力列表压缩包.</p> placement="top"
<div style="text-align: left; margin: 0;"> width="160"
<el-upload v-if="checkPermission(['ability_import'])"
:action="upUrl" v-model="popovervisible"
:on-success="handleUploadSuccess" >
accept=".rar,.zip" <p>导入能力列表压缩包.</p>
:headers="upHeaders" <div style="text-align: left; margin: 0">
:show-file-list ="false" <el-upload
> :action="upUrl"
<el-button size="small" type="primary" @click="popovervisible = false">上传导入</el-button> :on-success="handleUploadSuccess"
</el-upload> accept=".rar,.zip"
</div> :headers="upHeaders"
:show-file-list="false"
<el-button slot="reference">导入CMA能力</el-button>
</el-popover>
<el-popover
placement="top"
width="160"
v-if="checkPermission(['ability_import'])"
v-model="popovervisible2"
>
<p>导入能力列表压缩包.</p>
<div style="text-align: left; margin: 0;">
<el-upload
:action="upUrl"
:on-success="handleUploadSuccess2"
accept=".rar"
:headers="upHeaders"
:show-file-list ="false"
>
<el-button size="small" type="primary" @click="popovervisible2 = false">上传导入</el-button>
</el-upload>
</div>
<el-button slot="reference">导入CNAS能力</el-button>
</el-popover>
</div>
<el-table
v-loading="listLoading"
:data="cmaList.results"
style="width: 100%;margin-top:10px;"
border
fit
stripe
highlight-current-row
max-height="300"
ref="filterTable"
@filter-change="filterChange"
>
<el-table-column type="index" width="50" />
<el-table-column align="center" label="大类名称">
<template slot-scope="scope">{{ scope.row.dlmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="类别名称">
<template slot-scope="scope">{{ scope.row.lbmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="项目序号">
<template slot-scope="scope">{{ scope.row.xmxh }}</template>
</el-table-column>
<el-table-column align="header-center" label="项目名称">
<template slot-scope="scope">{{ scope.row.xmmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="标准名称">
<template slot-scope="scope">{{ scope.row.bzmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="标准编号">
<template slot-scope="scope">{{ scope.row.bzbh }}</template>
</el-table-column>
<el-table-column align="header-center" label="所属中心"
prop="sszx"
column-key="sszx"
:filters="groupBy.sszx"
:filter-multiple="false"
> >
<template slot-scope="scope">{{ scope.row.sszx }}</template> <el-button
</el-table-column> size="small"
<!-- <el-table-column align="center" label="操作"> type="primary"
@click="popovervisible = false"
>上传导入</el-button
>
</el-upload>
</div>
<el-button slot="reference">导入CMA能力</el-button>
</el-popover>
<el-popover
placement="top"
width="160"
v-if="checkPermission(['ability_import'])"
v-model="popovervisible2"
>
<p>导入能力列表压缩包.</p>
<div style="text-align: left; margin: 0">
<el-upload
:action="upUrl"
:on-success="handleUploadSuccess2"
accept=".rar"
:headers="upHeaders"
:show-file-list="false"
>
<el-button
size="small"
type="primary"
@click="popovervisible2 = false"
>上传导入</el-button
>
</el-upload>
</div>
<el-button slot="reference">导入CNAS能力</el-button>
</el-popover>
</div>
<el-card style="margin-top: 6px">
<el-table
v-loading="listLoading"
:data="cmaList.results"
style="width: 100%; "
border
fit
stripe
highlight-current-row
max-height="320"
ref="filterTable"
@filter-change="filterChange"
>
<el-table-column type="index" width="50" />
<el-table-column align="center" label="大类名称">
<template slot-scope="scope">{{ scope.row.dlmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="类别名称">
<template slot-scope="scope">{{ scope.row.lbmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="项目序号">
<template slot-scope="scope">{{ scope.row.xmxh }}</template>
</el-table-column>
<el-table-column align="header-center" label="项目名称">
<template slot-scope="scope">{{ scope.row.xmmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="标准名称">
<template slot-scope="scope">{{ scope.row.bzmc }}</template>
</el-table-column>
<el-table-column align="header-center" label="标准编号">
<template slot-scope="scope">{{ scope.row.bzbh }}</template>
</el-table-column>
<el-table-column
align="header-center"
label="所属中心"
prop="sszx"
column-key="sszx"
:filters="groupBy.sszx"
:filter-multiple="false"
>
<template slot-scope="scope">{{ scope.row.sszx }}</template>
</el-table-column>
<!-- <el-table-column align="center" label="操作">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
:disabled="!checkPermission(['cma_update'])" :disabled="!checkPermission(['cma_update'])"
@ -124,48 +142,47 @@
/> />
</template> </template>
</el-table-column> --> </el-table-column> -->
</el-table> </el-table>
<pagination <pagination
v-show="cmaList.count>0" v-show="cmaList.count > 0"
:total="cmaList.count" :total="cmaList.count"
:page.sync="listQuery.page" :page.sync="listQuery.page"
:limit.sync="listQuery.page_size" :limit.sync="listQuery.page_size"
@pagination="getList" @pagination="getList"
/> />
</el-card>
<el-table <el-card style="margin-top:6px">
v-loading="listLoading2" <el-table
:data="cnasList.results" v-loading="listLoading2"
style="width: 100%;margin-top:10px;" :data="cnasList.results"
border style="width: 100%;"
fit border
stripe fit
highlight-current-row stripe
max-height="300" highlight-current-row
max-height="320"
> >
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column align="header-center" label="类别名称"> <el-table-column align="header-center" label="类别名称">
<template slot-scope="scope">{{ scope.row.lbmc }}</template> <template slot-scope="scope">{{ scope.row.lbmc }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="项目名称"> <el-table-column align="header-center" label="项目名称">
<template slot-scope="scope">{{ scope.row.xmmc }}</template> <template slot-scope="scope">{{ scope.row.xmmc }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="标准名称"> <el-table-column align="header-center" label="标准名称">
<template slot-scope="scope">{{ scope.row.bzmc }}</template> <template slot-scope="scope">{{ scope.row.bzmc }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="标准编号"> <el-table-column align="header-center" label="标准编号">
<template slot-scope="scope">{{ scope.row.bzbh }}</template> <template slot-scope="scope">{{ scope.row.bzbh }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="标准条款"> <el-table-column align="header-center" label="标准条款">
<template slot-scope="scope">{{ scope.row.bztk }}</template> <template slot-scope="scope">{{ scope.row.bztk }}</template>
</el-table-column> </el-table-column>
<el-table-column align="header-center" label="所属中心" <el-table-column align="header-center" label="所属中心">
> <template slot-scope="scope">{{ scope.row.sszx }}</template>
<template slot-scope="scope">{{ scope.row.sszx }}</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-button <el-button
:disabled="!checkPermission(['cnas_update'])" :disabled="!checkPermission(['cnas_update'])"
@ -183,18 +200,26 @@
/> />
</template> </template>
</el-table-column> --> </el-table-column> -->
</el-table> </el-table>
<pagination <pagination
v-show="cnasList.count>0" v-show="cnasList.count > 0"
:total="cnasList.count" :total="cnasList.count"
:page.sync="listQuery2.page" :page.sync="listQuery2.page"
:limit.sync="listQuery2.page_size" :limit.sync="listQuery2.page_size"
@pagination="getList2" @pagination="getList2"
/> />
</el-card>
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'编辑':'新增'"> <el-dialog
<el-form ref="Form" :model="cma" label-width="80px" label-position="right" > :visible.sync="dialogVisible"
:title="dialogType === 'edit' ? '编辑' : '新增'"
>
<el-form
ref="Form"
:model="cma"
label-width="80px"
label-position="right"
>
<el-form-item label="姓名" prop="name"> <el-form-item label="姓名" prop="name">
<el-input v-model="cma.name" placeholder="姓名" /> <el-input v-model="cma.name" placeholder="姓名" />
</el-form-item> </el-form-item>
@ -202,36 +227,44 @@
<el-input v-model="cma.username" placeholder="账户" /> <el-input v-model="cma.username" placeholder="账户" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style="text-align:right;"> <div style="text-align: right">
<el-button type="danger" @click="dialogVisible=false">取消</el-button> <el-button type="danger" @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="confirm('Form')">确认</el-button> <el-button type="primary" @click="confirm('Form')">确认</el-button>
</div> </div>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<style > <style >
.el-table-filter{ .el-table-filter {
width:300px; width: 300px;
max-height: 300px; max-height: 300px;
overflow-y: auto; overflow-y: auto;
} }
</style> </style>
<script> <script>
import { getCMAList, createCMA, deleteCMA, updateCMA, importCMA, getCNASList, importCNAS, getCMAGroup } from "@/api/cma"; import {
import checkPermission from "@/utils/permission" getCMAList,
import { upUrl, upHeaders } from "@/api/file" createCMA,
import Pagination from "@/components/Pagination" // secondary package based on el-pagination deleteCMA,
updateCMA,
importCMA,
getCNASList,
importCNAS,
getCMAGroup,
} from "@/api/cma";
import checkPermission from "@/utils/permission";
import { upUrl, upHeaders } from "@/api/file";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
const defaultCMA = { const defaultCMA = {
id: "", id: "",
dlxh:null, dlxh: null,
dlmc:null, dlmc: null,
}; };
const dflistQuery = { const dflistQuery = {
page: 1, page: 1,
page_size: 20, page_size: 20,
type:'center' type: "center",
} };
export default { export default {
components: { Pagination }, components: { Pagination },
data() { data() {
@ -239,19 +272,19 @@ export default {
cma: defaultCMA, cma: defaultCMA,
upHeaders: upHeaders(), upHeaders: upHeaders(),
upUrl: upUrl(), upUrl: upUrl(),
groupBy:{sszx:[]}, groupBy: { sszx: [] },
cmaList: {count:0}, cmaList: { count: 0 },
cnasList: {count:0}, cnasList: { count: 0 },
listLoading: true, listLoading: true,
listLoading2:false, listLoading2: false,
listQuery: Object.assign({}, dflistQuery), listQuery: Object.assign({}, dflistQuery),
listQuery2: { listQuery2: {
page: 1, page: 1,
page_size: 20 page_size: 20,
}, },
enabledOptions: [ enabledOptions: [
{ key: "true", display_name: "激活" }, { key: "true", display_name: "激活" },
{ key: "false", display_name: "禁用" } { key: "false", display_name: "禁用" },
], ],
dialogVisible: false, dialogVisible: false,
dialogType: "new", dialogType: "new",
@ -260,131 +293,138 @@ export default {
}; };
}, },
computed: {}, computed: {},
watch: { watch: {},
},
created() { created() {
this.getList() this.getList();
this.getGroup() this.getGroup();
this.getList2() this.getList2();
}, },
methods: { methods: {
checkPermission, checkPermission,
handleUploadSuccess(res, file) { handleUploadSuccess(res, file) {
const loading = this.openLoading() const loading = this.openLoading();
let data = {path:res.data.path} let data = { path: res.data.path };
importCMA(data).then(res=>{ importCMA(data)
this.$message({ .then((res) => {
message: '导入成功', this.$message({
type: 'success' message: "导入成功",
type: "success",
});
loading.close();
this.resetFilter();
}) })
loading.close() .catch((error) => {
this.resetFilter() loading.close();
}).catch(error=>{loading.close()}) });
}, },
handleUploadSuccess2(res, file) { handleUploadSuccess2(res, file) {
const loading = this.openLoading() const loading = this.openLoading();
let data = {path:res.data.path} let data = { path: res.data.path };
importCNAS(data).then(res=>{ importCNAS(data)
this.$message({ .then((res) => {
message: '导入成功', this.$message({
type: 'success' message: "导入成功",
type: "success",
});
loading.close();
this.resetFilter();
}) })
loading.close() .catch((error) => {
this.resetFilter() loading.close();
}).catch(error=>{loading.close()}) });
}, },
getList() { getList() {
this.listLoading = true; this.listLoading = true;
getCMAList(this.listQuery).then(response => { getCMAList(this.listQuery).then((response) => {
if (response.data) { if (response.data) {
this.cmaList = response.data this.cmaList = response.data;
} }
this.listLoading = false this.listLoading = false;
}) });
}, },
getGroup() { getGroup() {
for(let key in this.groupBy){ for (let key in this.groupBy) {
let data = Object.assign({}, this.listQuery) let data = Object.assign({}, this.listQuery);
data.group_by = key data.group_by = key;
getCMAGroup(data).then(response => { getCMAGroup(data).then((response) => {
this.groupBy[key] = response.data this.groupBy[key] = response.data;
}) });
} }
}, },
getList2() { getList2() {
this.listLoading2 = true; this.listLoading2 = true;
getCNASList(this.listQuery2).then(response => { getCNASList(this.listQuery2).then((response) => {
if (response.data) { if (response.data) {
this.cnasList = response.data this.cnasList = response.data;
} }
this.listLoading2 = false this.listLoading2 = false;
}) });
}, },
resetFilter() { resetFilter() {
this.listQuery = Object.assign({}, dflistQuery), (this.listQuery = Object.assign({}, dflistQuery)),
this.listQuery2 = { (this.listQuery2 = {
page: 1, page: 1,
page_size: 20 page_size: 20,
} });
this.getList() this.getList();
this.getList2() this.getList2();
this.getGroup() this.getGroup();
}, },
handleFilter() { handleFilter() {
this.listQuery.page = 1 this.listQuery.page = 1;
this.getList() this.getList();
this.listQuery2.page = 1 this.listQuery2.page = 1;
this.listQuery2.search = this.listQuery.search this.listQuery2.search = this.listQuery.search;
this.getList2() this.getList2();
this.getGroup() this.getGroup();
}, },
handleAdd() { handleAdd() {
this.cma = Object.assign({}, defaultCMA) this.cma = Object.assign({}, defaultCMA);
this.dialogType = "new" this.dialogType = "new";
this.dialogVisible = true this.dialogVisible = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs["Form"].clearValidate() this.$refs["Form"].clearValidate();
}) });
}, },
handleEdit(scope) { handleEdit(scope) {
this.cma = Object.assign({}, scope.row) // copy obj this.cma = Object.assign({}, scope.row); // copy obj
this.dialogType = "edit" this.dialogType = "edit";
this.dialogVisible = true this.dialogVisible = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs["Form"].clearValidate() this.$refs["Form"].clearValidate();
}) });
}, },
handleDelete(scope) { handleDelete(scope) {
this.$confirm("确认删除?", "警告", { this.$confirm("确认删除?", "警告", {
confirmButtonText: "确认", confirmButtonText: "确认",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "error" type: "error",
}) })
.then(async () => { .then(async () => {
await deleteCMA(scope.row.id); await deleteCMA(scope.row.id);
this.cmaList.splice(scope.row.index, 1); this.cmaList.splice(scope.row.index, 1);
this.$message({ this.$message({
type: "success", type: "success",
message: "成功删除!" message: "成功删除!",
}); });
}) })
.catch(err => { .catch((err) => {
console.error(err); console.error(err);
}); });
}, },
filterChange (obj) { filterChange(obj) {
for(let key in obj){ for (let key in obj) {
this.listQuery[key] = obj[key][0] this.listQuery[key] = obj[key][0];
} }
this.listQuery.page=1 this.listQuery.page = 1;
this.getList() this.getList();
}, },
async confirm(form) { async confirm(form) {
this.$refs[form].validate(valid => { this.$refs[form].validate((valid) => {
if (valid) { if (valid) {
const isEdit = this.dialogType === "edit"; const isEdit = this.dialogType === "edit";
if (isEdit) { if (isEdit) {
updateCMA(this.cma.id, this.cma).then(res => { updateCMA(this.cma.id, this.cma).then((res) => {
if (res.code >= 200) { if (res.code >= 200) {
this.getList(); this.getList();
this.dialogVisible = false; this.dialogVisible = false;
@ -392,12 +432,12 @@ this.getList()
title: "成功", title: "成功",
message: "编辑成功", message: "编辑成功",
type: "success", type: "success",
duration: 2000 duration: 2000,
}); });
} }
}); });
} else { } else {
createCMA(this.cma).then(res => { createCMA(this.cma).then((res) => {
if (res.code >= 200) { if (res.code >= 200) {
this.getList(); this.getList();
this.dialogVisible = false; this.dialogVisible = false;
@ -405,7 +445,7 @@ this.getList()
title: "成功", title: "成功",
message: "新增成功", message: "新增成功",
type: "success", type: "success",
duration: 2000 duration: 2000,
}); });
} }
}); });
@ -414,7 +454,7 @@ this.getList()
return false; return false;
} }
}); });
} },
} },
}; };
</script> </script>

View File

@ -1,7 +1,8 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<div> <el-row :gutter="6">
<el-select v-model="listQuery.sszx" placeholder="所属中心" @change="handleFilter2" clearable> <el-col :xs="24" :md="4">
<el-select v-model="listQuery.sszx" placeholder="所属中心" @change="handleFilter2" clearable style="width: 100%;">
<el-option <el-option
v-for="item in groupBy.sszx" v-for="item in groupBy.sszx"
:key="item.value" :key="item.value"
@ -9,13 +10,18 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
</el-col>
<el-col :xs="24" :md="8">
<el-input <el-input
v-model="listQuery.search" v-model="listQuery.search"
placeholder="项目/标准/编号/中心" placeholder="项目/标准/编号/中心"
style="width: 600px;" style="width: 100%;"
class="filter-item" class="filter-item"
@keyup.enter.native="handleFilter" @keyup.enter.native="handleFilter"
/> />
</el-col>
<el-col :xs="24" :md="6">
<el-button <el-button
class="filter-item" class="filter-item"
type="primary" type="primary"
@ -24,12 +30,12 @@
>搜索</el-button> >搜索</el-button>
<el-button <el-button
class="filter-item" class="filter-item"
style="margin-left: 10px;"
type="primary" type="primary"
icon="el-icon-refresh-left" icon="el-icon-refresh-left"
@click="resetFilter" @click="resetFilter"
>刷新重置</el-button> >刷新重置</el-button>
</div> </el-col>
</el-row>
<div style="margin-top:10px"> <div style="margin-top:10px">
<!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['cma_create'])">新增</el-button> --> <!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['cma_create'])">新增</el-button> -->
<el-popover <el-popover
@ -62,7 +68,7 @@
fit fit
stripe stripe
highlight-current-row highlight-current-row
max-height="600" max-height="700"
ref="filterTable" ref="filterTable"
@filter-change="filterChange" @filter-change="filterChange"
> >

View File

@ -1,7 +1,8 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<div> <el-row :gutter="6">
<el-select v-model="listQuery.sszx" placeholder="所属单位" @change="handleFilter2" clearable> <el-col :xs="24" :md="4">
<el-select v-model="listQuery.sszx" placeholder="所属单位" @change="handleFilter2" clearable style="width: 100%;">
<el-option <el-option
v-for="item in groupBy.sszx" v-for="item in groupBy.sszx"
:key="item.value" :key="item.value"
@ -9,13 +10,17 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
</el-col>
<el-col :xs="24" :md="8">
<el-input <el-input
v-model="listQuery.search" v-model="listQuery.search"
placeholder="资质/服务" placeholder="资质/服务"
style="width: 40%;" style="width: 100%;"
class="filter-item" class="filter-item"
@keyup.enter.native="handleFilter" @keyup.enter.native="handleFilter"
/> />
</el-col>
<el-col :xs="24" :md="6">
<el-button <el-button
class="filter-item" class="filter-item"
type="primary" type="primary"
@ -24,12 +29,12 @@
>搜索</el-button> >搜索</el-button>
<el-button <el-button
class="filter-item" class="filter-item"
style="margin-left: 10px;"
type="primary" type="primary"
icon="el-icon-refresh-left" icon="el-icon-refresh-left"
@click="resetFilter" @click="resetFilter"
>刷新</el-button> >刷新</el-button>
</div> </el-col>
</el-row>
<div style="margin-top:10px"> <div style="margin-top:10px">
<el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['qualification_create'])">新增</el-button> <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['qualification_create'])">新增</el-button>
<!-- <el-popover <!-- <el-popover
@ -62,7 +67,7 @@
fit fit
stripe stripe
highlight-current-row highlight-current-row
max-height="600" max-height="700"
ref="filterTable" ref="filterTable"
@filter-change="filterChange" @filter-change="filterChange"
> >

View File

@ -140,7 +140,7 @@ export default {
disabled:false, disabled:false,
buttonmsg:'发送验证码', buttonmsg:'发送验证码',
count:20, count:20,
activeName: "pwd", activeName: "msg",
loginForm: { loginForm: {
username: "", username: "",
password: "", password: "",

View File

@ -65,7 +65,7 @@ class Login2View(APIView):
msg = request.data['msg'] msg = request.data['msg']
if not User.objects.filter(username=mail).exists(): if not User.objects.filter(username=mail).exists():
return Response('账户不存在', status=status.HTTP_400_BAD_REQUEST) return Response('账户不存在', status=status.HTTP_400_BAD_REQUEST)
if Message.objects.filter(mail=mail).last().msg == msg: if Message.objects.filter(mail=mail).exists() and Message.objects.filter(mail=mail).last().msg == msg:
user = User.objects.get(username=mail) user = User.objects.get(username=mail)
return Response(get_tokens_for_user(user), status=status.HTTP_200_OK) return Response(get_tokens_for_user(user), status=status.HTTP_200_OK)
return Response('验证码错误', status=status.HTTP_400_BAD_REQUEST) return Response('验证码错误', status=status.HTTP_400_BAD_REQUEST)
@ -75,7 +75,7 @@ class sendMsg(APIView):
permission_classes = [] permission_classes = []
def post(self, request): def post(self, request):
code = random.randint(1000,9999) code = random.randint(10000,99999)
my_sender = 'caoqianming@ctc.ac.cn' my_sender = 'caoqianming@ctc.ac.cn'
my_user = request.data['mail'] my_user = request.data['mail']
my_pass = '9093QQww' my_pass = '9093QQww'
@ -101,6 +101,7 @@ class sendMsg(APIView):
server.sendmail(my_sender,[my_user,],msg.as_string()) server.sendmail(my_sender,[my_user,],msg.as_string())
# 关闭连接 # 关闭连接
server.quit() server.quit()
Message.objects.filter(mail=my_user).delete()
Message.objects.create(mail=my_user, msg=code) Message.objects.create(mail=my_user, msg=code)
except: except:
return Response('验证码发送失败', status=status.HTTP_400_BAD_REQUEST) return Response('验证码发送失败', status=status.HTTP_400_BAD_REQUEST)

Binary file not shown.