public ActionResult ResetPassword()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Logout"));
            }

            var sessionCurrentUser = Session[User.Identity.Name];

            if (sessionCurrentUser == null)
            {
                return(RedirectToAction("Logout"));
            }

            var currentUser = (User)Session[User.Identity.Name];

            var user = _userService.GetDetailsById(currentUser.Id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            var model = new AccountResetPasswordViewModel {
                FullName = user.Contact.FullName,
                UserId   = user.Id,
                RoleId   = user.RoleId
            };

            return(View(model));
        }
        public ActionResult ResetPassword(AccountResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(View(model));
            }

            var currentUser = (User)Session[User.Identity.Name];

            if (currentUser == null)
            {
                return(RedirectToAction("Logout"));
            }

            var updateUser = Mapper.Map <User>(model);

            updateUser.Id = currentUser.Id;

            var isReset = _userService.ResetPassword(updateUser);

            if (!isReset)
            {
                return(View(model));
            }

            return(Redirect("/Home/Dashboard"));
        }
        public async Task <IActionResult> ResetPassForm(AccountResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var email = await this.aimloginDb.UserEmail.SingleOrDefaultAsync(e => e.Email == model.Email);

            if (email == null)
            {
                ModelState.AddModelError(nameof(model.Email), "The given email does not exist.");
                return(View(model));
            }

            var userId = await this.aimLoginData.SingleValue <UserEmail>().ReverseLookupUserId(email);

            if (userId == null)
            {
                ModelState.AddModelError(nameof(model.Email), "Internal Server Error: No userId could be found in a reverse lookup.");
            }

            var result = await this.ChangePasswordForUser(userId.Value, null, model.Password);

            return(result ?? View(model));
        }
        public ActionResult ResetPassword(AccountResetPasswordViewModel model, string returnUrl = null)
        {
            if (!ModelState.IsValid)
            {
                return(View(
                           viewName: "signIn",
                           model: new AccountSignInViewModel(
                               returnUrl: returnUrl,
                               displayCaptcha: CaptchaSettings.CaptchaIsConfigured() && CaptchaSettings.RequireCaptchaOnLogin,
                               passwordResetAvailable: ControllerHelper.IsPasswordResetAvailable())));
            }

            var signedInCustomer = HttpContext.GetCustomer();

            var result = ControllerHelper.RequestNewPassword(
                signedInCustomer: signedInCustomer,
                email: model.Email,
                skinId: signedInCustomer.SkinID);

            if (result.State == AccountControllerHelper.ResultState.Error)
            {
                NoticeProvider.PushNotice(result.Message, NoticeType.Failure);
            }
            else
            {
                NoticeProvider.PushNotice(result.Message, NoticeType.Success);
            }

            return(View(
                       viewName: "signIn",
                       model: new AccountSignInViewModel(
                           returnUrl: returnUrl,
                           displayCaptcha: CaptchaSettings.CaptchaIsConfigured() && CaptchaSettings.RequireCaptchaOnLogin,
                           passwordResetAvailable: ControllerHelper.IsPasswordResetAvailable())));
        }
Exemple #5
0
        public async Task <IActionResult> ResetPassword(AccountResetPasswordViewModel model)
        {
            //Find User by Id (given in email link)
            var user = await _userManager.FindByIdAsync(model.Id);

            if (user == null)
            {
                throw new InvalidOperationException();
            }

            //Check if passwords entered matches
            if (model.Password != model.RePassword)
            {
                //Display error
                ModelState.AddModelError(string.Empty, "Passwords do not match");
                return(View());
            }

            //Use user manager to reset password using information from view model
            var resetPasswordResult = await _userManager.ResetPasswordAsync(user, model.Token, model.Password);

            if (!resetPasswordResult.Succeeded)  //reset unsuccessful
            {
                //Display errors
                foreach (var error in resetPasswordResult.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }

                return(View());
            }

            return(RedirectToAction("ResetPasswordConfirm", "Account"));
        }
Exemple #6
0
        public IActionResult ResetPassword(string id, string token)
        {
            AccountResetPasswordViewModel model = new AccountResetPasswordViewModel();

            model.Id         = id;
            model.Token      = token;
            model.Password   = string.Empty;
            model.RePassword = string.Empty;

            return(View(model));
        }
Exemple #7
0
        public ActionResult ResetPassword(AccountResetPasswordViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(Content("Coś poszło nie tak..."));
            }

            var user = _userService.GetUserByEmail(vm.Email);

            if (user == null)
            {
                return(View("MessageSent"));
            }

            _resetPasswordService.Create(user);
            return(View("MessageSent"));
        }
Exemple #8
0
        public async Task <ActionResult> ResetPassword(AccountResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToAction("ResetPasswordConfirmation", "Account"));
            }
            var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("ResetPasswordConfirmation", "Account"));
            }
            AddErrors(result);
            return(View());
        }