Esempio n. 1
0
def add_data(real_user, user, profile, **kw):
    """
    can pass in data like 'phone:work'='555-555-5555'
    """
    if not profile:
        abort(403)
        
    forbidden_keys = ['latitude', 'longitude']
    
    class KVForm(formencode.Schema):
        key = fv.UnicodeString(not_empty=True, min=2, max=64)
        type = fv.OneOf([TYPE_WORK, TYPE_HOME, TYPE_MOBILE], not_empty=False)
        value = fv.UnicodeString(not_empty=True, min=2, max=1024)
    
    for k, v in kw.items():
        type = None
        s = k.split(':', 1)
        if len(s) == 2:
            k, type = s
        
        if k in forbidden_keys: continue
        
        if v:
            scrubbed = validate(KVForm, key=k, value=v, type=type)
            
            profile.add_data(user, scrubbed.key, scrubbed.value, type=scrubbed.type)
    
    Session.flush()
    
    return profile
Esempio n. 2
0
def teather(real_user, user, profile=None, email=None, latitude=None, longitude=None, **kw):
    """
    Will teather/follow another user
    
    kw can be extra data to be asscoiated with the teather. Passing a type is done
    by using a colon. i.e.
    
    kw['phone'] = '415-343-1234' # would just add a phone number
    kw['phone:work'] = '415-343-1234' # would add a phone number with type work
    
    also, notes are associated the same way as everything else.
    
    kw['notes'] = 'We met at the xyz blah'
    """
    if (not profile and not email) or not user.profile:
        abort(403)
    
    profile = get(real_user, user, profile=profile, email=email)
    if not profile and not email:
        abort(403)
    
    #create unclaimed
    elif not profile:
        email = validate(TeatherForm, email=email).email
        
        profile = profiles.Profile(user=None)
        Session.add(profile)
        Session.flush()
    
    add_data(real_user, user, profile, **kw)
    
    #attach an email address...
    if not email and profile.user:
        email = profile.user.email
    
    
    #all_data = profile.fetch_data()
    #has_email = False
    #for d in all_data:
    #    if d.key == 'email':
    #        has_email = True
    #        if (email and data.EmailHandler.normalize(email) != d.value):
    #            profile.add_data(user, 'email', email, type=d.type)
    
    #if not has_email and not email:
    #    raise ClientException('Need to specify an email address!')
    #elif not has_email:
    
    if email:
        profile.add_data(user, 'email', email)
    
    t = user.profile.teather(profile, latitude=latitude, longitude=longitude)
    Session.flush()
    
    return t
Esempio n. 3
0
def explode_no_auth(real_user, user, type=None, **kw):
    """
    An action to test the error handling of the stack. The tests use this.
    """
    if type == 'app':
        raise AppException('This is an app exception!', code=INVALID, field='type')
    elif type == 'client':
        raise ClientException('Oh Noes, ClientException!', code=INVALID, field='type')
    elif type == 'client404':
        raise ClientException('Oh Noes, ClientException NOT FOUND!', code=NOT_FOUND, field='type')
    elif type == 'client403':
        raise ClientException('Oh Noes, ClientException FORBIDDEN!', code=FORBIDDEN, field='type')
    elif type == 'explosion':
        1/0
    elif type == 'http':
        abort(404, 'This thing was not found!')
    elif type == 'validation':
        class Rawr(formencode.Schema):
            meow = fv.Number()
        scrubbed = validate(Rawr, meow='zzzz')
    
    return kw
Esempio n. 4
0
def get(real_user, user, id):
    if not id:
        abort(403)
    return id