-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Change Email review #5688
Change Email review #5688
Conversation
Related to #5362
Reminder: If you just check with MimeKit |
@agriffard you could rebase on dev after merging #5710 |
ok, dev merged and IEmailAddressValidator used in ChangeEmailViewModel. |
src/OrchardCore.Modules/OrchardCore.Users/ViewModels/ChangeEmailViewModel.cs
Outdated
Show resolved
Hide resolved
using Microsoft.Extensions.Localization; | ||
using MimeKit; | ||
using Microsoft.Extensions.Localization; | ||
using OrchardCore.Email; | ||
|
||
namespace OrchardCore.Users.ViewModels | ||
{ | ||
public class ChangeEmailViewModel : IValidatableObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need IValidatableObject
? IEmailAddressValidator
can handle the validation logic, so you can check directly in the POST
@@ -49,7 +55,7 @@ public async Task<IActionResult> Index() | |||
|
|||
var user = await _userService.GetAuthenticatedUserAsync(User); | |||
|
|||
return View(new ChangeEmailViewModel() { Email = ((User)user).Email }); | |||
return View(new ChangeEmailViewModel(_emailAddressValidator) { Email = ((User)user).Email }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service needs to be resolved in the Vallidate method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK: Resolve EmailAddressValidator from Validate method
@@ -38,7 +38,7 @@ public class ChangeEmailController : Controller | |||
_userService = userService; | |||
_userManager = userManager; | |||
_siteService = siteService; | |||
_emailAddressValidator = emailAddressValidator ?? throw new ArgumentNullException(nameof(emailAddressValidator)); | |||
_emailAddressValidator = emailAddressValidator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we don't check from null
in constructor which is useful for public
APIs, if the intend to prevent DI from throws, it will if the service is not there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DI container will throw a DI exception before it ever reaches this null check so a null check here is unreachable code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How? I think the check need to be in services public APIs, not in controller as you said
React to @sebastienros's comments.
Related to #5362