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

Change Email review #5688

Merged
merged 11 commits into from
Mar 31, 2020
Merged

Change Email review #5688

merged 11 commits into from
Mar 31, 2020

Conversation

agriffard
Copy link
Member

React to @sebastienros's comments.

Related to #5362

@agriffard
Copy link
Member Author

Reminder: If you just check with MimeKit !MailboxAddress.TryParse(Email, out var emailAddress), an email without any @ would work, so I also returned un invalid email if Email.IndexOf('@') == -1.

jstedfast/MimeKit#465

@hishamco
Copy link
Member

@agriffard you could rebase on dev after merging #5710

@agriffard
Copy link
Member Author

ok, dev merged and IEmailAddressValidator used in ChangeEmailViewModel.

using Microsoft.Extensions.Localization;
using MimeKit;
using Microsoft.Extensions.Localization;
using OrchardCore.Email;

namespace OrchardCore.Users.ViewModels
{
public class ChangeEmailViewModel : IValidatableObject
Copy link
Member

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 });
Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member

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

Copy link
Member

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

Copy link
Member

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

@agriffard agriffard merged commit ece4f52 into dev Mar 31, 2020
@delete-merged-branch delete-merged-branch bot deleted the ag/changeEmailReview branch March 31, 2020 11:33
scleaver pushed a commit to kast-cloud/OrchardCore that referenced this pull request Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants