public async Task <IActionResult> ChangePassword(ChangePasswordInputViewModel changePassword)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var user = await this.userManager.GetUserAsync(this.User);

            await this.userManager.ChangePasswordAsync(user, changePassword.OldPassword, changePassword.NewPassword);

            await this.signInManager.RefreshSignInAsync(user);

            return(this.Redirect("/Home/Index"));
        }
Beispiel #2
0
        public async Task <ActionResult> ChangePassword(string id, ChangePasswordInputViewModel changePassword)
        {
            var user = await this._userManager.FindByIdAsync(id);

            if (user != null &&
                this.ModelState.IsValid)
            {
                var result = await this._userManager.ChangePasswordAsync(user, changePassword.OldPassword,
                                                                         changePassword.NewPassword);

                if (!result.Succeeded)
                {
                    return(this.BadRequest(new { Message = "Change password failed!" }));
                }

                return(this.Ok(new { Message = "Successful changed password!" }));
            }

            return(this.BadRequest(new { Message = "Change password failed!" }));
        }