This commit is contained in:
SepehrYahyaee
2026-05-24 10:10:17 +03:30
parent 91221a6848
commit af875a4773
20 changed files with 439 additions and 9 deletions

View File

@@ -5,9 +5,12 @@ import {
Param,
Patch,
Post,
Query,
Req,
Res,
UseGuards,
} from "@nestjs/common";
import type { Response } from "express";
import {
ApiBody,
ApiAcceptedResponse,
@@ -17,6 +20,9 @@ import {
ApiBearerAuth,
} from "@nestjs/swagger";
import { ActorAuthService } from "src/auth/auth-services/actor.auth.service";
import { CaptchaAccountService } from "src/auth/auth-services/captcha-account.service";
import { CaptchaResponseDto } from "src/auth/dto/captcha-response.dto";
import { GetActorCaptchaQueryDto } from "src/auth/dto/get-actor-captcha.dto";
import {
ForgetPasswordSendCodeDto,
ForgetPasswordVerifyCodeDto,
@@ -37,7 +43,42 @@ import { CurrentUser } from "src/decorators/user.decorator";
@Controller("actor")
@ApiTags("actor")
export class ActorAuthController {
constructor(private readonly actorAuthService: ActorAuthService) {}
constructor(
private readonly actorAuthService: ActorAuthService,
private readonly captchaAccountService: CaptchaAccountService,
) {}
@Get("captcha")
@ApiOperation({
summary: "Get login captcha for an actor account",
description:
"Returns an SVG captcha stored on the actor record.\n\n" +
"**Viewing the image:** Swagger displays `image` as plain text. To see the captcha:\n" +
"- Add `format=raw` and open the request URL in a new browser tab, or\n" +
"- Copy the full `image` value from the JSON response and paste it into the browser address bar, or\n" +
"- In your app: `<img src={response.image} alt=\"captcha\" />`\n\n" +
"Type the characters shown in the image into the `captcha` field on POST /actor/login.",
})
@ApiResponse({ status: 200, type: CaptchaResponseDto })
async getCaptcha(
@Query() query: GetActorCaptchaQueryDto,
@Res({ passthrough: true }) res: Response,
) {
const result = await this.captchaAccountService.issueActorCaptcha(
query.username,
query.role,
);
if (query.format === "raw") {
const base64 = result.image.replace(/^data:image\/svg\+xml;base64,/, "");
const svg = Buffer.from(base64, "base64").toString("utf8");
res.type("image/svg+xml");
res.send(svg);
return;
}
return result;
}
/**
* @deprecated Use the unified actor onboarding flow instead. This endpoint
@@ -113,6 +154,7 @@ export class ActorAuthController {
role: "company",
username: "saman_insurer@gmail.com",
password: "123321",
captcha: "a7bx2",
},
},
expert: {
@@ -122,6 +164,7 @@ export class ActorAuthController {
role: "expert",
username: "blame@gmail.com",
password: "123321",
captcha: "a7bx2",
},
},
damage_expert: {
@@ -131,6 +174,7 @@ export class ActorAuthController {
role: "damage_expert",
username: "claim@gmail.com",
password: "123321",
captcha: "a7bx2",
},
},
},