this is my code auth.js(koa)
const auth=require('../function/auth');
const jwt = require('jsonwebtoken');
const bcrypt = require('bcryptjs');
var log = async (ctx,next)=>{
var Account=ctx.request.body.account,
Password=ctx.request.body.password,
query={
account:Account,
}
var data=await auth.log(query);
if(data.length>0){
if(bcrypt.compareSync(Password,data[0].password)){
const userToken={
account:data[0].account,
id:data[0]._id
}
const secret = 'vue-koa-demo';
const token =jwt.sign(userToken,secret);
ctx.response.type='application/json'
ctx.response.body={
sta:true,
token:token}
}
else if(!bcrypt.compareSync(Password,data[0].password)){
ctx.response.type='application/json'
ctx.response.body={
sta:false,
info:'密码错了'}
}
}if(data.length==0){
ctx.response.type='application/json'
ctx.response.body={
sta:false,
info:'账号不存在'}
}
}
and this is my TodoList.vue (vue)
...
<script>
import jws from 'jsonwebtoken'
export default {
created () { // 组件创建时调用
const userInfo = this.getUserInfo()
if (userInfo !== null) {
this.id = userInfo.id
this.name = userInfo.name
} else {
this.id = ''
this.name = ''
}
},
data () {
return {
name: 'Molunerfinn',
todos: '',
activeName: 'first',
list: [],
count: 0
}
},
computed: { // 计算属性用于计算是否已经完成了所有任务
Done () {
let count = 0
let length = this.list.length
for (let i in this.list) {
this.list[i].status === true ? count += 1 : ''
}
this.count = count
if (count === length || length === 0) {
return true
} else {
return false
}
}
},
methods: {
addTodos () {
if (this.todos === '') {
return
}
let obj = {
status: false,
content: this.todos
}
this.list.push(obj)
this.todos = ''
},
finished (index) {
this.$set(this.list[index], 'status', true)
this.$message({
type: 'success',
message: '任务完成'
})
},
remove (index) {
this.list.splice(index, 1)
this.$message({
type: 'info',
message: '任务删除'
})
},
restore (index) {
this.$set(this.list[index], 'status', false)
this.$message({
type: 'info',
message: '任务还原'
})
},
getUserInfo () {
const token = sessionStorage.getItem('my-token')
if (token !== null) {
let decode = jwt.verify(token, 'vue-koa-demo')
return decode
} else {
return null
}
}
}
}
</script>
...
then in vsCODE npm run dev ,
hese dependencies were not found:
- net in ./~/joi/lib/string.js
- dns in ./~/isemail/lib/isemail.js
To install them, you can run: npm install --save net dns
and i try , but now the problem is
These dependencies were not found:
- fs in ./~/native-dns/lib/platform.js
- dgram in ./~/native-dns/lib/server.js, ./~/native-dns/lib/utils.js and 1 other
To install them, you can run: npm install --save fs dgram
via ZZ huang
No comments:
Post a Comment