Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateCredentials(
            UpdateResourceOwnerCredentialsViewModel viewModel,
            CancellationToken cancellationToken)
        {
            // 1. Validate the view model.
            var authenticatedUser = await SetUser().ConfigureAwait(false);

            ViewBag.IsUpdated = false;
            viewModel.Validate(ModelState);
            if (!ModelState.IsValid)
            {
                return(await GetEditView(authenticatedUser !, cancellationToken).ConfigureAwait(false));
            }

            // 2. CreateJwk a new user if he doesn't exist or update the credentials.
            //var resourceOwner = await _getUserOperation.Execute(authenticatedUser).ConfigureAwait(false);
            var subject = authenticatedUser.GetSubject();
            var updated = subject != null &&
                          await _resourceOwnerRepository.SetPassword(subject, viewModel.Password !, cancellationToken)
                          .ConfigureAwait(false);

            ViewBag.IsUpdated = updated;
            return(await GetEditView(authenticatedUser !, cancellationToken).ConfigureAwait(false));
        }