diff --git a/src/apis/auth/local-auth.controller.ts b/src/apis/auth/local-auth.controller.ts index b054941..eb34556 100755 --- a/src/apis/auth/local-auth.controller.ts +++ b/src/apis/auth/local-auth.controller.ts @@ -10,21 +10,12 @@ import { AppError } from '@/lib/error' import { genRandom32BitsHexString, genUniqString, genPBK } from '@/lib/encryption/crypto' import { Types } from 'mongoose' -/** 用户登录信息 */ interface LoginInfo { - /** 用户邮箱 */ email: string - /** 用户密码 */ password: string } -/** 用户注册信息 */ -interface RegisterInfo { - /** 用户注册邮箱 */ - email: string - /** 用户密码 */ - password: string -} +type RegisterInfo = LoginInfo class LocalAuthController { public static async login(req: Request, res: Response, next: NextFunction) { @@ -72,11 +63,9 @@ class LocalAuthController { const salt = genRandom32BitsHexString() const password = genPBK(registerInfo.password, salt) - const username = `user-${genUniqString()}` const newUserProps: Partial = { email: registerInfo.email, - username, password, salt } diff --git a/src/apis/user/user.controller.ts b/src/apis/user/user.controller.ts index 7cb002d..3a44448 100755 --- a/src/apis/user/user.controller.ts +++ b/src/apis/user/user.controller.ts @@ -9,17 +9,14 @@ import UserStore from '../../business/user/user.store' * 获取用户主页信息 */ export async function getProfile(req: Request, res: Response) { + const user = req.user + const [updateSessionInfoErr] = await callAsync( SessionInfoDao.findOneAndUpdate({ sessionId: req.sessionID }, { activeAt: new Date() }) ) - if (updateSessionInfoErr) return res.status(500).send(`更新会话信息失败 => ${updateSessionInfoErr}`) - - const [findUserInfoErr, userInfo] = await callAsync( - UserDao.findOne({ _id: req.user._id }, { activeAt: new Date() }, { lean: true }) - ) - if (findUserInfoErr) return res.status(500).send(`获取用户信息失败 => ${findUserInfoErr}`) + if (updateSessionInfoErr) console.log(`更新会话信息失败 => ${updateSessionInfoErr}`) - const profile = _.pick(userInfo, UserStore.theProfileKeys()) + const profile = _.pick(user, UserStore.theProfileKeys()) res.send(profile) } diff --git a/src/business/auth/local/local-auth.store.ts b/src/business/auth/local/local-auth.store.ts index 4ee13d9..e841dd2 100755 --- a/src/business/auth/local/local-auth.store.ts +++ b/src/business/auth/local/local-auth.store.ts @@ -2,7 +2,7 @@ const LocalAuthStore = { /** 登录信息字段名 */ theLoginInfoKeys: () => ['email', 'password'], /** 注册信息字段名 */ - theRegisterInfoKeys: () => ['email', 'password'] + theRegisterInfoKeys: () => [...LocalAuthStore.theLoginInfoKeys()] } export { LocalAuthStore } diff --git a/src/business/user/user.store.ts b/src/business/user/user.store.ts index 87915a8..b8d0b13 100755 --- a/src/business/user/user.store.ts +++ b/src/business/user/user.store.ts @@ -2,7 +2,7 @@ const UserStore = { /** * 用户主页属性键名。 */ - theProfileKeys: () => ['email', 'username', 'nickname', 'avatar', 'roles'] + theProfileKeys: () => ['email', 'username', 'nickname', 'avatar', 'role'] } export default UserStore diff --git a/src/entities/auth/user.model.ts b/src/entities/auth/user.model.ts index 995c62c..d7f5dc5 100755 --- a/src/entities/auth/user.model.ts +++ b/src/entities/auth/user.model.ts @@ -8,15 +8,15 @@ export interface UserProps extends App.User { /** * 用户名 */ - username: string + //username: string /** * 用户昵称 */ - nickname?: string + //nickname?: string /** * 用户头像保存路径 */ - avatar?: string + //avatar?: string /** * 密码 */ @@ -109,14 +109,14 @@ const userSchema = new Schema