安装
npm install md5
用法
var md5 = require(‘md5’);
md5(‘message’)
- message – String, Buffer, Array or Uint8Array
- returns String
const Admin = require('../models/admin')
const md5 = require('md5')
exports.addAdmin =async function(adminObj){
adminObj.loginPwd = md5(adminObj.loginPwd)
const ins = await Admin.create(adminObj)
console.log(ins.toJSON())
return ins.toJSON()
}
exports.deteleAdmin =async function(loginId){
// const ins = await Admin.findByPk(id)
// console.log(ins.toJSON())
// await ins.destroy()
const re= await Admin.destroy({
where:{
loginId,
}
})
console.log(re)
}
exports.updateAdmin =async function(id,loginObj){
if(loginObj.loginPwd){
adminObj.loginPwd = md5(adminObj.loginPwd)
}
const re = await Admin.update(loginObj,{
where:{
id,
}
})
console.log(re)
}
exports.login= async function(loginId,loginPwd){
loginPwd = md5(loginPwd)
const result = await Admin.findOne({
where:{
loginId,
loginPwd
},
});
if(result && result.loginId == loginId){
return result.toJSON()
}
return null
}