diff --git a/dao/userDao.js b/dao/userDao.js index 8d19887..7ef2b6b 100644 --- a/dao/userDao.js +++ b/dao/userDao.js @@ -17,4 +17,12 @@ module.exports.updateUserDao = async function (loginInfo) { loginId: loginInfo.loginId, } }) +} + +module.exports.getUserInfoDao = async function (loginId) { + return await userModel.findOne({ + where: { + loginId, + } + }) } \ No newline at end of file diff --git a/routes/user.js b/routes/user.js index 3651035..2f33b2b 100644 --- a/routes/user.js +++ b/routes/user.js @@ -2,7 +2,8 @@ var express = require('express'); var router = express.Router(); const { loginService, - updateUserInfoService + updateUserInfoService, + getUserInfoService } = require("../services/userService") const { formatResponse, @@ -29,27 +30,16 @@ router.get("/whoami", async function (req, res, next) { //获取token,然后进行解析 const { loginId, - sex, - brithday, - region, - number } = analysisToken(req.get("authorization")) - - res.send(formatResponse(0, "", { - loginId, - sex, - brithday, - region, - number - })) + const { + loginPwd, + ...data + } = await getUserInfoService(loginId) + res.send(formatResponse(0, "", data)) }) router.put("/", async function (req, res, next) { - const { - token, - data - } = await updateUserInfoService(req.body) - res.setHeader("authentication", token) + const data = await updateUserInfoService(req.body) res.send(formatResponse(0, "", data)) }) diff --git a/services/userService.js b/services/userService.js index 984881f..5cd5f52 100644 --- a/services/userService.js +++ b/services/userService.js @@ -1,7 +1,8 @@ const md5 = require('md5'); const { loginDao, - updateUserDao + updateUserDao, + getUserInfoDao } = require("../dao/userDao") const jwt = require("jsonwebtoken"); const { @@ -31,16 +32,13 @@ module.exports.loginService = async function (loginInfo) { } module.exports.updateUserInfoService = async function (userInfo) { - const data = userInfo - data.loginPwd = md5(data.loginPwd) - await updateUserDao(data) - const { - loginPwd, - ...result - } = userInfo - //重新赋值token - return { - token: getJwtToken(result), - data: result - } + await updateUserDao(userInfo) + + const data = await getUserInfoDao(userInfo.loginId) + return data.dataValues +} + +module.exports.getUserInfoService = async function (loginId) { + const data = await getUserInfoDao(loginId) + return data.dataValues } \ No newline at end of file