Skip to content

Commit

Permalink
add is email exists before reset password
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed Jul 6, 2024
1 parent 146a4ca commit 0e3c1f9
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions custom_components/mydolphin_plus/managers/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,28 @@ async def reset_password(self):
if self._session is None:
await self._initialize_session()

username = self.config_data.username
is_valid_email = await self._email_validation()

request_data = f"{API_REQUEST_SERIAL_EMAIL}={username}"

payload = await self._async_post(
FORGOT_PASSWORD_URL, LOGIN_HEADERS, request_data
)
if is_valid_email:
username = self.config_data.username

if payload is None:
_LOGGER.error("Empty response of reset password")
request_data = f"{API_REQUEST_SERIAL_EMAIL}={username}"

else:
data = payload.get(API_RESPONSE_DATA)
payload = await self._async_post(
FORGOT_PASSWORD_URL, LOGIN_HEADERS, request_data
)

if data is None:
_LOGGER.error("Empty response payload of reset password")
if payload is None:
_LOGGER.error("Empty response of reset password")

else:
_LOGGER.info(f"Reset password response: {data}")
data = payload.get(API_RESPONSE_DATA)

if data is None:
_LOGGER.error("Empty response payload of reset password")

else:
_LOGGER.info(f"Reset password response: {data}")

async def _email_validation(self) -> bool:
_LOGGER.debug("Validating account email")
Expand Down

0 comments on commit 0e3c1f9

Please sign in to comment.