|
@@ -11,6 +11,7 @@ import { LoginDTO, LoginType, UPwdDTO } from '../interface/login.interface';
|
|
import { Opera } from '../frame/dbOpera';
|
|
import { Opera } from '../frame/dbOpera';
|
|
import { Admin } from '../entity/system/admin.entity';
|
|
import { Admin } from '../entity/system/admin.entity';
|
|
import * as bcrypt from 'bcryptjs';
|
|
import * as bcrypt from 'bcryptjs';
|
|
|
|
+import { User } from '../entity/system/user.entity';
|
|
|
|
|
|
@Provide()
|
|
@Provide()
|
|
export class LoginService {
|
|
export class LoginService {
|
|
@@ -29,6 +30,8 @@ export class LoginService {
|
|
|
|
|
|
@InjectEntityModel(Admin)
|
|
@InjectEntityModel(Admin)
|
|
adminModel: Repository<Admin>;
|
|
adminModel: Repository<Admin>;
|
|
|
|
+ @InjectEntityModel(User)
|
|
|
|
+ userModel: Repository<User>;
|
|
|
|
|
|
async onePointLogin(loginVo) {
|
|
async onePointLogin(loginVo) {
|
|
const { id, role } = loginVo;
|
|
const { id, role } = loginVo;
|
|
@@ -53,10 +56,8 @@ export class LoginService {
|
|
async loginByAccount(data: LoginDTO, type: LoginType) {
|
|
async loginByAccount(data: LoginDTO, type: LoginType) {
|
|
let model;
|
|
let model;
|
|
if (type === LoginType.Admin) model = this.adminModel;
|
|
if (type === LoginType.Admin) model = this.adminModel;
|
|
- // TODO: 缺少user登录映射到model变量上
|
|
|
|
- // const user = await model.findOne({ where: { account: Equal(data.account) }, select: ['password'] });
|
|
|
|
|
|
+ else model = this.userModel;
|
|
const user = await model.createQueryBuilder('t').where('t.account = :account', { account: data.account }).addSelect('t.password').getOne();
|
|
const user = await model.createQueryBuilder('t').where('t.account = :account', { account: data.account }).addSelect('t.password').getOne();
|
|
- // const user = await model.findOne({ account: data.account }, '+password').lean();
|
|
|
|
if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
|
|
if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
|
|
await this.checkAccountCanLogin(user, type);
|
|
await this.checkAccountCanLogin(user, type);
|
|
const result = bcrypt.compareSync(data.password, user.password);
|
|
const result = bcrypt.compareSync(data.password, user.password);
|