适配第二版验证码
This commit is contained in:
1 parent
564ffecfed
commit
c1451d0e6d
5 files changed
+79
-14
No files matched your search
Submodule
+1
Submodule packages/CaptchaKit added at 9122699c8b.
@@ -142,10 +142,15 @@ public sealed class AuthController(
|
|||||||
[HttpPost("login/captcha")]
|
[HttpPost("login/captcha")]
|
||||||
public async Task<ActionResult<LoginCaptchaResponse>> CreateLoginCaptcha(CancellationToken cancellationToken)
|
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(
|
return Ok(new LoginCaptchaResponse(
|
||||||
generated.Id,
|
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]
|
[AllowAnonymous]
|
||||||
@@ -155,7 +160,7 @@ public sealed class AuthController(
|
|||||||
LoginRequest request,
|
LoginRequest request,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (!await captcha.VerifyAsync(request.CaptchaId, request.CaptchaCode, cancellationToken))
|
if (!await captcha.VerifyAsync(request.CaptchaId, request.CaptchaCode, cancellationToken: cancellationToken))
|
||||||
return Unauthorized(LoginCaptchaProblem());
|
return Unauthorized(LoginCaptchaProblem());
|
||||||
var user = await userManager.FindByNameAsync(request.UserName);
|
var user = await userManager.FindByNameAsync(request.UserName);
|
||||||
if (user is null || !user.IsEnabled)
|
if (user is null || !user.IsEnabled)
|
||||||
@@ -333,7 +338,14 @@ public sealed record LoginRequest(
|
|||||||
[Required, MinLength(3), MaxLength(16)] string CaptchaCode,
|
[Required, MinLength(3), MaxLength(16)] string CaptchaCode,
|
||||||
bool IsNativeApp = false);
|
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(
|
public sealed record TotpLoginRequest(
|
||||||
[Required, MinLength(20), MaxLength(2048)] string TwoFactorTicket,
|
[Required, MinLength(20), MaxLength(2048)] string TwoFactorTicket,
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public sealed class SsoController(
|
|||||||
if (string.IsNullOrWhiteSpace(bindingIntent) &&
|
if (string.IsNullOrWhiteSpace(bindingIntent) &&
|
||||||
(string.IsNullOrWhiteSpace(captchaId) ||
|
(string.IsNullOrWhiteSpace(captchaId) ||
|
||||||
string.IsNullOrWhiteSpace(captchaCode) ||
|
string.IsNullOrWhiteSpace(captchaCode) ||
|
||||||
!await captcha.VerifyAsync(captchaId, captchaCode, cancellationToken)))
|
!await captcha.VerifyAsync(captchaId, captchaCode, cancellationToken: cancellationToken)))
|
||||||
{
|
{
|
||||||
return Unauthorized(AuthController.LoginCaptchaProblem());
|
return Unauthorized(AuthController.LoginCaptchaProblem());
|
||||||
}
|
}
|
||||||
|
|||||||
Loaded 3 of 5 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user