Beispiel #1
0
        public async Task <SendPasswordResetEmailResult> SendPasswordResetEmail(SendPasswordResetEmailCommand config, AppUser user)
        {
            var link = UrlHelperExtensions.Action(
                _urlHelper,                                              /*Url Helper*/
                "PasswordResetConfirmation",                             /*Action*/
                "Authenticate",                                          /*Controller*/
                new { userId = user.Id },                                /*Object Value*/
                _httpContextAccessor.HttpContext.Request.Scheme,         /*Scheme*/
                _httpContextAccessor.HttpContext.Request.Host.ToString() /*Host*/
                );

            var client      = new SendGridClient(config.ApiKey);
            var from        = new EmailAddress(config.SenderEmail, config.SenderName);
            var to          = new EmailAddress(config.ReceiverEmail, config.ReceiverName);
            var htmlContent = $"<p>You recently requested to reset your password for your MRT FareMatrix Account. Click the link provided below to confirm password reset.<br></p>" +
                              $"<a href='{HtmlEncoder.Default.Encode(link)}'>Reset Password</a>" +
                              $"<p>If you did not request this password reset, please ignore this message.</p>" +
                              $"<p>- MRT Farematrix Team.</p>";

            var msg = MailHelper.CreateSingleEmail(
                from,
                to,
                config.Subject,
                config.TextContent,
                htmlContent);

            msg.SetClickTracking(false, false);
            var response = await client.SendEmailAsync(msg);

            return(new SendPasswordResetEmailResult
            {
                Response = response
            });
        }
Beispiel #2
0
        public async Task <PasswordResetResult> PasswordReset(PasswordResetCommand config)
        {
            var user = await _userManager.FindByEmailAsync(config.Email);

            var emailConfig = new SendPasswordResetEmailCommand
            {
                ApiKey        = GetValueInSection("EmailConfig", "SendGridApiKey"),
                SenderEmail   = GetValueInSection("EmailConfig", "SenderEmail"),
                SenderName    = GetValueInSection("EmailConfig", "SenderName"),
                ReceiverEmail = user.Email,
                ReceiverName  = user.FirstName,
                Subject       = GetValueInSection("PasswordReset", "Subject")
            };

            var result = SendPasswordResetEmail(emailConfig, user);

            return(new PasswordResetResult {
            });
        }