Beispiel #1
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
Beispiel #2
0
def create_user(is_admin=False, **kw):

    kw.setdefault("email", create_email_address())
    kw.setdefault("username", create_unique_str(u'user', extra=u''))
    kw.setdefault("password", u'testpassword')
    
    if is_admin:
        kw.setdefault("role", users.ROLE_ADMIN)
    else:
        kw.setdefault("role", users.ROLE_USER)

    user = users.User(**kw)
    Session.add(user)
    Session.flush()
    return user
Beispiel #3
0
def create(user, **params):
    """
    Creates a profile.
    
    DO NOT EXPOSE THIS to the web api. Please.
    """
    if user and user.profile:
        raise AppException('User cannot have an existing profile.', field='user', code=INVALID)
    
    params.setdefault('is_active', True)
    
    scrubbed = validate(CreateForm, **params)
    
    profile = profiles.Profile(user=user, **scrubbed)
    Session.add(profile)
    
    return profile
Beispiel #4
0
def create(**params):
    """
    Creates a user.
    
    DO NOT EXPOSE THIS to the web api. Please.
    """
    numusers = len(Session.query(users.User).all())
    
    scrubbed = validate(RegisterForm, **params)
    
    user = users.User()
    Session.add(user)
    
    user.email = scrubbed.email
    user.username = '******' in scrubbed and scrubbed.username or scrubbed.email
    user.password = scrubbed.password
    user.set_timezone_int(scrubbed.default_timezone)
    
    if scrubbed.get('name'):
        name = scrubbed.get('name').split(' ', 1)
        user.first_name = name[0].strip()
        user.last_name = len(name) == 2 and name[1].strip() or u''
    else:
        user.first_name = scrubbed.get('first_name')
        user.last_name = scrubbed.get('last_name')
    
    #first user is an admin. 
    if numusers == 0:
        user.role = users.ROLE_ADMIN
    
    #this will need some thought. We should have some kind of verification.
    profile = profiles.Profile.find_unclaimed(user.email)
    if profile:
        profile.user = user
    else:
        from tethr import api
        profile = api.profile.create(user)
    
    if user.first_name or user.last_name:
        profile.add_data(user, 'name', u'%s %s' % (user.first_name, user.last_name))
    
    profile.add_data(user, 'email', user.email)
    
    Session.flush()
    
    return user
Beispiel #5
0
def create_profile(user='******', **kw):
    if user == 'create':
        user = create_user()
    
    kw.setdefault("is_active", True)
    kw.setdefault("user", user)
    kw.setdefault('name', create_unique_str(pre=u'name'))
    kw.setdefault('email', user and user.email or create_email_address())
    
    name = kw.pop('name')
    email = kw.pop('email')
    
    profile = profiles.Profile(**kw)
    Session.add(profile)
    
    if user:
        profile.add_data(user, 'name', name)
        profile.add_data(user, 'email', email)
    
    Session.flush()
    return profile