예제 #1
0
def store_iyo_info_in_userdata(username, user_detail):
    logging.info('Getting the user\'s info from IYO')
    iyo_user = get_user(username)

    api_key = get_rogerthat_api_key()
    user_data_keys = ['name', 'email', 'phone', 'address']
    current_user_data = system.get_user_data(api_key, user_detail.email, user_detail.app_id, user_data_keys)

    user_data = dict()
    if not current_user_data.get('name') and iyo_user.firstname and iyo_user.lastname:
        user_data['name'] = '%s %s' % (iyo_user.firstname, iyo_user.lastname)

    if not current_user_data.get('email') and iyo_user.validatedemailaddresses:
        user_data['email'] = iyo_user.validatedemailaddresses[0].emailaddress

    if not current_user_data.get('phone') and iyo_user.validatedphonenumbers:
        user_data['phone'] = iyo_user.validatedphonenumbers[0].phonenumber

    if not current_user_data.get('address') and iyo_user.addresses:
        user_data['address'] = '%s %s' % (iyo_user.addresses[0].street, iyo_user.addresses[0].nr)
        user_data['address'] += '\n%s %s' % (iyo_user.addresses[0].postalcode, iyo_user.addresses[0].city)
        user_data['address'] += '\n%s' % iyo_user.addresses[0].country
        if iyo_user.addresses[0].other:
            user_data['address'] += '\n\n%s' % iyo_user.addresses[0].other

    if user_data:
        system.put_user_data(api_key, user_detail.email, user_detail.app_id, user_data)
예제 #2
0
파일: hoster.py 프로젝트: FastGeert/tf_app
def set_hoster_status_in_user_data(app_user, can_order=None):
    # type: (users.User, bool) -> None
    if not isinstance(can_order, bool):
        can_order = all(o.status == NodeOrderStatus.CANCELED
                        for o in NodeOrder.list_by_user(app_user))
    user_data = {'hoster': {'can_order': can_order}}
    api_key = get_rogerthat_api_key()
    email, app_id = get_app_user_tuple(app_user)
    current_user_data = system.get_user_data(api_key, email.email(), app_id,
                                             ['hoster'])
    if current_user_data != user_data:
        system.put_user_data(api_key, email.email(), app_id, user_data)
예제 #3
0
def _remove_list(email, app_id, list_id):
    user_data_keys = ['todo_lists']

    api_key = get_rogerthat_api_key()
    current_user_data = system.get_user_data(api_key, email, app_id,
                                             user_data_keys)
    todo_lists = current_user_data.get('todo_lists') or []
    if list_id in todo_lists:
        todo_lists.remove(list_id)
        user_data = {'todo_lists': todo_lists}
        system.put_user_data(api_key, email, app_id, user_data)

    system.del_user_data(api_key, email, app_id, ['todo_%s' % list_id])
예제 #4
0
def _update_list(email, app_id, list_id, progress):
    user_data_keys = ['todo_lists']

    api_key = get_rogerthat_api_key()
    current_user_data = system.get_user_data(api_key, email, app_id,
                                             user_data_keys)
    user_data = {}
    if not current_user_data.get('todo_lists'):
        user_data['todo_lists'] = [list_id]
    elif list_id not in current_user_data.get('todo_lists'):
        user_data['todo_lists'] = current_user_data.get('todo_lists') + [
            list_id
        ]

    user_data['todo_%s' % list_id] = progress

    system.put_user_data(api_key, email, app_id, user_data)
예제 #5
0
파일: hoster.py 프로젝트: FastGeert/tf_app
def _order_node(order_key, user_email, app_id, steps):
    logging.info('Receiving order of Zero-Node')
    app_user = create_app_user_by_email(user_email, app_id)

    overview_step = get_step(steps, 'message_overview')
    if overview_step and overview_step.answer_id == u"button_use":
        api_key = get_rogerthat_api_key()
        user_data_keys = [
            'name', 'email', 'phone', 'billing_address', 'address',
            'shipping_name', 'shipping_email', 'shipping_phone',
            'shipping_address'
        ]
        user_data = system.get_user_data(api_key, user_email, app_id,
                                         user_data_keys)
        billing_info = ContactInfo(name=user_data['name'],
                                   email=user_data['email'],
                                   phone=user_data['phone'],
                                   address=user_data['billing_address']
                                   or user_data['address'])

        if user_data['shipping_name']:
            shipping_info = ContactInfo(name=user_data['shipping_name'],
                                        email=user_data['shipping_email'],
                                        phone=user_data['shipping_phone'],
                                        address=user_data['shipping_address'])
        else:
            shipping_info = billing_info

        updated_user_data = None
    else:
        name = get_step_value(steps, 'message_name')
        email = get_step_value(steps, 'message_email')
        phone = get_step_value(steps, 'message_phone')
        billing_address = get_step_value(steps, 'message_billing_address')
        updated_user_data = {
            'name': name,
            'email': email,
            'phone': phone,
            'billing_address': billing_address,
        }

        billing_info = ContactInfo(name=name,
                                   email=email,
                                   phone=phone,
                                   address=billing_address)

        same_shipping_info_step = get_step(steps,
                                           'message_choose_shipping_info')
        if same_shipping_info_step and same_shipping_info_step.answer_id == u"button_yes":
            shipping_info = billing_info
        else:
            shipping_name = get_step_value(steps, 'message_shipping_name')
            shipping_email = get_step_value(steps, 'message_shipping_email')
            shipping_phone = get_step_value(steps, 'message_shipping_phone')
            shipping_address = get_step_value(steps,
                                              'message_shipping_address')
            updated_user_data.update({
                'shipping_name': shipping_name,
                'shipping_email': shipping_email,
                'shipping_phone': shipping_phone,
                'shipping_address': shipping_address,
            })

            shipping_info = ContactInfo(name=shipping_name,
                                        email=shipping_email,
                                        phone=shipping_phone,
                                        address=shipping_address)
    socket_step = get_step(steps, 'message_socket')
    socket = socket_step and socket_step.answer_id.replace('button_', '')

    # Only one node is allowed per user, and one per location
    if NodeOrder.has_order_for_user_or_location(
            app_user, billing_info.address) and not DEBUG:
        logging.info('User already has a node order, sending abort message')
        msg = u'Dear ThreeFold Member, we sadly cannot grant your request to host an additional ThreeFold Node:' \
              u' We are currently only allowing one Node to be hosted per ThreeFold Member and location.' \
              u' This will allow us to build a bigger base and a more diverse Grid.'
        subject = u'Your ThreeFold Node request'
        send_message_and_email(app_user, msg, subject)
        return

    # Check if user has invested >= 120 tokens
    paid_orders = InvestmentAgreement.list_by_status_and_user(
        app_user, InvestmentAgreement.STATUS_PAID)
    total_tokens = sum([o.token_count_float for o in paid_orders])
    can_host = total_tokens >= REQUIRED_TOKEN_COUNT_TO_HOST

    def trans():
        logging.debug('Storing order in the database')
        order = NodeOrder(key=order_key,
                          app_user=app_user,
                          tos_iyo_see_id=None,
                          billing_info=billing_info,
                          shipping_info=shipping_info,
                          order_time=now(),
                          status=NodeOrderStatus.APPROVED
                          if can_host else NodeOrderStatus.WAITING_APPROVAL,
                          socket=socket)
        order.put()
        if can_host:
            logging.info(
                'User has invested more than %s tokens, immediately creating node order PDF.',
                REQUIRED_TOKEN_COUNT_TO_HOST)
            deferred.defer(_create_node_order_pdf,
                           order_key.id(),
                           _transactional=True)
        else:
            logging.info(
                'User has not invested more than %s tokens, an admin needs to approve this order manually.',
                REQUIRED_TOKEN_COUNT_TO_HOST)
            deferred.defer(_inform_support_of_new_node_order,
                           order_key.id(),
                           _transactional=True)
        deferred.defer(set_hoster_status_in_user_data,
                       order.app_user,
                       False,
                       _transactional=True)
        if updated_user_data:
            deferred.defer(put_user_data,
                           app_user,
                           updated_user_data,
                           _transactional=True)

    ndb.transaction(trans)