1
+ using Microsoft . AspNetCore . Identity ;
1
2
using OrchardCore . ReCaptcha . Services ;
2
3
using OrchardCore . Users ;
3
4
using OrchardCore . Users . Events ;
@@ -7,10 +8,12 @@ namespace OrchardCore.ReCaptcha.Users.Handlers;
7
8
public class LoginFormEventEventHandler : ILoginFormEvent
8
9
{
9
10
private readonly ReCaptchaService _reCaptchaService ;
11
+ private readonly SignInManager < IUser > _signInManager ;
10
12
11
- public LoginFormEventEventHandler ( ReCaptchaService reCaptchaService )
13
+ public LoginFormEventEventHandler ( ReCaptchaService reCaptchaService , SignInManager < IUser > signInManager )
12
14
{
13
15
_reCaptchaService = reCaptchaService ;
16
+ _signInManager = signInManager ;
14
17
}
15
18
16
19
public Task IsLockedOutAsync ( IUser user )
@@ -23,14 +26,16 @@ public Task LoggedInAsync(IUser user)
23
26
return Task . CompletedTask ;
24
27
}
25
28
26
- public Task LoggingInAsync ( string userName , Action < string , string > reportError )
29
+ public async Task LoggingInAsync ( string userName , Action < string , string > reportError )
27
30
{
28
- if ( _reCaptchaService . IsThisARobot ( ) )
31
+ // When logging in via an external provider, authentication security is already handled by the provider.
32
+ // Therefore, using a CAPTCHA is unnecessary and impractical, as users wouldn't be able to complete it anyway.
33
+ if ( ! _reCaptchaService . IsThisARobot ( ) || await _signInManager . GetExternalLoginInfoAsync ( ) != null )
29
34
{
30
- return _reCaptchaService . ValidateCaptchaAsync ( reportError ) ;
35
+ return ;
31
36
}
32
37
33
- return Task . CompletedTask ;
38
+ await _reCaptchaService . ValidateCaptchaAsync ( reportError ) ;
34
39
}
35
40
36
41
public Task LoggingInFailedAsync ( string userName )
0 commit comments