示例#1
0
        public async Task <IActionResult> ForgotPassword(string Email)
        {
            if (Email == null)
            {
                ModelState.AddModelError("", "Email Can't be null");
                return(View());
            }
            if (ModelState.IsValid)
            {
                // Find the user by email
                var user = await Usermanager.FindByEmailAsync(Email);

                // If the user is found AND Email is confirmed
                if (user != null && await Usermanager.IsEmailConfirmedAsync(user))
                {
                    // Generate the reset password token
                    var token = await Usermanager.GeneratePasswordResetTokenAsync(user);

                    // Build the password reset link
                    var passwordResetLink = Url.Action("ResetPassword", "Account",
                                                       new { email = Email, token = token }, Request.Scheme);


                    string str = await ViewToStringRenderer.RenderViewToStringAsync(HttpContext.RequestServices, $"~/Views/Template/ResetPassword.cshtml", passwordResetLink);

                    //util.sendemail(user.Email, "Reset Account Password", str);
                    //await _emailSender.SendEmailAsync(user.Email, "Reset Account Password", $"<h2>Here is the Reset Password Confirmation Link</h2></br> <a href ={passwordResetLink}>{passwordResetLink}</a>");
                    await _emailSender.SendEmailAsync(user.Email, "Reset Account Password", str);


                    ViewBag.PageTitle = "Email Confirmation";
                    ViewBag.Title     = "Password Reset Success";
                    ViewBag.Message   = "Before you can Login, please Reset your " +
                                        "Password, by clicking on the Reset Password link we have emailed you";
                    return(View("EmailConfirmation"));
                }

                // To avoid account enumeration and brute force attacks, don't
                // reveal that the user does not exist or is not confirmed
                ViewBag.PageTitle = "Email Confirmation";
                ViewBag.Title     = "Password Reset Success";
                ViewBag.Message   = "Before you can Login, please Reset your " +
                                    "Password, by clicking on the Reset Password link we have emailed you";
                return(View("EmailConfirmation"));
            }

            return(View());
        }
示例#2
0
        public IActionResult ResetPassword(PasswordViewModel model)
        {
            //AppUser user = Usermanager.FindByEmailAsync(model.Email).Result;
            AppUser user = CurrentUser;

            if (user != null)
            {
                string passwordResettoken = Usermanager.GeneratePasswordResetTokenAsync(user).Result;
                string passwrodlink       = Url.Action("ResetPasswordConfirm", "Home", new
                {
                    userid = user.Id,
                    token  = passwordResettoken
                }, HttpContext.Request.Scheme);

                MailHelper.SendMail(passwrodlink, model.Email, "mmesaj'", false);

                ViewBag.status = "tmaam";
            }
            else
            {
                ModelState.AddModelError("", "boyle biri yok");
            }
            return(View(model));
        }