From ea5a1152fd400ce99deb7fe98a0fe7cdf45a8cb7 Mon Sep 17 00:00:00 2001 From: P-Jhao <113034340+P-Jhao@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:37:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/userDao.js | 8 ++++++++ routes/user.js | 26 ++++++++------------------ services/userService.js | 24 +++++++++++------------- 3 files changed, 27 insertions(+), 31 deletions(-) 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