neozhu / CleanArchitectureWithBlazorServer

This is a repository for creating a Blazor Server dashboard application following the principles of Clean Architecture
https://architecture.blazorserver.com/
MIT License
763 stars 213 forks source link

Register confirmation is not working #708

Open Alywan opened 1 month ago

Alywan commented 1 month ago

We do not receive any registration confirmation when registering a new user. Is this related to the fact that you deleted the [IdentityNoOpEmailSender.cs] file ?

neozhu commented 1 month ago

image Don't forget to configure these parameters for your SMTP server.

Alywan commented 1 month ago

It's configured correctly, other e-mails are working fine. In my case : the register confirmation e-mail is not sent via e-mail.

I have to go with the Admin account, set the new registered user as "Active", and then, he will get the e-mail to reset the password. After that, though, he cannot login, because in the database the "EmailConfirmed" value is 0.

btw, why do i have to setup a password at signup, and after that, when the user gets the confirmation e-mail, he has to reset the password again ?

Alywan commented 1 month ago

Btw, this is the error message we get : [14:08:35 ERR ] Failed to send templated email. Subject: Account Activation Required, Template: _useractivation. An exception occurred. System.ObjectDisposedException: Cannot access a disposed object. Object name: 'IServiceProvider'. at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException() at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.FluentEmailServiceCollectionExtensions.<>cDisplayClass0_0.b0(IServiceProvider x) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>cDisplayClass2_0.b0(ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at FluentEmail.Core.FluentEmailFactory.Create() at PropertyManagement.Infrastructure.Services.MailService.SendAsync(String to, String subject, String template, Object model) in D:\Dev\xxx\src\Infrastructure\Services\MailService.cs:line 71 at PropertyManagement.Application.Features.Identity.Notifications.UserActivation.UserActivationNotificationHandler.Handle(UserActivationNotification notification, CancellationToken cancellationToken) in D:\Dev\xxx\src\Application\Features\Identity\Notifications\UserActivationCommand.cs:line 29

neozhu commented 1 month ago

Can you debug and fix this error? also you can check the email template file in the folder \Resources\EmailTemplates_authenticatorcode.cshtml

Bram1903 commented 1 month ago

Can you debug and fix this error?

also you can check the email template file in the folder \Resources\EmailTemplates_authenticatorcode.cshtml

Looks like the dependency container already disposes the service before the service is needed. I would have tried to fix this myself, but I'm currently on vacation to Japan for 3 weeks 😅

Alywan commented 1 month ago

Can you debug and fix this error? also you can check the email template file in the folder \Resources\EmailTemplates_authenticatorcode.cshtml

Hard to debug... I have all the files in the correct place.

At this line of code in my MailService i get that error :

        else
        {
            return _fluentEmailFactory
                .Create()
                .To(to)
                .Subject(subject)
                .UsingTemplateFromEmbedded(string.Format(TemplatePath, template), model, Assembly.GetEntryAssembly())
                .SendAsync();
        }