|
|
@@ -22,6 +22,7 @@ import { ApiUserService } from '../api-users/api-user.service'
|
|
|
import { paginate, Pagination } from 'nestjs-typeorm-paginate'
|
|
|
import { Role } from '../model/role.enum'
|
|
|
import { PageRequest } from '../common/dto/page-request'
|
|
|
+import { th } from 'date-fns/locale'
|
|
|
|
|
|
@Injectable()
|
|
|
export class UsersService {
|
|
|
@@ -105,9 +106,15 @@ export class UsersService {
|
|
|
if (!isMatch) {
|
|
|
throw new UnauthorizedException('用户名或密码错误')
|
|
|
}
|
|
|
- if (!user.roles.includes(Role.Admin)) {
|
|
|
+ if (!user.roles.includes(Role.Admin) && !user.roles.includes(Role.Api)) {
|
|
|
throw new UnauthorizedException('用户名或密码错误')
|
|
|
}
|
|
|
+ if (user.roles.includes(Role.Api)) {
|
|
|
+ let apiUser = await this.apiUserService.findById(user.apiUserId)
|
|
|
+ if (apiUser.userId != apiUser.id) {
|
|
|
+ throw new UnauthorizedException('用户名或密码错误')
|
|
|
+ }
|
|
|
+ }
|
|
|
return user
|
|
|
}
|
|
|
|