def auth_login(account_main: AccountMain):
        account_main.create_hash_password()
        account_main, err = AccountMainDao().get_by_email_and_hash_password(
            account_main)
        if err:
            return None, err

        if not account_main:
            return None, "Неверный email"

        account_session = AccountSession(account_main=account_main)
        account_session, err = AccountSessionDao().add(account_session)
        if err:
            return None, err

        account_main.auth_token = account_session.create_token()

        return account_main, None
    def register(account_main: AccountMain):
        account_main.create_hash_password()
        account_main.is_confirmed = False
        account_main, errors = AuthService._add_account_main_and_create_session(
            account_main)
        if errors:
            return None, errors

        auth_code = AuthCode(account_main=account_main)
        auth_code.create_random_code()

        _, errors = AuthCodeDao().add(auth_code)
        if errors:
            return None, errors

        account_main.is_email_sent = MailServer.send_email(
            EMAIL_CODE_TYPE, account_main.email, auth_code.code)

        return account_main, None
    def recovery_password(account_main: AccountMain):
        account_main, err = AccountMainDao().get_by_email_and_name(
            account_main)
        if err:
            return None, err

        if not account_main:
            return None, "Неверный email"

        if not account_main.is_confirmed:
            return None, "email не подтвержден"

        account_main.password = get_temp_password()
        account_main.create_hash_password()
        account_main, err = AccountMainDao().set_temp_psw(account_main)
        if err:
            return None, err

        account_main.is_email_sent = MailServer.send_email(
            EMAIL_RECOVERY_PASSWORD_TYPE, account_main.email,
            account_main.password)

        return account_main, None