def validate_presenters(presenters):
    """Check validity of  the list of presenters.

    This function should never fail since the checks should already have been made client-side.
     """
    mandatory_keys = ['is_lead', 'email', 'name', 'bio', 'country']
    leads_found = []
    for presenter in presenters:
        for key in mandatory_keys:
            if key not in presenter:
                return False, '{} attribute is mandatory for Presenters'.format(key)
            if presenter[key] is None:
                return False, '{} attribute should have valid data'.format(key)
        if not is_valid_email(presenter['email']):
            return False, '{} not a valid email'.format(presenter['email'])
        if not is_valid_name(presenter['name']):
            return False, '{} not a valid name'.format(presenter['name'])
        if not is_valid_bio(presenter['bio']):
            return False, '{} not a valid bio'.format(presenter['bio'])
        if not is_valid_country(presenter['country']):
            return False, '{} not a valid country'.format(presenter['country'])
        if presenter['is_lead']:
            leads_found.append(presenter['email'])
    lead_count = len(leads_found)
    if lead_count == 0:
        return False, 'No lead presenter.'
    elif lead_count > 1:
        return False, '{} marked as lead presenters'.format(leads_found)
    return True, 'validated'
Esempio n. 2
0
def validate_login_data(login_data):
    if not login_data:
        return False, 'No JSON data returned.'
    mandatory_keys = ['email', 'passphrase']
    missing_keys = [key for key in mandatory_keys if key not in login_data]
    if missing_keys:
        return False, 'Missing keys in registration data: {}'.format(
            missing_keys)
    if not is_valid_email(login_data['email']):
        return False, 'The email address is invalid.'
    user = User.query.filter_by(email=login_data['email']).first()
    if not user or user.passphrase != hash_passphrase(
            login_data['passphrase']):
        return False, 'User/passphrase not recognised.'
    return user, None
def validate_login_data(login_data):
    """Check some aspects of putative login details.

    Return a pair with the zero element being a Boolean determining whether validation
    has been successful, the one element is a message in the case of failure and "validated"
    in the case of success.
    """
    if not login_data:
        return False, 'No JSON data returned.'
    mandatory_keys = ['email', 'passphrase']
    missing_keys = [key for key in mandatory_keys if key not in login_data]
    if missing_keys:
        return False, 'Missing keys in registration data: {}'.format(
            missing_keys)
    if not is_valid_email(login_data['email']):
        return False, 'The email address is invalid.'
    user = User.query.filter_by(email=login_data['email']).first()
    if not user or user.passphrase != hash_passphrase(
            login_data['passphrase']):
        return False, 'User/passphrase not recognised.'
    return user, None
Esempio n. 4
0
def test_string_with_no_at_is_not_email():
    assert not utils.is_valid_email('russel.winder.org.uk')
Esempio n. 5
0
def test_reasonable_email():
    assert utils.is_valid_email('*****@*****.**')