|
@@ -10,6 +10,7 @@ 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) {
|
|
async loginByPhone(loginDto: PhoneLoginDto) {
|
|
|
|
|
+ throw new Error('Permission denied')
|
|
|
let user = await this.usersService.loginByPhone(loginDto.phone, loginDto.code, loginDto.invitor)
|
|
let user = await this.usersService.loginByPhone(loginDto.phone, loginDto.code, loginDto.invitor)
|
|
|
const payload = {
|
|
const payload = {
|
|
|
username: user.username,
|
|
username: user.username,
|
|
@@ -24,6 +25,9 @@ export class AuthService {
|
|
|
|
|
|
|
|
async login(username: string, password: string) {
|
|
async login(username: string, password: string) {
|
|
|
let user = await this.usersService.login(username, password)
|
|
let user = await this.usersService.login(username, password)
|
|
|
|
|
+ if (user.roles.includes(Role.Admin)) {
|
|
|
|
|
+ throw new UnauthorizedException('Permission denied')
|
|
|
|
|
+ }
|
|
|
const payload = {
|
|
const payload = {
|
|
|
username: user.username,
|
|
username: user.username,
|
|
|
sub: user.id,
|
|
sub: user.id,
|
|
@@ -36,10 +40,13 @@ export class AuthService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async loginAdmin(username: string, password: string) {
|
|
async loginAdmin(username: string, password: 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)
|
|
|
- /*if (!user.roles.includes(Role.Admin)) {
|
|
|
|
|
|
|
+ if (!user.roles.includes(Role.Admin)) {
|
|
|
throw new UnauthorizedException('Permission denied')
|
|
throw new UnauthorizedException('Permission denied')
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
const payload = {
|
|
const payload = {
|
|
|
username: user.username,
|
|
username: user.username,
|
|
|
sub: user.id,
|
|
sub: user.id,
|
|
@@ -64,6 +71,7 @@ export class AuthService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async register(register: UserRegisterDto) {
|
|
async register(register: UserRegisterDto) {
|
|
|
|
|
+ throw new Error('Permission denied')
|
|
|
return await this.usersService.register(register)
|
|
return await this.usersService.register(register)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|