예제 #1
0
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = BoardSquaresRepository.Context.Users.FirstOrDefault(r => r.Email == model.Email); //await UserManager.FindByNameAsync(model.Email);
                if (user == null)                                                                            //|| !(await UserManager.IsEmailConfirmedAsync(user.UserID.ToString())))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string code = Membership.GeneratePassword(25, 8);//await UserManager.GeneratePasswordResetTokenAsync(user.UserID.ToString());
                BoardSquaresRepository.AssignPasswordResetCode(user.UserID, code);
                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.UserID, code = code }, protocol: Request.Url.Scheme);
                var subject     = "Playoff Fantasy - Password Reset Request";
                var message     = "We have received a request to change your password. Please click the 'Reset Password' button below to continue.<br /><br />" +
                                  "<a href=\"" + callbackUrl + "\">Reset Password</a><br /><br />" +
                                  "If you do not wish to change your password at this time, please ignore this email." +
                                  "<br /><br />Thank you!<br />" +
                                  "<a href=\"https://boardsquares.com\">BoardSquares.com</a>";
                var mailClient  = new SmtpClient();
                var mailMessage = new MailMessage
                {
                    From       = new MailAddress("*****@*****.**"),
                    Subject    = subject,
                    Body       = message,
                    IsBodyHtml = true
                };
                mailMessage.To.Add(new MailAddress(model.Email));
                mailClient.Send(mailMessage);
                mailClient.Dispose();
                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }