public ActionResult RequestPasswordResetConfirmation(string email)
        {
            var user = UserRepository.GetUserByNameOrEmail(email);

            if (user != null)
            {
                var myMessage = SendGrid.GetInstance();
                myMessage.AddTo(user.Email);
                myMessage.From    = new MailAddress("*****@*****.**", "Mittagessen Service");
                myMessage.Subject = "Mittagessen Passwort zurücksetzen";
                var passwordResetString = PasswordResetHelper.EncryptString(user.Email);
                myMessage.Html = string.Format(MAIL_TEMPLATE,
                                               Url.Action("ResetPassword", "Account", null, Request.Url.Scheme),
                                               HttpUtility.UrlEncode(passwordResetString));

                // Create credentials, specifying your user name and password.
                var credentials = new NetworkCredential(
                    ConfigurationManager.AppSettings["MailLogin"], ConfigurationManager.AppSettings["MailPassword"]);

                // Create an SMTP transport for sending email.
                var transportSMTP = SMTP.GetInstance(credentials);

                // Send the email.
                transportSMTP.Deliver(myMessage);
            }
            return(View("RequestPasswordResetConfirmation", user));
        }
        public ActionResult ResetPasswordConfirmation(PasswordResetModel model)
        {
            User user = null;

            try
            {
                var userEmail = PasswordResetHelper.DecryptString(model.PasswordResetString);
                user = UserRepository.GetUserByEmail(userEmail);
                if (user != null)
                {
                    user.Password = PasswordHelper.GeneratePassword(model.NewPassword, user.PasswordSalt);
                    UserRepository.Update(user);
                }
            }
            catch (Exception)
            {
                user = null;
            }

            return(View(user));
        }
Beispiel #3
0
        public IActionResult ResetPassword([Bind("Email")] ResetPasswordViewModel resetPasswordViewModel)
        {
            var user = _userManager.FindByEmailAsync(resetPasswordViewModel.Email).Result;

            if (user != null)
            {
                string passwordResetToken = _userManager.GeneratePasswordResetTokenAsync(user).Result;

                string passwordResetLink = Url.Action("ResetPasswordConfirm", "Home", new
                {
                    userId = user.Id,
                    token  = passwordResetToken
                }, HttpContext.Request.Scheme);

                PasswordResetHelper.SendEmail(passwordResetLink, user.Email);
                ViewBag.status = "success";
            }
            else
            {
                ModelState.AddModelError("", "Belirtilen email adresine ait herhangi bir kullanıcı bulunamamıştır.");
            }
            return(View(resetPasswordViewModel));
        }