|
|
@ -1,6 +1,7 @@ |
|
|
|
import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorator'; |
|
|
|
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; |
|
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
|
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|
|
|
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
|
|
|
import { |
|
|
|
AccessTokenResponse, |
|
|
@ -40,6 +41,7 @@ export class UserController { |
|
|
|
public constructor( |
|
|
|
private readonly configurationService: ConfigurationService, |
|
|
|
private readonly jwtService: JwtService, |
|
|
|
private readonly prismaService: PrismaService, |
|
|
|
private readonly propertyService: PropertyService, |
|
|
|
@Inject(REQUEST) private readonly request: RequestWithUser, |
|
|
|
private readonly userService: UserService |
|
|
@ -51,10 +53,10 @@ export class UserController { |
|
|
|
public async deleteOwnUser( |
|
|
|
@Body() data: DeleteOwnUserDto |
|
|
|
): Promise<UserModel> { |
|
|
|
const hashedAccessToken = this.userService.createAccessToken( |
|
|
|
data.accessToken, |
|
|
|
this.configurationService.get('ACCESS_TOKEN_SALT') |
|
|
|
); |
|
|
|
const hashedAccessToken = this.userService.createAccessToken({ |
|
|
|
password: data.accessToken, |
|
|
|
salt: this.configurationService.get('ACCESS_TOKEN_SALT') |
|
|
|
}); |
|
|
|
|
|
|
|
const [user] = await this.userService.users({ |
|
|
|
where: { accessToken: hashedAccessToken, id: this.request.user.id } |
|
|
@ -89,14 +91,20 @@ export class UserController { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Post(':id/access-token') |
|
|
|
@HasPermission(permissions.accessAdminControl) |
|
|
|
@Post(':id/access-token') |
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|
|
|
public async generateAccessToken( |
|
|
|
@Param('id') id: string |
|
|
|
): Promise<AccessTokenResponse> { |
|
|
|
const { accessToken } = await this.userService.generateAccessToken({ |
|
|
|
userId: id |
|
|
|
const { accessToken, hashedAccessToken } = |
|
|
|
this.userService.generateAccessToken({ |
|
|
|
userId: id |
|
|
|
}); |
|
|
|
|
|
|
|
await this.prismaService.user.update({ |
|
|
|
data: { accessToken: hashedAccessToken }, |
|
|
|
where: { id } |
|
|
|
}); |
|
|
|
|
|
|
|
return { accessToken }; |
|
|
|