Ejemplo n.º 1
0
        public async Task <IActionResult> ChangePassword(SmsChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = _userService.GetUserByNationalCode(model.NationalCode);

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

            var result = await _userManager.ResetPasswordAsync(user, model.Code, model.NewPassword);

            if (result.Succeeded)
            {
                await _userManager.UpdateSecurityStampAsync(user);

                TempData.AddResult(ServiceResult.Okay());

                return(RedirectToAction("Index", "Login"));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ChangePassword(ForgotPasswordViewModel vm)
        {
            var user = _userService.GetUserByNationalCode(vm.NationalCode);

            var token = await _userManager.GeneratePasswordResetTokenAsync(user);

            var model = new SmsChangePasswordViewModel()
            {
                Code         = token,
                NationalCode = vm.NationalCode,
                PhoneNumber  = vm.PhoneNumber
            };

            return(View(model));
        }