Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ReCaptchaMode and DetectionThreshold #17229

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ nav:
- Feeds: reference/modules/Feeds/README.md
- Commerce: https://commerce.orchardcore.net/en/latest
- Core Modules:
- Display Management: reference/core/DisplayManagement/README.md
- Audit Trail: reference/modules/AuditTrail/README.md
- Auto Setup: reference/modules/AutoSetup/README.md
- Features: reference/modules/Features/README.md
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.ReCaptcha.Configuration;
Expand All @@ -19,11 +20,14 @@ public override async Task<IDisplayResult> EditAsync(ForgotPasswordForm model, B
{
var settings = await _siteService.GetSettingsAsync<ReCaptchaSettings>();

if (!settings.IsValid())
if (!settings.ConfigurationExists())
{
return null;
}

return View("FormReCaptcha", model).Location("Content:after");
return Dynamic("ReCaptcha", (m) =>
{
m.language = CultureInfo.CurrentUICulture.Name;
}).Location("Content:after");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Globalization;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.ReCaptcha.Configuration;
using OrchardCore.ReCaptcha.Services;
using OrchardCore.Settings;
using OrchardCore.Users.Models;

Expand All @@ -10,25 +10,24 @@ namespace OrchardCore.ReCaptcha.Drivers;
public sealed class ReCaptchaLoginFormDisplayDriver : DisplayDriver<LoginForm>
{
private readonly ISiteService _siteService;
private readonly ReCaptchaService _reCaptchaService;

public ReCaptchaLoginFormDisplayDriver(
ISiteService siteService,
ReCaptchaService reCaptchaService)
public ReCaptchaLoginFormDisplayDriver(ISiteService siteService)
{
_siteService = siteService;
_reCaptchaService = reCaptchaService;
}

public override async Task<IDisplayResult> EditAsync(LoginForm model, BuildEditorContext context)
{
var _reCaptchaSettings = await _siteService.GetSettingsAsync<ReCaptchaSettings>();
var settings = await _siteService.GetSettingsAsync<ReCaptchaSettings>();

if (!_reCaptchaSettings.IsValid() || !_reCaptchaService.IsThisARobot())
if (!settings.ConfigurationExists())
{
return null;
}

return View("FormReCaptcha", model).Location("Content:after");
return Dynamic("ReCaptcha", (m) =>
{
m.language = CultureInfo.CurrentUICulture.Name;
}).Location("Content:after");
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.ReCaptcha.Configuration;
Expand All @@ -19,11 +20,14 @@ public override async Task<IDisplayResult> EditAsync(ResetPasswordForm model, Bu
{
var settings = await _siteService.GetSettingsAsync<ReCaptchaSettings>();

if (!settings.IsValid())
if (!settings.ConfigurationExists())
{
return null;
}

return View("FormReCaptcha", model).Location("Content:after");
return Dynamic("ReCaptcha", (m) =>
{
m.language = CultureInfo.CurrentUICulture.Name;
}).Location("Content:after");
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.ReCaptcha.Configuration;
Expand All @@ -19,11 +20,14 @@ public override async Task<IDisplayResult> EditAsync(RegisterUserForm model, Bui
{
var settings = await _siteService.GetSettingsAsync<ReCaptchaSettings>();

if (!settings.IsValid())
if (!settings.ConfigurationExists())
{
return null;
}

return View("FormReCaptcha", model).Location("Content:after");
return Dynamic("ReCaptcha", (m) =>
{
m.language = CultureInfo.CurrentUICulture.Name;
}).Location("Content:after");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override IDisplayResult Display(ReCaptchaPart part, BuildPartDisplayConte
return Initialize<ReCaptchaPartViewModel>("ReCaptchaPart", async model =>
{
var settings = await _siteService.GetSettingsAsync<ReCaptchaSettings>();
model.SettingsAreConfigured = settings.IsValid();
model.SettingsAreConfigured = settings.ConfigurationExists();
}).Location("Detail", "Content");
}

Expand All @@ -29,7 +29,7 @@ public override IDisplayResult Edit(ReCaptchaPart part, BuildPartEditorContext c
return Initialize<ReCaptchaPartViewModel>("ReCaptchaPart_Fields_Edit", async model =>
{
var settings = await _siteService.GetSettingsAsync<ReCaptchaSettings>();
model.SettingsAreConfigured = settings.IsValid();
model.SettingsAreConfigured = settings.ConfigurationExists();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using OrchardCore.ReCaptcha.Services;
using OrchardCore.Users;
using OrchardCore.Users.Events;

namespace OrchardCore.ReCaptcha.Users.Handlers;

public class LoginFormEventEventHandler : LoginFormEventBase
public sealed class LoginFormEventEventHandler : LoginFormEventBase
{
private readonly ReCaptchaService _reCaptchaService;

Expand All @@ -13,34 +12,6 @@ public LoginFormEventEventHandler(ReCaptchaService reCaptchaService)
_reCaptchaService = reCaptchaService;
}

public override Task LoggedInAsync(IUser user)
{
_reCaptchaService.ThisIsAHuman();

return Task.CompletedTask;
}

public override Task LoggingInAsync(string userName, Action<string, string> reportError)
{
if (_reCaptchaService.IsThisARobot())
{
return _reCaptchaService.ValidateCaptchaAsync(reportError);
}

return Task.CompletedTask;
}

public override Task LoggingInFailedAsync(string userName)
{
_reCaptchaService.MaybeThisIsARobot();

return Task.CompletedTask;
}

public override Task LoggingInFailedAsync(IUser user)
{
_reCaptchaService.MaybeThisIsARobot();

return Task.CompletedTask;
}
=> _reCaptchaService.ValidateCaptchaAsync(reportError);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,18 @@

namespace OrchardCore.ReCaptcha.Users.Handlers;

public class PasswordRecoveryFormEventEventHandler : IPasswordRecoveryFormEvents
public sealed class PasswordRecoveryFormEventEventHandler : PasswordRecoveryFormEvents
{
private readonly ReCaptchaService _recaptchaService;
private readonly ReCaptchaService _reCaptchaService;

public PasswordRecoveryFormEventEventHandler(ReCaptchaService recaptchaService)
public PasswordRecoveryFormEventEventHandler(ReCaptchaService reCaptchaService)
{
_recaptchaService = recaptchaService;
_reCaptchaService = reCaptchaService;
}

public Task RecoveringPasswordAsync(Action<string, string> reportError)
{
return _recaptchaService.ValidateCaptchaAsync(reportError);
}

public Task PasswordResetAsync(PasswordRecoveryContext context)
{
return Task.CompletedTask;
}
public override Task RecoveringPasswordAsync(Action<string, string> reportError)
=> _reCaptchaService.ValidateCaptchaAsync(reportError);

public Task ResettingPasswordAsync(Action<string, string> reportError)
{
return _recaptchaService.ValidateCaptchaAsync(reportError);
}

public Task PasswordRecoveredAsync(PasswordRecoveryContext context)
{
return Task.CompletedTask;
}
public override Task ResettingPasswordAsync(Action<string, string> reportError)
=> _reCaptchaService.ValidateCaptchaAsync(reportError);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace OrchardCore.ReCaptcha.Users.Handlers;

public class RegistrationFormEventHandler : RegistrationFormEventsBase
public sealed class RegistrationFormEventHandler : RegistrationFormEventsBase
{
private readonly ReCaptchaService _reCaptchaService;

public RegistrationFormEventHandler(ReCaptchaService recaptchaService)
public RegistrationFormEventHandler(ReCaptchaService reCaptchaService)
{
_reCaptchaService = recaptchaService;
_reCaptchaService = reCaptchaService;
}

public override Task RegistrationValidationAsync(Action<string, string> reportError)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="mb-3">
<captcha mode="AlwaysShow" language="@Orchard.CultureName()" />
<captcha language="@Orchard.CultureName()" />
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

namespace OrchardCore.Users.AuditTrail.ResetPassword;

public class UserResetPasswordEventHandler : IPasswordRecoveryFormEvents
public sealed class UserResetPasswordEventHandler : PasswordRecoveryFormEvents
{
private readonly IAuditTrailManager _auditTrailManager;
private readonly IServiceProvider _serviceProvider;

private UserManager<IUser> _userManager;

public UserResetPasswordEventHandler(
Expand All @@ -22,19 +23,12 @@ public UserResetPasswordEventHandler(
_serviceProvider = serviceProvider;
}

public Task PasswordRecoveredAsync(PasswordRecoveryContext context)
public override Task PasswordRecoveredAsync(PasswordRecoveryContext context)
=> RecordAuditTrailEventAsync(UserResetPasswordAuditTrailEventConfiguration.PasswordRecovered, context.User);

public Task PasswordResetAsync(PasswordRecoveryContext context)
public override Task PasswordResetAsync(PasswordRecoveryContext context)
=> RecordAuditTrailEventAsync(UserResetPasswordAuditTrailEventConfiguration.PasswordReset, context.User);

#region Unused events

public Task RecoveringPasswordAsync(Action<string, string> reportError) => Task.CompletedTask;

public Task ResettingPasswordAsync(Action<string, string> reportError) => Task.CompletedTask;

#endregion
private async Task RecordAuditTrailEventAsync(string name, IUser user)
{
var userName = user.UserName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ public async Task<IActionResult> Login(string returnUrl = null)
[ActionName(nameof(Login))]
public async Task<IActionResult> LoginPOST(string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;

var model = new LoginForm();

var formShape = await _loginFormDisplayManager.UpdateEditorAsync(model, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty);

var loginSettings = await _siteService.GetSettingsAsync<LoginSettings>();

if (loginSettings.DisableLocalLogin)
{
ModelState.AddModelError(string.Empty, S["Local login is disabled."]);
await _notifier.ErrorAsync(H["Local login is disabled."]);

return View(formShape);
return RedirectToAction(nameof(Login), new { returnUrl });
}

ViewData["ReturnUrl"] = returnUrl;

var model = new LoginForm();

var formShape = await _loginFormDisplayManager.UpdateEditorAsync(model, _updateModelAccessor.ModelUpdater, false);

await _accountEvents.InvokeAsync((e, model, modelState) => e.LoggingInAsync(model.UserName, (key, message) => modelState.AddModelError(key, message)), model, ModelState, _logger);

IUser user = null;
Expand Down
1 change: 1 addition & 0 deletions src/OrchardCore.Themes/TheAdmin/Assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Assets/scss/login.scss"
],
"watch": [
"Assets/scss/componenets/_recaptcha.scss",
"Assets/scss/componenets/_validations.scss"
],
"output": "wwwroot/css/login.css"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.g-recaptcha {
margin-bottom: 1rem;
}
1 change: 1 addition & 0 deletions src/OrchardCore.Themes/TheAdmin/Assets/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@import 'components/navbar';
@import 'components/nouislider';
@import 'components/pager';
@import 'components/recaptcha';
@import 'components/sortable';
@import 'components/tabs';
@import 'components/trumbowyg';
Expand Down
1 change: 1 addition & 0 deletions src/OrchardCore.Themes/TheAdmin/Assets/scss/login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ body, html {
margin: auto;
}

@import 'components/recaptcha';
@import 'components/validations';
4 changes: 4 additions & 0 deletions src/OrchardCore.Themes/TheAdmin/wwwroot/css/TheAdmin.css
Original file line number Diff line number Diff line change
Expand Up @@ -8461,6 +8461,10 @@ ul.pager {
justify-content: center;
}

.g-recaptcha {
margin-bottom: 1rem;
}

/*
IMPORTANT: Never import Bootstrap directly into the theme.
TheAdmin.css will depend on Bootstrap, but we never want to compile it.
Expand Down

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/OrchardCore.Themes/TheAdmin/wwwroot/css/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ body, html {
margin: auto;
}

.g-recaptcha {
margin-bottom: 1rem;
}

span.field-validation-error {
width: 100%;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Themes/TheAdmin/wwwroot/css/login.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ By Orchard Core Team
@import "modules/_flow.scss";
@import "modules/_messages.scss";
@import "modules/_widgets.scss";
@import "modules/_recaptcha.scss";
@import "modules/_pager.scss";
@import "modules/_taxonomy.scss";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.g-recaptcha {
margin-bottom: 1rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ By Orchard Core Team
}
}

.g-recaptcha {
margin-bottom: 1rem;
}

ul.pager {
display: flex;
padding-left: 0;
Expand Down
Loading
Loading