コード例 #1
0
        public async Task <IHttpActionResult> ChangePassword(AccountChangePasswordApplicationUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result =
                await _accountService.ChangeUserPasswordAsync(User.Identity.GetUserId(), model.OldPassword,
                                                              model.NewPassword);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            _accountService.Logout(CookieAuthenticationDefaults.AuthenticationType);
            return(Ok());
        }
コード例 #2
0
        public async Task <ActionResult> ChangePassword(AccountChangePasswordApplicationUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _accountService.FindUserByUserNameAsync(HttpContext.User.Identity.Name);

            var result = await _accountService.ChangeUserPasswordAsync(user.Id, model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                return(RedirectToAction("Login", "Account"));
            }

            AddErrors(result);

            return(View(model));
        }