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.
|
|
|
const md5 = require('md5');
|
|
|
|
const {
|
|
|
|
loginDao,
|
|
|
|
updateUserDao,
|
|
|
|
getUserInfoDao
|
|
|
|
} = 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 (userInfo) {
|
|
|
|
|
|
|
|
// userInfo.loginPwd = md5(userInfo.loginPwd)
|
|
|
|
await updateUserDao(userInfo)
|
|
|
|
|
|
|
|
const result = await getUserInfoDao(userInfo.loginId)
|
|
|
|
|
|
|
|
return result.dataValues
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.getUserInfoService = async function (loginId) {
|
|
|
|
const data = await getUserInfoDao(loginId)
|
|
|
|
return data.dataValues
|
|
|
|
}
|