You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
964 B

const md5 = require('md5');
const {
loginDao,
updateUserDao
} = require("../dao/userDao")
const jwt = require("jsonwebtoken");
const {
getJwtToken
} = require('../utils/tools');
module.exports.loginService = async function (loginInfo) {
//将明文密码转换为加密密码
loginInfo.loginPwd = md5(loginInfo.loginPwd);
let userInfo = await loginDao(loginInfo)
if (userInfo) {
const {
loginPwd,
id,
...data
} = userInfo.dataValues
//添加token后返回
let token = ""
token = getJwtToken(data)
return {
token,
data
}
}
return {
data: userInfo
}
}
module.exports.updateUserInfoService = async function (loginInfo) {
const data = loginInfo
data.loginPwd = md5(data.loginPwd)
await updateUserDao(data)
const {
loginPwd,
...result
} = loginInfo
return result
}