* @description: 校验用户信息 * @param {LoginParamsDto} loginParams * @author: 白雾茫茫丶
(
loginParams: LoginParamsDto,
session: SessionTypes,
)
| 118 | * @author: 白雾茫茫丶 |
| 119 | */ |
| 120 | async validateUser( |
| 121 | loginParams: LoginParamsDto, |
| 122 | session: SessionTypes, |
| 123 | ): Promise<responseResult> { |
| 124 | // 解构参数 |
| 125 | const { type, user_name, password, phone, verifyCode } = loginParams; |
| 126 | // 判断参数是否正确 |
| 127 | if (!type) { |
| 128 | return responseMessage({}, '参数不正确!', -1); |
| 129 | } |
| 130 | // 判断是否是用户登录,否则是手机登录 |
| 131 | const isAccount = type === 'account'; |
| 132 | // 查询条件 |
| 133 | const where: WhereOptions = isAccount ? { user_name } : { phone }; |
| 134 | // 查找用户 |
| 135 | const userInfo = await this.userModel.findOne({ where }); |
| 136 | // 根据登录类型执行不同的处理 |
| 137 | switch (type) { |
| 138 | // 用户名登录 |
| 139 | case 'account': |
| 140 | // 根据用户信息不同,返回相应的信息 |
| 141 | if (session.verifyCode.toUpperCase() !== verifyCode.toUpperCase()) { |
| 142 | return responseMessage({}, '验证码不正确!', -1); |
| 143 | } else if (!userInfo) { |
| 144 | return responseMessage({}, '用户不存在!', -1); |
| 145 | } else if (userInfo.password !== password) { |
| 146 | return responseMessage({}, '密码不正确!', -1); |
| 147 | } else if (!userInfo.status) { |
| 148 | return responseMessage({}, '当前用户已被禁用,请联系管理员!', -1); |
| 149 | } |
| 150 | // 手机登录 |
| 151 | case 'mobile': |
| 152 | if (!userInfo) { |
| 153 | return responseMessage({}, '手机号码不存在!', -1); |
| 154 | } |
| 155 | } |
| 156 | return responseMessage(userInfo, '登录成功!'); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @description: 用户退出当前登录 |
no test coverage detected