Base solution for your next web application

Activities of "eamonkeane"

Hey,

I've also had success with sendgrid recently

See my answer here

https://support.aspnetzero.com/QA/Questions/4661/Is-anyone-using-SendGrid-emails-successfully#answer-efedb2ba-e4a5-4118-5735-39f728ca6d9a

Hey Mitch,

I'm also using sendgrid.

However I use the following settings.

Default from (sender) email address address of choice Default from (sender) display name displayname of choice SMTP host smtp.sendgrid.net SMTP port 465 Use SSL checked Use default credentials unchecked Domain name sendgrid.net User name apikey Password api key generated in sendgrid.

*** If you are testing this code locally and you're running in debug mode, the application will not send the emails, only log them.

To get around this, i just commented out this code in {YourProjectName}.CoreModule.cs

if (DebugHelper.IsDebug)
            {
                //Disabling email sending in debug mode
                //Configuration.ReplaceService<IEmailSender, NullEmailSender>(DependencyLifeStyle.Transient);
            }

I would like to add my code here to help anyone that comes across this thread.

I created a custom UserAccount repository with a new method which ignores the IMustHaveTenant filter.

I then modified the Authenticate method within the TokenAuthController

  public async Task<AuthenticateResultModel> Authenticate([FromBody] AuthenticateModel model)
        {
            if (UseCaptchaOnLogin())
            {
                await ValidateReCaptcha(model.CaptchaResponse);
            }

            var user = await _userAccountRepository.FindByUsernameOrEmailAddressIgnoreTenant(model.UserNameOrEmailAddress);

            var userTenantId = user.TenantId;

               var tenancyNameOrNull =
                userTenantId.HasValue ? _tenantCache.GetOrNull(userTenantId.Value)?.TenancyName : null;

            var loginResult = await GetLoginResultAsync(
                model.UserNameOrEmailAddress,
                model.Password,
                tenancyNameOrNull
            );
            ..................
            ..........

Custom UserAccountRepository

public class UserAccountRepository: RinavoreRepositoryBase<UserAccount, long>, IUserAccountRepository
    {
        private readonly IDbContextProvider<RinavoreDbContext> _contextProvider;
        private readonly IUnitOfWorkManager _unitOfWorkManager;

        public UserAccountRepository(IDbContextProvider<RinavoreDbContext> contextProvider, IUnitOfWorkManager unitOfWorkManager):base(contextProvider)
        {
            _contextProvider = contextProvider;
            _unitOfWorkManager = unitOfWorkManager;
        }

        public Task<UserAccount> FindByUsernameOrEmailAddressIgnoreTenant(string usernameOrEmailAddress)
        {
            var context = _contextProvider.GetDbContext();

            using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MustHaveTenant))
            {
                var user = context.UserAccounts.FirstOrDefaultAsync(ua => ua.EmailAddress == usernameOrEmailAddress || ua.UserName == usernameOrEmailAddress);

                return user;
            }
        }
    }
Showing 1 to 3 of 3 entries