public async Task <ChangePasswordResultModel> ChangePasswordAsync(string customerId, string password) { if (string.IsNullOrEmpty(customerId)) { throw new ArgumentNullException(nameof(customerId)); } if (string.IsNullOrEmpty(password)) { throw new ArgumentNullException(nameof(password)); } var customerResponse = await _customerProfileClient.CustomerProfiles.GetByCustomerIdAsync(customerId, true); if (customerResponse.ErrorCode == CustomerProfileErrorCodes.CustomerProfileDoesNotExist) { return(new ChangePasswordResultModel(ServicesError.LoginNotFound)); } var customerFlags = await _customerFlagsRepository.GetByCustomerIdAsync(customerId); if (customerFlags != null && customerFlags.IsBlocked) { return(new ChangePasswordResultModel(ServicesError.CustomerBlocked)); } try { await _credentialsClient.Api.ChangePasswordAsync(new CredentialsUpdateRequest { CustomerId = customerId, Password = password, Login = customerResponse.Profile.Email }); await _postProcessService.ClearSessionsAndSentEmailAsync(customerId, _passwordSuccessfulChangeEmailTemplateId, _passwordSuccessfulChangeEmailSubjectTemplateId); return(new ChangePasswordResultModel()); } catch (ClientApiException e) when(e.HttpStatusCode == HttpStatusCode.BadRequest) { if (e.ErrorResponse.ModelErrors.ContainsKey(nameof(CredentialsCreateRequest.Password))) { return(new ChangePasswordResultModel(ServicesError.InvalidPasswordFormat)); } _log.Error(e, "Tried to change password of non-existing customer", customerId); throw; } }
public async Task <PasswordResetError> PasswordResetAsync( string customerEmail, string identifier, string newPassword) { var customer = await _customerProfileClient.CustomerProfiles.GetByEmailAsync( new GetByEmailRequestModel { Email = customerEmail, IncludeNotVerified = true }); if (customer?.Profile == null) { _log.Info($"Unable to Finish Reset password procedure cause customer with {customerEmail} doesn't exist"); return(new PasswordResetError { Error = PasswordResetErrorCodes.NoCustomerWithSuchEmail }); } var customerFlags = await _customerFlagsRepository.GetByCustomerIdAsync(customer.Profile.CustomerId); if (customerFlags != null && customerFlags.IsBlocked) { return new PasswordResetError { Error = PasswordResetErrorCodes.CustomerBlocked } } ; try { var result = await _credentialsClient.Api.PasswordResetAsync(new PasswordResetRequest { CustomerEmail = customerEmail, ResetIdentifier = identifier, Password = newPassword }); if (result.Error == Credentials.Client.Enums.PasswordResetError.None) { await _postProcessService.ClearSessionsAndSentEmailAsync(customer.Profile?.CustomerId, _passwordSuccessfulResetEmailTemplateId, _passwordSuccessfulResetEmailSubjectTemplateId); } return(_mapper.Map <PasswordResetError>(result)); } catch (ClientApiException e) when(e.HttpStatusCode == HttpStatusCode.BadRequest) { _log.Info(e.Message); return(new PasswordResetError { Error = PasswordResetErrorCodes.InvalidPasswordFormat }); } }