Source code for q2_sdk.hq.models.external_auth.change_password

from __future__ import annotations
import base64
from dataclasses import dataclass

from lxml import objectify  # type: ignore

from q2_sdk.tools.utils import to_bool
from .base import BaseAuthRequest, BaseAuthResponse, Password


[docs] @dataclass class Request(BaseAuthRequest): """ Shape that comes in from HQ from a password change request. This can be invoked in the sandbox by navigating to Settings -> Security Preferences -> Change Password .. code-block:: xml <HQ request="ChangePassword" messageID="{0}"> <LoginId>2</LoginId> <Password Encrypted="true">Ns+9NPAJs+PpmIoBirrWGQ==</Password> <OldPassword Encrypted="true">tJ6HqNzIZH0iGVdmH5t6Tw==</OldPassword> <CSRLogin>CSRLoginName</CSRLogin> <UserPrimaryCIF>MDcyMTIwMTA=</UserPrimaryCIF> <CustomerPrimaryCIF>MDcyMTIwMTA=</CustomerPrimaryCIF> <isLogon>True</isLogon> <IsPrelogonSession>False</IsPrelogonSession> <SessionId>shb3cnukdl32c54nodvyxcsj</SessionId> </HQ> """ raw: objectify.Element login_id: int password: Password old_password: Password user_primary_cif: str customer_primary_cif: str is_logon: bool is_prelogon_session: bool session_id: str @staticmethod def from_xml(xml: objectify.Element) -> Request: login_id = int(xml.LoginId.text) password = Password(xml.Password.text, to_bool(xml.Password.get("Encrypted"))) old_password = Password( xml.OldPassword.text, to_bool(xml.Password.get("Encrypted")) ) user_primary_cif = base64.b64decode(xml.UserPrimaryCIF.text).decode() customer_primary_cif = base64.b64decode(xml.CustomerPrimaryCIF.text).decode() is_logon = to_bool(xml.isLogon.text) is_prelogon_session = to_bool(xml.IsPrelogonSession.text) session_id = xml.SessionId.text return Request( xml, login_id, password, old_password, user_primary_cif, customer_primary_cif, is_logon, is_prelogon_session, session_id, )
[docs] @dataclass class Response(BaseAuthResponse): """ .. code-block:: xml <Q2Bridge request="ChangePassword" messageID="messageID"> <Status>"Success"/"Error"</Status> <HQErrorReturnCode>{0}</HQErrorReturnCode> <StatusDescription>{0}</StatusDescription> <PasswordComplexityFailedDescription>{0}</PasswordComplexityFailedDescription> <EndUserMessage>{0}</EndUserMessage> </Q2Bridge> """
[docs] @classmethod def get_failure(cls, password_complexity_failed_description: str): """Same as basic get_failure but can provide a reason for failure""" resp = cls(cls._get_standard_auth_failure_fields()) resp.add_response_field( "password_complexity_failed_description", password_complexity_failed_description, ) return resp