public ActionResult PasswordReset(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = _userService.ResetPassword(model.EmailAddress);
                    if (ModelState.Process(result))
                    {
                        return View("ResetSuccess");
                    }
                    ModelState.AddModelError("", "Error resetting password. The email might be invalid.");

                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
                catch (UserNotFoundException ex)
                {
                    ModelState.AddModelError("", "Error resetting password. The email might be invalid.");
                }
            }
            return View(model);
        }
示例#2
0
        public JsonResult ForgotPasswordForm(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                return Json("");
            }

            return Json(new ResponseModel
            {
                Success = false,
                Message = GetFirstValidationResults(ModelState).Message
            });
        }
        public ActionResult ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // lookup user by username...
                var user = _userService.Find(u => model.EmailAddress == u.Email).FirstOrDefault();

                if (user == null)
                {
                    ModelState.AddModelError("", "There is no user with this email address");
                }
                else
                {
                    var temp = Guid.NewGuid().ToString().Substring(0, 8);

                    //user.ResetPassword = true;
                    user.TemporaryPassword = temp;

                    try
                    {

                        if (!ModelState.Process(_userService.SaveOrUpdate(user)))
                            return View();

                        var loginUrl = Url.AbsoluteAction("Login", "Account");

                        new Mailer().ForgotPassword(new ForgotPasswordResetModel()
                        {
                            EmailAddress = user.Email,
                            FirstName = user.FirstName,
                            TemporaryPassword = temp,
                            UserName = user.Username,
                            LoginUrl = loginUrl
                        }).Send();

                        // send email
                        TempData.AddSuccessMessage("An email was sent to your account with password reset instructions");
                    }
                    catch (Exception ex)
                    {
                        TempData["Error"] = ex.Message;
                    }

                }

                // set flag to forgot password
            }
            return View(model);
        }
        public async Task <JsonResult> ForgotPassword(ForgotPasswordModel model)
        {
            try
            {
                ToastModel tm            = new ToastModel();
                bool       isEmailExists = await _account.CheckIsEmailExists(model.Email);

                if (isEmailExists)
                {
                    EmailTemplateModel etm = await _account.GetEmailTemplate(8);

                    EncryptDecrypt ed       = new EncryptDecrypt();
                    string         fullName = await _user.GetUserFullName(model.Email);

                    string forgotPasswordResetLink = configMngr["ResetForgotPasswordLink"] + ed.Encrypt(model.Email, configMngr["ServiceAccountPassword"]);
                    string emaiBody = etm.Body.Replace("[Username]", fullName)
                                      .Replace("[URL]", forgotPasswordResetLink);
                    etm.Body = emaiBody;
                    EmailManager em = new EmailManager
                    {
                        Body    = etm.Body,
                        To      = model.Email,
                        Subject = etm.Subject,
                        From    = ConfigurationManager.AppSettings["SMTPUsername"]
                    };

                    em.Send();

                    tm.Message   = "Email sent";
                    tm.IsSuccess = true;
                }
                else
                {
                    tm.Message   = "Email not found";
                    tm.IsSuccess = false;
                }

                return(Json(tm));
            } catch (Exception ex)
            {
                return(Json(""));
            }
        }
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(await Task.FromResult(View(model)));
            }

            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("ForgotPasswordSent", "Error occured");
                return(await Task.FromResult(View(model)));
            }

            await user.ForgotPasswordAsync();

            return(await Task.FromResult(View("ResetPassword")));
        }
示例#6
0
        public ActionResult ForgotPasword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                if (Metodos.ValidarEmailUsuario(model.Email))
                {
                    string _esquema  = Request.Url.Scheme;
                    string _hostName = Request.Url.Host;

                    EmailManager.EnviarEmailConfirmPassword(model.Email, this.ControllerContext, RouteTable.Routes, _esquema, _hostName);
                    return(RedirectToAction("EmailSent"));
                }
                else
                {
                    ModelState.AddModelError("Email", Resources.ErrorResource.EmailError);
                }
            }
            return(View(model));
        }
示例#7
0
        public void ProcessForgotPassword(ForgotPasswordModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {
                //Get user info
                var user = Session.Query <AccountUserDocument>().Where(x => x.Email == model.Email).SingleOrDefault();

                //Create return email object
                BCryptService crypto        = new BCryptService();
                var           identifier    = crypto.GenerateToken();
                var           resetDocument = new ReturnEmailDocument
                {
                    UserId     = user.Id,
                    Email      = user.Email,
                    Identifier = identifier,
                    Hash       = crypto.Hash(identifier),
                    Timestamp  = DateTime.Now
                };

                //Creste reset Url
                resetDocument.ResetUrl = ConfigurationManager.AppSettings["BaseUrl"] + "Account/ResetPassword?prc=" + System.Uri.EscapeDataString(resetDocument.Hash);

                //Persist reset object
                Session.Store(resetDocument);
                Session.SaveChanges();



                //Send the email
                if (user != null)
                {
                    EmailModel emailProperties = new EmailModel();
                    emailProperties.ToAddress = user.Email;
                    emailProperties.FirstName = user.FirstName;
                    emailProperties.ReturnUrl = resetDocument.ResetUrl;
                    new MailController().ForgotPasswordEmail(emailProperties).Deliver();
                }
                else
                {
                    throw new UserNotFoundException("User not found by specified email address");
                }
            }
        }
示例#8
0
        public async Task <Guid> PostForgotPassword(ForgotPasswordModel _Dto)
        {
            emp_CustomerLoginInformation _CustomerLoginInformation = new emp_CustomerLoginInformation();
            SecurityAnswerUserMap        _SecurityAnswerUserMap    = new SecurityAnswerUserMap();

            var dbresult = await db.emp_CustomerLoginInformation.Where(o => o.CrossLinkUserId == _Dto.CrossLinkUserId).Select(o => new CustomerLoginModel
            {
                CrossLinkUserId = o.CrossLinkUserId,
            }).FirstOrDefaultAsync();

            if (dbresult != null)
            {
                var result = await db.SecurityAnswerUserMaps.Where(o => (o.QuestionId == _SecurityAnswerUserMap.QuestionId) && (o.Answer == _SecurityAnswerUserMap.Answer)).Select(o => new SecurityAnswerUserMap
                {
                    UserId = o.UserId,
                }).FirstOrDefaultAsync();
            }
            return(dbresult.UserId ?? Guid.Empty);
        }
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null || user.IsAccountDisabled || !await _userManager.IsEmailConfirmedAsync(user))
            {
                //await _loggerService.Information();
                // Don't reveal that the user does not exist
                return(BadRequest("User not found."));
            }
            var token = await _userManager.GeneratePasswordResetTokenAsync(user);

            var link = string.Empty;
            await _notificationService.SendPasswordRecoveryLink(new NotificationDto { Email = user.Email, Name = user.Name, Token = token });

            await _loggerService.LogInformation($"Password reset link sent. link={ link }");

            return(Ok());
        }
示例#10
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    var token = await _userManager.GeneratePasswordResetTokenAsync(user);

                    return(Ok(token));
                }
                return(NotFound("Usuario(Email) nao encontrado"));
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Error API: {e}"));
            }
        }
示例#11
0
        public async Task <ForgotPasswordResetResult> ForgotPassword(ForgotPasswordModel model)
        {
            var validationResult = ValidateForgotModel(model);

            if (validationResult != null)
            {
                return(validationResult);
            }

            var userExists = await _identityProvider.VerifyUserExists(model.Email);

            if (!userExists)
            {
                return(ForgotPasswordResetResult.BadEmail(model.Email));
            }

            return(await SendEmail(
                       model, (email, confirmationSecret) => _emailService.SendForgotPasswordEmail(email, confirmationSecret)));
        }
示例#12
0
        async void should_send_reset_password_email()
        {
            var user  = CreateUser(true);
            var model = new ForgotPasswordModel {
                UsernameOrEmail = user.UserName
            };

            var mailSender = MockMailSender();
            var controller = _app.CreateController <AccountController>();
            var result     = await controller.DoForgotPassword(model);

            result.ShouldNotBeNull();
            result.HasSucceeded.ShouldBeTrue();

            mailSender.Verify(x => x.SendEmailAsync(
                                  user.EmailAddress,
                                  "dotnet club 用户密码重置",
                                  It.IsAny <string>()), Times.Once);
        }
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordModel model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
            {
                return(Ok(JsonConvert.SerializeObject(new ErrorResponse
                {
                    Error = "User does not exist or email unconfirmed"
                })));
            }

            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            var callbackUrl = $"https://{_configuration["Domain"]}/auth/resetpassword?userId={user.Id}&code={code}";
            await _emailSender.SendResetPasswordAsync(model.Email, callbackUrl);

            return(Ok());
        }
示例#14
0
        public async Task <bool> ForgotMyPass(ForgotPasswordModel model)
        {
            _accessor.HttpContext.Session.Remove("email");
            MultipartFormDataContent formDataContent = new MultipartFormDataContent();

            formDataContent.Add(new StringContent(model.Email), nameof(model.Email));

            var responseMessage = await _httpClient.PostAsync("ForgotPassword", formDataContent);

            if (responseMessage.IsSuccessStatusCode)
            {
                _accessor.HttpContext.Session.SetString("email", model.Email);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#15
0
        public async Task <IActionResult> GenerateTemporaryPassword(ForgotPasswordModel forgotPasswordModel)
        {
            string temporaryPassword = "";
            bool   isEmailSent       = false;
            ForgotPasswordResponse forgotPasswordResponse = null;

            try
            {
                var Email = flightDBContext.FlightUsers.Where(x => x.Username == forgotPasswordModel.Username)
                            .Select(x => x.Email).FirstOrDefault();

                var IsUserExists = flightDBContext.FlightUsers.
                                   Where(x => x.Email == Email &&
                                         x.DateOfBirth == forgotPasswordModel.DateOfBirth)
                                   .Any();
                if (IsUserExists)
                {
                    temporaryPassword = GenerateTemporaryPassword();
                    string             mailBodyContent = BuildMailContentBody(temporaryPassword);
                    List <MailMessage> mailMessages    =
                        GetMailMessage(Email, mailBodyContent);
                    isEmailSent = SendEmails(mailMessages);
                }
                if (isEmailSent && IsUserExists)
                {
                    forgotPasswordResponse = new ForgotPasswordResponse();
                    forgotPasswordResponse.IsUserExists      = IsUserExists;
                    forgotPasswordResponse.TemporaryPassword = temporaryPassword;
                    return(Ok(SerializeIntoJson(forgotPasswordResponse)));
                }
                else
                {
                    forgotPasswordResponse = new ForgotPasswordResponse();
                    forgotPasswordResponse.IsUserExists      = IsUserExists;
                    forgotPasswordResponse.TemporaryPassword = "******";
                    return(Ok(SerializeIntoJson(forgotPasswordResponse)));
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Invalid Request" + e.StackTrace + e.Message));
            }
        }
示例#16
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    await user.ForgotPasswordAsync().ConfigureAwait(false);

                    return(RedirectToAction("ResetPassword"));
                }
                else
                {
                    ModelState.AddModelError("UserNotFound", "Unable to find the user for provided email address");
                }
            }
            return(View(model));
        }
        public async Task <ActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Username);

                if (user == null)
                {                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPassword"));
                }
                if (model.NewPassword != model.ConfirmPassword)
                {
                    ModelState.AddModelError("", "Passwords do not match");
                    return(View("ForgotPassword"));
                }

                var provider = new DpapiDataProtectionProvider("SampleAppName");
                UserManager.UserTokenProvider = new DataProtectorTokenProvider <IdentityUser>(
                    provider.Create("UserToken"));
                string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, model.NewPassword);



                if (passwordChangeResult.Succeeded)
                {
                    return(View("~/Views/ResetPassword/ResetPasswordConfirmation.cshtml"));
                }
                else
                {
                    ModelState.AddModelError("", "Could not Reset Password");
                    return(View("ForgotPassword"));
                }



                // If we got this far, something failed, redisplay form
                //return View(model);
            }
            return(View());
        }
        public ActionResult ForgotPassword(ForgotPasswordModel model)
        {
            AuthorizationCode Code = UserBL.AuthCode(model.Email);

            if (Code.UserID >= 1)
            {
                Emails Email = new Emails();

                Email.FromEmail    = "*****@*****.**";
                Email.ToEmail      = model.Email;
                Email.SubjectEmail = Code.FullName + " - Restablecer contraseña";
                Email.BodyEmail    = "Para restablecer su contraseña, utilice el siguiente link https://mmoasisalajuela.azurewebsites.net/Account/ResetPassword?GUID=" + Code.GUID;
                //Email.BodyEmail = "Para restablecer su contraseña, utilice el siguiente link https://localhost:56593/Account/ResetPassword?GUID=" + Code.GUID;

                MailMessage mm = new MailMessage(Email.FromEmail, Email.ToEmail);
                mm.Subject    = Email.SubjectEmail;
                mm.Body       = Email.BodyEmail;
                mm.IsBodyHtml = false;

                SmtpClient smtp = new SmtpClient();
                smtp.Host      = "smtp.gmail.com";
                smtp.Port      = 587;
                smtp.EnableSsl = true;
                //smtp.Host = "smtp.office365.com";
                //smtp.Port = 587;
                //smtp.EnableSsl = true;

                NetworkCredential nc = new NetworkCredential("*****@*****.**", "Jonitapc1985N");
                smtp.UseDefaultCredentials = true;
                smtp.Credentials           = nc;
                smtp.Send(mm);

                ViewBag.GUID = Code.GUID;
                return(this.RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }
            else
            {
                this.ModelState.AddModelError(String.Empty, "Este correo no esta registrado en la aplicación.");
            }

            return(this.View(model));
        }
示例#19
0
        public async Task <IActionResult> SendForgotPasswordMail(ForgotPasswordModel forgotPasswordModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            dynamic result;
            string  url = AbsoluteUrl(_httpContextAccessor, "/resetpassword/");

            var user = await _userService.FindByEmailAsync(forgotPasswordModel.Email);

            if (user != null)
            {
                var token = await _userService.GeneratePasswordResetTokenAsync(user);

                if (token != null && url != null)
                {
                    string sent = await _mailService.SendResetEmailAsync(user.Email, token, url);

                    result = new
                    {
                        data = "sent"
                    };
                }
                else
                {
                    result = new
                    {
                        data = "token generation failed!"
                    };
                }
            }
            else
            {
                result = new
                {
                    data = "User not found!"
                };
            }
            return(Ok(result));
        }
示例#20
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByEmailAsync(model.Email);

                if (user != null && await userManager.IsEmailConfirmedAsync(user))
                {
                    var token = await userManager.GeneratePasswordResetTokenAsync(user);

                    var passwordResetLink = Url.Action("ResetPassword", "Account", new { email = model.Email, token = token }, Request.Scheme);

                    logger.Log(LogLevel.Warning, passwordResetLink);

                    return(View("ForgotPasswordConfirmation"));
                }
                return(View("ForgotPasswordConfirmation"));
            }
            return(View(model));
        }
示例#21
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null && await _userManager.IsEmailConfirmedAsync(user))
                {
                    var token = await _userManager.GeneratePasswordResetTokenAsync(user);

                    var passwordResetLink = Url.Action("ResetPassword", "Account",
                                                       new { email = model.Email, token = token }, Request.Scheme);

                    var message = new Message(new string[] { user.Email }, "Reset password link", passwordResetLink, null);
                    await _emailSender.SendEmailAsync(message);
                }
                return(View("ForgotPasswordConfirmation"));
            }
            return(View(model));
        }
示例#22
0
        public async Task ForgotPassword(ForgotPasswordModel forgotPasswordModel)
        {
            var requestModel = new ForgotPasswordRequestModel(forgotPasswordModel);

            try
            {
                await PostAsync(Resources.ForgotPasswordAction, requestModel);
            }
            catch (BadRequestException e)
            {
                ThrowNewIfDelayException(e);

                if (e.Message.StartsWith("Unconfirmed Email"))
                {
                    throw new UnconfirmedEmailException();
                }

                throw;
            }
        }
示例#23
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordModel model, [FromServices] IMemoryCache cache)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                string jsonError = ErrorFormat.SerializeError(new BadRequestError("The email address does not exist."));
                return(BadRequest(jsonError));
            }

            var token = await _userManager.GeneratePasswordResetTokenAsync(user);

            var code = RandomGenerator.GenerateString(8);

            cache.Set(code, token);

            await _emailService.SendEmailAsync(model.Email, "Reset password account.", "Code:" + code);

            return(Ok());
        }
示例#24
0
        public IHttpActionResult ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindByEmail(model.Email);
                if (user == null || !(UserManager.IsEmailConfirmed(user.Id)))
                {
                    return(BadRequest("User does not exist in the system or this email is not confirmed"));
                }

                var code        = UserManager.GeneratePasswordResetToken(user.Id);
                var callBackUrl = new Uri(Url.Link("ResetPasswordViewRoute", new { Email = user.Email, code = code }));
                UserManager.SendEmail(user.Id, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callBackUrl + "\">link</a>");
                return(Ok("Success"));
            }
            else
            {
                return(BadRequest());
            }
        }
示例#25
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.FindByNameAsync(model.Email);

            if (user == null)
            {
                AddUserNotFoundModelState();
                return(View(model));
            }
            ;

            await user.ForgotPasswordAsync();

            return(RedirectToAction("ConfirmForgotPassword"));
        }
示例#26
0
        public async Task <IActionResult> ForgetPassword([FromBody] ForgotPasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _userManager.FindByNameAsync(model.Mobile);

            if (user == null)
            {
                return(BadRequest(string.Format(ErrorMessageResource.NotFoundError, DisplayNameResource.User)));
            }

            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            //send code via SMS

            return(Ok());
        }
示例#27
0
        public async Task <ActionResult <ResetPasswordModel> > CreateResetToken(ForgotPasswordModel forgotPasswordModel)
        {
            try
            {
                ResetPasswordModel resetPasswordModel = await _userRepository.CreateResetToken(forgotPasswordModel);

                return(resetPasswordModel);
            }
            catch (MovieMindException e)
            {
                if (e.MovieMindError.Status.Equals("404"))
                {
                    return(NotFound(e.MovieMindError));
                }
                else
                {
                    return(BadRequest(e.MovieMindError));
                }
            }
        }
示例#28
0
        //method for forgot password
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel forgotPassword)
        {
            if (ModelState.IsValid)
            {
                var user = await _accountRepository.GetUserByEmailAsync(forgotPassword.Email);

                if (user != null)
                {
                    await _accountRepository.GenerateForgotPasswordTokenAsync(user);

                    ModelState.Clear();
                    forgotPassword.EmailSent = true;
                }
                else
                {
                    ModelState.AddModelError("Email", "Please enter a registered email id!");
                }
            }
            return(View(forgotPassword));
        }
示例#29
0
        public virtual async Task <string> GeneratePasswordResetToken(ForgotPasswordModel model, CancellationToken cancellationToken = default)
        {
            var user = await userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                throw new BadRequestException("حساب کاربری با ایمیل وارد شده یافت نشد!");
            }

            //if (!await userManager.IsEmailConfirmedAsync(user))
            //    throw new BadRequestException("ایمیل تایید نشده است!!");

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

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

            return(code);
        }
        public async Task ForgotPasswordShouldReturnOkWhenUserDoesNotExist()
        {
            // Arrange
            var model = new ForgotPasswordModel
            {
                Email = "*****@*****.**"
            };

            _userService.Setup(service => service.FindOneAsync(
                                   It.Is <UserFilter>(filter => filter.Email == model.Email && filter.AsNoTracking)))
            .ReturnsAsync((User)null);

            var controller = CreateInstance();

            // Act
            var result = await controller.ForgotPasswordAsync(model);

            // Assert
            Assert.IsType <OkResult>(result);
        }
示例#31
0
      public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
      {
          if (ModelState.IsValid)
          {
              var user = await _userManager.FindByEmailAsync(model.Email);

              if (user == null)
              {
                  return(RedirectToAction("ForgotPasswordConfirmation"));
              }
              var code = await _userManager.GeneratePasswordResetTokenAsync(user);

              var callbackurl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
              await _emailSender.SendEmailAsync(model.Email, "Reset Password",
                                                "Please reset your password by clicking here: <a href=\"" + callbackurl + "\">link</a>");

              return(RedirectToAction("ForgotPasswordConfirmation"));
          }
          return(View(model));
      }
        public IActionResult Index(ForgotPasswordModel request)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "ForgotPassword Failed!");
                return(View(request));
            }

            var result = (ObjectResult)_authController.ForgotPassword(request).Result;

            if (result.StatusCode.Value == 200)
            {
                ModelState.AddModelError(string.Empty, "Success");
                return(View(request));
            }

            ModelState.AddModelError(string.Empty, result.ToString());

            return(View(request));
        }
示例#33
0
        public async Task <IActionResult> RecoverPassword([FromBody] ForgotPasswordModel model)
        {
            User user = await _userInMgr.FindByEmailAsync(model.Email);

            if (user == null || !(await _userInMgr.IsEmailConfirmedAsync(user)))
            {
                //Don't reveal that the user does not exist
                return(BadRequest("Something is wrong, please try again later"));
            }

            string generatedCode = await _userInMgr.GeneratePasswordResetTokenAsync(user);

            var callbackUrl = string.Format(@"{0}/{1}", model.ResetUrl, HttpUtility.UrlEncode(generatedCode));

            string bodyHtmlEmail = Helper.CreateBodyemailForgotPassword(user, callbackUrl);

            await _emailSender.SendEmailAsync(model.Email, "Reset Password", bodyHtmlEmail);

            return(Ok("Please check your email to reset your password."));
        }
示例#34
0
 public ActionResult ForgotPasswordForm()
 {
     var model = new ForgotPasswordModel();
     return PartialView("Login/_ForgotPassword", model);
 }
示例#35
0
        public ActionResult ForgotPassword()
        {
            ForgotPasswordModel model = new ForgotPasswordModel();
            PopupModel popup = new PopupModel();
            popup.Title = "Forgot Password";
            popup.Body = RenderRazorViewToString("_ForgotPassword", model);

            string popupString = RenderRazorViewToString("_LayoutPopup", popup);
            return Json(new ActionOutput { Results = new List<string> { popupString }, Status = ActionStatus.Successfull }, JsonRequestBehavior.AllowGet);
        }
示例#36
0
 //
 // GET: /Account/Forgot
 public ActionResult Forgot()
 {
     var v = new ForgotPasswordModel {  Email = "" };
     return View(v);
 }
示例#37
0
        public ActionResult ForgotPassword(string userName, bool captchaValid )
        {
            if (!captchaValid)
            {
                ModelState.AddModelError("Captcha", "Recaptcha value not valid");
                Message = "Unable to reset password";
                return View(new ForgotPasswordModel() { UserName = userName .ToLower()});
            }
            userName = userName.Trim().ToLower();

            if (!_membershipService.DoesUserExist(userName))
            {
                ModelState.AddModelError("UserName", "Email not found");
            }

            CallForProposal callForProposal = null;
            var proposal =
                Repository.OfType<Proposal>().Queryable.Where(a => a.Email == userName && a.CallForProposal.IsActive)
                    .FirstOrDefault();
            if(proposal == null)
            {
                proposal =
                    Repository.OfType<Proposal>().Queryable.Where(a => a.Email == userName).FirstOrDefault();
            }
            if(proposal == null)
            {
                var editor =
                    Repository.OfType<Editor>().Queryable.Where(a => a.ReviewerEmail == userName && a.CallForProposal != null).FirstOrDefault();
                if(editor != null)
                {
                    callForProposal =
                        Repository.OfType<CallForProposal>().Queryable.Where(a => a.Editors.Contains(editor)).
                            FirstOrDefault();
                }
            }
            else
            {
                callForProposal = proposal.CallForProposal;
            }

            if(callForProposal == null)
            {
               ModelState.AddModelError("UserName", "Linked Email not found");
            }

            if (ModelState.IsValid)
            {
                var tempPass = _membershipService.ResetPassword(userName);
                _emailService.SendPasswordReset(callForProposal, userName, tempPass);

                Message = "A new password has been sent to your email. It should arrive in a few minutes";
                return this.RedirectToAction<PublicController>(a => a.LogOn());
            }

            Message = "Unable to reset password";
            var viewModel = new ForgotPasswordModel();
            viewModel.UserName = userName;
            return View(viewModel);
        }
        public ActionResult ForgotPassword(ForgotPasswordModel forgotPasswordModel)
        {
            if (ModelState.IsValid)
            {
                var passwordResetRequest = new PasswordResetRequestCommand(forgotPasswordModel.Email);
                var result = ExecuteCommand(passwordResetRequest);

                if (result)
                {
                    _userMailer.PasswordReset(passwordResetRequest.Name, passwordResetRequest.Token, forgotPasswordModel.Email).Send();

                    return View("ForgotPasswordMailSent");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "We couldn't find an account with the given email address. Please check the email address.");
                }
            }

            return View(forgotPasswordModel);
        }
示例#39
0
        public virtual ActionResult ForgotPassword(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                Status status;
                if (model.GenerateResetToken(out status))
                    ModelState.AddModelError("Error", "Please check your email for password reset token!");
                else
                    ModelState.AddModelError("Error", status.Message());
            }
            else
            {
                ModelState.AddModelError("Error", "Please update the required fields!");
            }

            return View(model);
        }        
示例#40
0
        public ActionResult Forgot(ForgotPasswordModel model)
        {
            if (ModelState.IsValid && EmailExist(model.Email))
            {
                Session["email"] = model.Email;
                //Send email with new password here

                this.FlashInfo("an email has been sent to " + model.Email);
                //var newPassword = RandomHelper.RandomString(12);
                var newpassword = ResetPassword(model.Email);

                Email email = new Email();
                email.ToAddressList = model.Email;
                MailAddress mailAddress = new MailAddress("*****@*****.**");
                email.FromAddress = mailAddress;
                email.Subject = "Password Recovery";
                email.IsBodyHtml = true;
                email.Body = "This e-mail has been sent from an automated system. PLEASE DO NOT REPLY. <br/> <br/> Your password for Frigo Cheeseheads Bikes has been changed.  <br/><br/>" +
                             "-------------------------------- <br/> INSTRUCTIONS <br/> -------------------------------- <br/>" +
                             "1. Go to this URL: https://frigocheeseheadsbikes.amssupport.net/admin <br/>" +
                             "2. Log in with this password: <b>" + newpassword + "</b> <br/>" +
                             "3. Change your password";
                email.Send();

                ViewBag.Result = true;
                return View(model);
            }
            ModelState.AddModelError(string.Empty, "Oops, "+ String.Join("; ",  ModelState.Values.First().Errors.Select(x=>x.ErrorMessage)));
            return View(model);
        }
        public async Task<ActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            EmailSender.EmailSender sendEmail = new EmailSender.EmailSender();
            string subject = "Forgot Password";
            string CC = (string)ConfigurationManager.AppSettings["adminEmail"];
            string fromEmail = (string)ConfigurationManager.AppSettings["Email_To"];
            string template = string.Empty;
            SAASContext SAASdb = new SAASContext();
            var user = SAASdb.Users.Where(c => c.UserName == model.UserName).FirstOrDefault();
            using (StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/EmailTemplates/ForgotPassword.html")))
            {
                template = reader.ReadToEnd();
            }

            var companyUserManger = ApplicationUserManager.Create(user.RestaurantName);
            var getuser = companyUserManger.FindByName(user.Email);
            var resetToken = companyUserManger.GeneratePasswordResetToken(getuser.Id);

            string sitepath = "http://www.mondofi.com/Account/ResetPassword?email=" + model.UserName + "&code=" + resetToken;

            template = template.Replace("{verifyUrl}", sitepath);

            sendEmail.SendEmail(subject, template, model.UserName, null, fromEmail, null);
            return RedirectToAction("EmailSend", "Account");
        }
示例#42
0
 public ActionResult SendForgotPassword(ForgotPasswordModel model)
 {
     return Json(_homeManager.ForgotPassword(model.UserEmail), JsonRequestBehavior.AllowGet);
 }
示例#43
0
        /// <summary>
        /// #3
        /// </summary>
        /// <returns></returns>
        public ActionResult ForgotPassword()
        {
            var viewModel = new ForgotPasswordModel();

            return View(viewModel);
        }
示例#44
0
 public ActionResult Forgot(ForgotPasswordModel model)
 {
     if (ModelState.IsValid && EmailExist(model.Email))
     {
         Session["email"] = model.Email;
         //Send email with new password here
         this.FlashInfo("an email has been sent to <b> " + model.Email + "</b>");
         ViewBag.Result = true;
         return View(model);
     }
     ModelState.AddModelError(string.Empty, "Errors: "+ String.Join("; ",  ModelState.Values.First().Errors.Select(x=>x.ErrorMessage)));
     return View(model);
 }
 public string ForgotPassword(ForgotPasswordModel model)
 {
     if (ModelState.IsValid)
     {
         return "validdd";
     }
     return "not valid"+ model.UserName+model.Password;
 }