适配第二版验证码
This commit is contained in:
1 parent
564ffecfed
commit
c1451d0e6d
5 files changed
+79
-14
No files matched your search
@@ -142,10 +142,15 @@ public sealed class AuthController(
|
||||
[HttpPost("login/captcha")]
|
||||
public async Task<ActionResult<LoginCaptchaResponse>> CreateLoginCaptcha(CancellationToken cancellationToken)
|
||||
{
|
||||
var generated = await captcha.CreateAsync(cancellationToken);
|
||||
var generated = await captcha.CreateAsync(cancellationToken: cancellationToken);
|
||||
return Ok(new LoginCaptchaResponse(
|
||||
generated.Id,
|
||||
$"data:{generated.ContentType};base64,{Convert.ToBase64String(generated.ImageBytes)}"));
|
||||
generated.Type.ToString(),
|
||||
generated.Prompt,
|
||||
generated.Choices?.Select(x => new LoginCaptchaChoice(x.Id, x.Label)).ToList(),
|
||||
generated.ImageBytes is null || string.IsNullOrWhiteSpace(generated.ContentType)
|
||||
? null
|
||||
: $"data:{generated.ContentType};base64,{Convert.ToBase64String(generated.ImageBytes)}"));
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
@@ -155,7 +160,7 @@ public sealed class AuthController(
|
||||
LoginRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (!await captcha.VerifyAsync(request.CaptchaId, request.CaptchaCode, cancellationToken))
|
||||
if (!await captcha.VerifyAsync(request.CaptchaId, request.CaptchaCode, cancellationToken: cancellationToken))
|
||||
return Unauthorized(LoginCaptchaProblem());
|
||||
var user = await userManager.FindByNameAsync(request.UserName);
|
||||
if (user is null || !user.IsEnabled)
|
||||
@@ -333,7 +338,14 @@ public sealed record LoginRequest(
|
||||
[Required, MinLength(3), MaxLength(16)] string CaptchaCode,
|
||||
bool IsNativeApp = false);
|
||||
|
||||
public sealed record LoginCaptchaResponse(string CaptchaId, string ImageData);
|
||||
public sealed record LoginCaptchaResponse(
|
||||
string CaptchaId,
|
||||
string Type,
|
||||
string? Prompt,
|
||||
IReadOnlyList<LoginCaptchaChoice>? Choices,
|
||||
string? ImageData);
|
||||
|
||||
public sealed record LoginCaptchaChoice(string Id, string Label);
|
||||
|
||||
public sealed record TotpLoginRequest(
|
||||
[Required, MinLength(20), MaxLength(2048)] string TwoFactorTicket,
|
||||
|
||||
@@ -59,7 +59,7 @@ public sealed class SsoController(
|
||||
if (string.IsNullOrWhiteSpace(bindingIntent) &&
|
||||
(string.IsNullOrWhiteSpace(captchaId) ||
|
||||
string.IsNullOrWhiteSpace(captchaCode) ||
|
||||
!await captcha.VerifyAsync(captchaId, captchaCode, cancellationToken)))
|
||||
!await captcha.VerifyAsync(captchaId, captchaCode, cancellationToken: cancellationToken)))
|
||||
{
|
||||
return Unauthorized(AuthController.LoginCaptchaProblem());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user