Exemplo n.º 1
0
def _get_known_information(username):
    date_of_birth = datetime.datetime.now()
    date_of_birth = date_of_birth.replace(year=date_of_birth.year - 18, hour=0, minute=0, second=0, microsecond=0)
    known_information = {
        'first_name': None,
        'last_name': None,
        'email': None,
        'telephone': None,
        'address_building_number': None,
        'address_street': None,
        'address_town': None,
        'address_postcode': None,
        'dob': long(time.mktime(date_of_birth.timetuple())),
    }
    profile = get_profile(username)
    if profile.info:
        if profile.info.firstname:
            known_information['first_name'] = profile.info.firstname
        if profile.info.lastname:
            known_information['last_name'] = profile.info.lastname
        if profile.info.validatedphonenumbers:
            known_information['telephone'] = profile.info.validatedphonenumbers[0].phonenumber
        elif profile.info.phonenumbers:
            known_information['telephone'] = profile.info.phonenumbers[0].phonenumber
        if profile.info.validatedemailaddresses:
            known_information['email'] = profile.info.validatedemailaddresses[0].emailaddress
        elif profile.info.emailaddresses:
            known_information['email'] = profile.info.emailaddresses[0].emailaddress
        if profile.info.addresses:
            known_information['address_street'] = profile.info.addresses[0].street
            known_information['address_building_number'] = profile.info.addresses[0].nr
            known_information['address_town'] = profile.info.addresses[0].city
            known_information['address_postcode'] = profile.info.addresses[0].postalcode
    return known_information
Exemplo n.º 2
0
def notify_stalled_flow_run(flow_run_key):
    flow_run = flow_run_key.get()  # type: FlowRun
    if not should_notify_for_flow(flow_run):
        return
    url = get_base_url() + '/flow-statistics/%s/%s' % (flow_run.flow_name,
                                                       flow_run.id),
    subject = 'Stalled flow %s' % flow_run.flow_name
    profile = get_profile(flow_run.user)
    body = 'User %s appears to be stuck in the %s flow. Click the following link to check the details: %s' % (
        profile.full_name or profile.username, flow_run.flow_name, url)
    send_emails_to_support(subject, body)
Exemplo n.º 3
0
def transfer_genesis_coins_to_user(app_user,
                                   token_type,
                                   amount,
                                   memo=None,
                                   epoch=0):
    validate_token_type(token_type)
    if amount <= 0:
        raise HttpBadRequestException('invalid_amount')
    # Validate that this user has a profile
    get_profile(get_iyo_username(app_user))
    if epoch > 0:
        date_signed = datetime.utcfromtimestamp(epoch)
    else:
        date_signed = datetime.now()

    if TokenType.A == token_type:
        token = TOKEN_TFT
        unlock_timestamps = [0]
        unlock_amounts = [amount]

    elif TokenType.B == token_type:
        token = TOKEN_TFT
        d = date_signed + relativedelta(months=6)
        unlock_timestamps = [get_epoch_from_datetime(d)]
        unlock_amounts = [amount]

    elif TokenType.C == token_type:
        token = TOKEN_TFT
        unlock_timestamps = []
        unlock_amounts = []
        a = amount / 48
        for i in xrange(0, 39):
            d = date_signed + relativedelta(months=48 - i)
            unlock_timestamps = [get_epoch_from_datetime(d)
                                 ] + unlock_timestamps
            unlock_amounts = [a] + unlock_amounts

        d = date_signed + relativedelta(months=9)
        unlock_timestamps = [get_epoch_from_datetime(d)] + unlock_timestamps
        unlock_amounts = [amount - sum(unlock_amounts)] + unlock_amounts

    elif TokenType.D == token_type:
        token = TOKEN_TFT_CONTRIBUTOR
        unlock_timestamps = [0]
        unlock_amounts = [amount]

    elif TokenType.I == token_type:
        token = TOKEN_ITFT
        unlock_timestamps = [0]
        unlock_amounts = [amount]

    else:
        raise Exception(u"Unknown token type")

    key = ThreeFoldWallet.create_key(app_user)
    wallet = key.get()
    if not wallet:
        wallet = ThreeFoldWallet(key=key, tokens=[])

    if token not in wallet.tokens:
        wallet.tokens.append(token)

    if unlock_timestamps[0] > 0 and (
            not wallet.next_unlock_timestamp
            or unlock_timestamps[0] < wallet.next_unlock_timestamp):
        wallet.next_unlock_timestamp = unlock_timestamps[0]

    wallet.put()

    transaction_id = unicode(uuid.uuid4())
    pt = ThreeFoldPendingTransaction(
        key=ThreeFoldPendingTransaction.create_key(transaction_id),
        timestamp=now(),
        unlock_timestamps=unlock_timestamps,
        unlock_amounts=unlock_amounts,
        token=token,
        token_type=token_type,
        amount=amount,
        memo=memo,
        app_users=[app_user],
        from_user=None,
        to_user=app_user,
        synced=False,
        synced_status=ThreeFoldPendingTransaction.STATUS_PENDING)
    pt.put()
    return pt
Exemplo n.º 4
0
def api_get_user(username):
    username = username.decode('utf-8')  # username must be unicode
    return get_profile(username).to_dict()