コード例 #1
0
        public async Task <IActionResult> SetPassword([FromBody] SetPasswordInputDto request)
        {
            var user = await _userManager.FindByIdAsync(request.UserId);

            if (user == null)
            {
                return(Unauthorized(new ApiResponse(401)));
            }

            var isValid = await _userManager.CheckPasswordAsync(user, request.CurrentPassword);

            if (!isValid)
            {
                return(BadRequest(new ApiResponse(400, "The password entered doesn't match the current password.")));
            }

            var response = await _userManager.ChangePasswordAsync(user, request.CurrentPassword, request.NewPassword);

            if (response.Succeeded)
            {
                user.HasChangePassword = true;
                await _userManager.UpdateAsync(user);

                return(Ok(new ApiResponse(200, "You have successfully set your password!")));
            }
            else
            {
                return(BadRequest(new ApiResponse(400, "There is a problem changing the account's password.")));
            }
        }
コード例 #2
0
ファイル: ManageController.cs プロジェクト: yurekliisa/BBC
        public async Task <IActionResult> SetPassword([FromBody] SetPasswordInputDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            IdentityResult result = await _manageService.SetPassword(model);

            if (result.Succeeded)
            {
                return(Ok(result));
            }
            return(BadRequest(result.Errors.Select(x => x.Description)));
        }
コード例 #3
0
        public async Task <IdentityResult> SetPassword(SetPasswordInputDto model)
        {
            var user = await GetCurrentUserAsync();

            if (user == null)
            {
                return(IdentityResult.Failed(new IdentityError[]
                {
                    new IdentityError()
                    {
                        Code = "User",
                        Description = "Not Found User"
                    }
                }));
            }

            var addPasswordResult = await _userManager.AddPasswordAsync(user, model.NewPassword);

            return(addPasswordResult);
        }