|
|
@@ -4,10 +4,12 @@ import { JwtService } from '@nestjs/jwt'
|
|
|
import { UsersService } from '../users/users.service'
|
|
|
import { Role } from 'src/model/role.enum'
|
|
|
import { UserRegisterDto } from 'src/users/dto/user-register.dto'
|
|
|
+import { generateKey } from '../utils/authenticator'
|
|
|
|
|
|
@Injectable()
|
|
|
export class AuthService {
|
|
|
- constructor(private readonly usersService: UsersService, private readonly jwtService: JwtService) {}
|
|
|
+ constructor(private readonly usersService: UsersService, private readonly jwtService: JwtService) {
|
|
|
+ }
|
|
|
|
|
|
async loginByPhone(loginDto: PhoneLoginDto) {
|
|
|
throw new Error('Permission denied')
|
|
|
@@ -23,8 +25,8 @@ export class AuthService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async login(username: string, password: string) {
|
|
|
- let user = await this.usersService.login(username, password)
|
|
|
+ async login(username: string, password: string, code: string) {
|
|
|
+ let user = await this.usersService.login(username, password, code)
|
|
|
if (user.roles.includes(Role.Admin)) {
|
|
|
throw new UnauthorizedException('Permission denied')
|
|
|
}
|
|
|
@@ -39,11 +41,11 @@ export class AuthService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async loginAdmin(username: string, password: string) {
|
|
|
+ async loginAdmin(username: string, password: string, code: string) {
|
|
|
// if (process.env.ALLOW_ADMIN_LOGIN !== 'true') {
|
|
|
// throw new UnauthorizedException('Permission denied')
|
|
|
// }
|
|
|
- let user = await this.usersService.login(username, password)
|
|
|
+ let user = await this.usersService.login(username, password, code)
|
|
|
// if (!user.roles.includes(Role.Admin)) {
|
|
|
// throw new UnauthorizedException('Permission denied')
|
|
|
// }
|
|
|
@@ -58,6 +60,10 @@ export class AuthService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async bindingGoogleTwoFactorValidate(username: string, password: string) {
|
|
|
+ return await this.usersService.binding(username)
|
|
|
+ }
|
|
|
+
|
|
|
async getToken(id: number) {
|
|
|
let user = await this.usersService.findById(id)
|
|
|
const payload = {
|