Esempio n. 1
0
        public async Task <IActionResult> ChangePassword(UserChangePassword changePassword)
        {
            if (changePassword != null && ModelState.IsValid)
            {
                changePassword.UserId = User.Identity.Name;
                IdentityResult result = await _dataProcessingConveyor.ChangePasswordAsync(changePassword);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    string errorText, key;
                    foreach (var error in result.Errors)
                    {
                        errorText = error.Description;
                        key       = String.Empty;
                        if (error.Description == "Incorrect password.")
                        {
                            errorText = "Неправильный старый пароль";
                            key       = "OldPassword";
                        }
                        ModelState.AddModelError(key, errorText);
                    }
                    return(View(changePassword));
                }
            }
            return(View(changePassword));
        }