Exemple #1
0
    def create(self, form, bank_account_form):
        listing_id = form.listing_id.data
        email_address = form.email_address.data
        name = form.name.data
        merchant_data = form.data.copy()
        password = merchant_data.pop('password', None)
        month = merchant_data.pop('date_of_birth_month')
        year = merchant_data.pop('date_of_birth_year')
        merchant_data['dob'] = '{}-{}'.format(year, month)
        merchant_data.pop('listing_id')
        if not merchant_data.get('email_address', None):
            merchant_data.pop('email_address', None)

        if request.user.is_authenticated:
            user = request.user
        else:
            user = User.create_guest_user(email_address, name, password)
            # do this password check as a guest user should not be able to take
            # over an existing account without authentication
            # flush to ensure password gets hashed
            Session.flush()
            if user.has_password and not user.check_password(password):
                raise Exception('Password mismatch')

        if not user.account_uri:
            self.create_balanced_account(user, merchant_data=merchant_data)
        else:
            user.add_merchant(merchant_data)

        if bank_account_form.bank_account_uri.data:
            user.balanced_account.add_bank_account(
                bank_account_form.bank_account_uri.data)

        return listing_id
Exemple #2
0
    def create(self, form, bank_account_form):
        listing_id = form.listing_id.data
        email_address = form.email_address.data
        name = form.name.data
        merchant_data = form.data.copy()
        password = merchant_data.pop('password', None)
        month = merchant_data.pop('date_of_birth_month')
        year = merchant_data.pop('date_of_birth_year')
        merchant_data['dob'] = '{}-{}'.format(year, month)
        merchant_data.pop('listing_id')
        if not merchant_data.get('email_address', None):
            merchant_data.pop('email_address', None)

        if request.user.is_authenticated:
            user = request.user
        else:
            user = User.create_guest_user(email_address, name, password)
            # do this password check as a guest user should not be able to take
            # over an existing account without authentication
            # flush to ensure password gets hashed
            Session.flush()
            if user.has_password and not user.check_password(password):
                raise Exception('Password mismatch')

        if not user.account_uri:
            self.create_balanced_account(user, merchant_data=merchant_data)
        else:
            user.add_merchant(merchant_data)

        if bank_account_form.bank_account_uri.data:
            user.balanced_account.add_bank_account(
                bank_account_form.bank_account_uri.data)

        return listing_id
Exemple #3
0
    def create(self, form, bank_account_form):
        listing_id = form.listing_id.data
        email = form.email.data
        name = form.name.data
        merchant_data = form.data.copy()
        password = merchant_data.pop('password', None)
        month = merchant_data.pop('dob_month')
        year = merchant_data.pop('dob_year')
        merchant_data['dob_month'] = month
        merchant_data['dob_year'] = year
        merchant_data.pop('listing_id')
        if not merchant_data.get('email', None):
            merchant_data.pop('email', None)

        if request.user.is_authenticated:
            user = request.user
        else:
            user = User.create_guest_user(email, name, password)
            # do this password check as a guest user should not be able to take
            # over an existing account without authentication
            # flush to ensure password gets hashed
            Session.flush()
            if user.has_password and not user.check_password(password):
                raise Exception('Password mismatch')

        if not user.account_href:
            self.create_balanced_customer(user, merchant_data=merchant_data)
        else:
            user.add_merchant(merchant_data)

        if bank_account_form.bank_account_href.data:
            bank_account = balanced.BankAccount.fetch(
                bank_account_form.bank_account_href.data)
            bank_account.associate_to_customer(user.balanced_customer.href)
        return listing_id
Exemple #4
0
    def create(self, form, bank_account_form):
        listing_id = form.listing_id.data
        email = form.email.data
        name = form.name.data
        merchant_data = form.data.copy()
        password = merchant_data.pop("password", None)
        month = merchant_data.pop("dob_month")
        year = merchant_data.pop("dob_year")
        merchant_data["dob_month"] = month
        merchant_data["dob_year"] = year
        merchant_data.pop("listing_id")
        if not merchant_data.get("email", None):
            merchant_data.pop("email", None)

        if request.user.is_authenticated:
            user = request.user
        else:
            user = User.create_guest_user(email, name, password)
            # do this password check as a guest user should not be able to take
            # over an existing account without authentication
            # flush to ensure password gets hashed
            Session.flush()
            if user.has_password and not user.check_password(password):
                raise Exception("Password mismatch")

        if not user.account_href:
            self.create_balanced_customer(user, merchant_data=merchant_data)
        else:
            user.add_merchant(merchant_data)

        if bank_account_form.bank_account_href.data:
            bank_account = balanced.BankAccount.fetch(bank_account_form.bank_account_href.data)
            bank_account.associate_to_customer(user.balanced_customer.href)
        return listing_id
Exemple #5
0
    def add_dummy_data(self):
        user = User(
            name='Dummy User', email=self.dummy_email_generator(),
            password='******')
        Session.add(user)
        user.create_balanced_customer()

        for i in range(4):
            owner = User.fetch_one_at_random()
            if not user.balanced_customer.bank_accounts.count():
                self.dummy_bank_account_generator(owner)
            listing = Listing.query.filter(Listing.id == i + 1).count()
            if not listing:
                listing = Listing(id=i + 1, owner_guid=owner.guid)
                Session.add(listing)

        Session.commit()
Exemple #6
0
    def _associate_email_and_account(self, email_address, account_uri):
        if request.user.is_authenticated:
            user = request.user
        else:
            # we're creating an account as they list, create a guest user.
            user = User.create_guest_user(email_address)
            # flush to db, to force guid creation as we're about to log them
            # in.
            Session.flush()
            session['user_guid'] = user.guid
        user.associate_account_uri(account_uri)

        return user
Exemple #7
0
    def _associate_email_and_account(self, email_address, account_uri):
        if request.user.is_authenticated:
            user = request.user
        else:
            # we're creating an account as they list, create a guest user.
            user = User.create_guest_user(email_address)
            # flush to db, to force guid creation as we're about to log them
            # in.
            Session.flush()
            session['user_guid'] = user.guid
        user.associate_account_uri(account_uri)

        return user
    def add_dummy_data(self):
        for name, email, password in config['DEFAULT_USERS']:
            user = User.query.filter(User.email_address == email).count()
            if not user:
                user = User(name=name, email_address=email, password=password)
                Session.add(user)

        for i in range(4):
            listing = Listing.query.filter(Listing.id == i + 1).count()
            if not listing:
                listing = Listing(id=i + 1)
                Session.add(listing)

        Session.commit()
    def _populate_data(self):
        if not User.query.count():
            for name, email, password in [
                ('Marshall Jones', '*****@*****.**', 'secret'),
                ('Matin Tamizi', '*****@*****.**', 'secret'),
            ]:
                user = User(name=name, email=email, password=password)
                self.session.add(user)

        if not Listing.query.count():
            for i in range(4):
                listing = Listing()
                self.session.add(listing)

        self.session.flush()
Exemple #10
0
    def rent(self, listing, email_address, card_uri, name=None):
        Session.flush()
        if request.user.is_authenticated:
            user = request.user
        else:
            user = User.create_guest_user(email_address, name)

            # this user has not authenticated with their email/password combo
            # we cannot allow them to charge an existing card if it exists
            if not card_uri:
                raise Exception('Non-authenticated user must supply card data')

        Session.flush()  # ensure there is no db inconsistency
        if not user.account_uri:
            self.create_balanced_account(user, card_uri)
        else:
            if card_uri:
                user.add_card(card_uri)

        Session.flush()  # ensure there is no db inconsistency
        return listing.rent_to(user, card_uri)
Exemple #11
0
    def rent(self, listing, email, card_href, name=None):

        Session.flush()
        if request.user.is_authenticated:
            user = request.user
        else:
            user = User.create_guest_user(email, name)

            # this user has not authenticated with their email/password combo
            # we cannot allow them to charge an existing card if it exists
            if not card_href:
                raise Exception('Non-authenticated user must supply card data')

        Session.flush()  # ensure there is no db inconsistency
        if not user.account_href:
            self.create_balanced_customer(user, card_href)
        else:
            if card_href:
                user.add_card(card_href)

        Session.flush()  # ensure there is no db inconsistency
        return listing.rent_to(user, card_href)