示例#1
0
        public async Task SendEmailToResetPasswordAsync(EmailResetPasswordRequestModel model)
        {
            try
            {
                if (model is null)
                {
                    throw new Exception("The model to send the email to reset the password can not be null");
                }

                var user = await CustomFindUserAsync("email", model.UserEmail);

                var token = await _userManager.GeneratePasswordResetTokenAsync(user);

                string htmlparent = Directory.GetParent(Directory.GetCurrentDirectory()).ToString();

                string htmlPath = htmlparent += "\\IdentityMicroservice\\Mails\\ResetPassword.html";

                string                  subject     = "Reset Password";
                List <Attachment>       attachments = new();
                List <string>           mails       = new() { model.UserEmail };
                List <(string, string)> values      = new() { ("Link", string.Format(Configuration.GetValue <string>("AppsUrls:Self") + $"/Account/ResetPassword?id={user.Id}&token={token}")), ("UserName", user.UserName) };
                await SendEmailAsync(subject, htmlPath, mails, attachments, values);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public async Task <IActionResult> SendEmailToResetPassword(EmailResetPasswordRequestModel model)
        {
            try
            {
                ViewBag.Errors = string.Empty;

                if (!ModelState.IsValid)
                {
                    throw new Exception("The model is not valid");
                }

                await _accountService.SendEmailToResetPasswordAsync(model);
            }
            catch (Exception ex)
            {
                ViewBag.Errors = ex.Message;
            }

            return(View());
        }