Exemplo n.º 1
0
        private NotificationModel BuildResetPasswordNotificationModel(ResetPasswordNotificationModel resetPasswordNotificationModel)
        {
            var resetPasswordNotificationMessage = new ManufacturerPartialRegistrationMessage
            {
                From             = resetPasswordNotificationModel.FromEmail,
                EmailDisplayName = "Tssp Portal",
                To = new List <string> {
                    resetPasswordNotificationModel.ToEmail
                },
                ReceiverDisplayName = resetPasswordNotificationModel.ContactName,
                Subject             = "Reset Password",
                OrganizationName    = resetPasswordNotificationModel.OrgName,
                URL = resetPasswordNotificationModel.CallBackUrl
            };
            NotificationModel notificationModel = new NotificationModel();

            notificationModel.EmailContent          = resetPasswordNotificationMessage;
            notificationModel.EmailContentModelType = notificationModel.EmailContent.GetType().Name;
            notificationModel.NotificationType      = NotificationType.Email;
            return(notificationModel);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel forgotPasswordModel)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(forgotPasswordModel.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordEmailFailed"));
                }

                // For more information on how to enable account confirmation and password reset please
                // visit https://go.microsoft.com/fwlink/?LinkID=532713
                var userClaims = await _userManager.GetClaimsAsync(user);

                var fromEmail         = _configurationRoot.GetValue <string>("NotificationFromEmail");
                var resetPasswordCode = await _userManager.GeneratePasswordResetTokenAsync(user);

                resetPasswordCode = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(resetPasswordCode));

                var resetPasswordUrl = Url.Action("ResetPassword", "Account", new { code = resetPasswordCode }, Request.Scheme);

                var resetPasswordNotificationModel = new ResetPasswordNotificationModel();
                resetPasswordNotificationModel.CallBackUrl = resetPasswordUrl;
                resetPasswordNotificationModel.ContactName = userClaims.FirstOrDefault(x => x.Type == "GivenName")?.Value ?? string.Empty;
                resetPasswordNotificationModel.FromEmail   = fromEmail;
                resetPasswordNotificationModel.ToEmail     = user.Email;
                resetPasswordNotificationModel.OrgName     = userClaims.FirstOrDefault(x => x.Type == "OrgName")?.Value ?? string.Empty;
                await _notificationHelper.SendNotificationToQueue(BuildResetPasswordNotificationModel(resetPasswordNotificationModel));

                return(View("ForgotPasswordConfirmation"));
            }

            return(View(forgotPasswordModel));
        }