コード例 #1
0
ファイル: login.py プロジェクト: SamvitJ/21BC-lib
def _login(config, user):
    if config.username:
        click.secho("currently logged in as: {}".format(config.username), fg="blue")

    # get machine auth
    if hasattr(config, "machine_auth"):
        machine_auth = config.machine_auth
    else:
        dp = TwentyOneProvider(TWO1_PROVIDER_HOST)
        wallet_path = Two1Wallet.DEFAULT_WALLET_PATH
        if not Two1Wallet.check_wallet_file(wallet_path):
            create_wallet_and_account()
            return

        wallet = Wallet(wallet_path=wallet_path,
                        data_provider=dp)
        machine_auth = MachineAuthWallet(wallet)

    client = rest_client.TwentyOneRestClient(TWO1_HOST,
                                             machine_auth)

    # get a list of all usernames for device_id/wallet_pk pair
    res = client.account_info()
    usernames = res.json()["usernames"]
    if len(usernames) == 0:
        create_wallet_and_account()
        return


    else:
        if user is None:
            # interactively select the username
            counter = 1
            click.secho(UxString.registered_usernames_title)
            for user in usernames:
                click.secho("{}- {}".format(counter, user))
                counter += 1

            username_index = -1
            while username_index <= 0 or username_index > len(usernames):
                username_index = click.prompt(UxString.login_prompt, type=int)
                if username_index <= 0 or username_index > len(usernames):
                    click.secho(UxString.login_prompt_invalid_user.format(1, len(usernames)))

            username = usernames[username_index - 1]
        else:
            # log in with provided username
            if user in usernames:
                username = user
            else:
                click.secho(UxString.login_prompt_user_does_not_exist.format(user))
                return

        # save the selection in the config file
        save_config(config, machine_auth, username)
コード例 #2
0
ファイル: authentication.py プロジェクト: masonicGIT/two1
from two1.commands.config import TWO1_PROVIDER_HOST
from two1.lib.bitserv import PaymentServer, DatabaseDjango
from two1.lib.blockchain.twentyone_provider import TwentyOneProvider
from two1.lib.blockchain.exceptions import DataProviderError
from two1.examples.bitcoin_auth.helpers.bitcoin_auth_provider_helper import (
    BitcoinAuthProvider
)

from .models import BitcoinToken, PaymentChannel, PaymentChannelSpend
from .pricing import get_price_for_request
from .exceptions import PaymentRequiredException
from .exceptions import ServiceUnavailable

if settings.WALLET_MNEMONIC:
    dp = TwentyOneProvider(TWO1_PROVIDER_HOST)
    wallet = Two1Wallet.import_from_mnemonic(dp, settings.WALLET_MNEMONIC)
else:
    wallet = Wallet()
payment_server = PaymentServer(
    wallet, DatabaseDjango(PaymentChannel, PaymentChannelSpend))


class BaseBitcoinAuthentication(BaseAuthentication):

    """Basic Bitcoin authentication.

    Attributes:
        bitcoin_provider_helper (BlockchainProvider): provides
            an api & helper methods into the blockchain.
    """
コード例 #3
0
ファイル: authentication.py プロジェクト: erikvold/two1
from two1.lib.wallet import Wallet, Two1Wallet
from two1.commands.config import TWO1_PROVIDER_HOST
from two1.lib.bitserv import PaymentServer, DatabaseDjango
from two1.lib.blockchain.twentyone_provider import TwentyOneProvider
from two1.lib.blockchain.exceptions import DataProviderError
from two1.examples.bitcoin_auth.helpers.bitcoin_auth_provider_helper import (
    BitcoinAuthProvider)

from .models import BitcoinToken, PaymentChannel, PaymentChannelSpend
from .pricing import get_price_for_request
from .exceptions import PaymentRequiredException
from .exceptions import ServiceUnavailable

if settings.WALLET_MNEMONIC:
    dp = TwentyOneProvider(TWO1_PROVIDER_HOST)
    wallet = Two1Wallet.import_from_mnemonic(dp, settings.WALLET_MNEMONIC)
else:
    wallet = Wallet()
payment_server = PaymentServer(
    wallet, DatabaseDjango(PaymentChannel, PaymentChannelSpend))


class BaseBitcoinAuthentication(BaseAuthentication):
    """Basic Bitcoin authentication.

    Attributes:
        bitcoin_provider_helper (BlockchainProvider): provides
            an api & helper methods into the blockchain.
    """

    bitcoin_provider_helper = BitcoinAuthProvider()