Example #1
0
def delete_profile():
    user_key = current_user.key()
    #Sign out and capture the redirect
    response = sign_out()
    #delete the user
    HubUser.delete(user_key)
    #return the redirect
    return response
Example #2
0
def people(page):
    user_query = PagedQuery(HubUser.all(), PAGESIZE)
    users = user_query.fetch_page(page)
    links = PageLinks(page, user_query.page_count(), '/people/').get_links()
    return dict(current_user=current_user,
                users=users,
                links=links,
                page_number=str(page))
Example #3
0
def facebook_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    code = request.args.get('code')
    if code in (None, ''):
        #No code, send back to index page
        return redirect(url_for('index', _external=True))

    response = urllib2.urlopen("https://graph.facebook.com/oauth/access_token?%s" %
                    urllib.urlencode({'client_id': app.config['FACEBOOK_ID'],
                                  'redirect_uri': url_for('facebook_authorized', _external=True),
                                  'client_secret': app.config['FACEBOOK_SECRET'],
                                  'code':code}))
    data = response.read()
    params = dict([part.split('=') for part in data.split('&')])
    session['facebook_access_token'] = params['access_token']
    session['facebook_code'] = code
    
    response = urllib2.urlopen("https://graph.facebook.com/me?%s" %
                    urllib.urlencode({'access_token': session['facebook_access_token']}))
    data = response.read()
    user_info = json.loads(data)
    logging.info(user_info.get('name'))

    facebook_id = user_info.get('id')
    hubid = u'facebook-%s' % facebook_id

    user = HubUser.find(hubid)
    if user is None:
        #This is the first time this Facebook user has signed in
        #to hub-ology.  We'll need to create a new HubUser for them.
        user = HubUser(socnet=u'facebook', userid=facebook_id,
                       hubid=hubid, name=user_info.get('name'))

        user.username = user_info.get('username')
        user.profile_image_url = u'https://graph.facebook.com/%s/picture' % user_info.get('username')
        user.link = user_info.get('link')
        user.gender = user_info.get('gender')
        
        #Save the user
        user.put()
    
    login_user(user)
    #Redirect the user to the 'hub'
    return redirect(url_for('hub', _external=True))
    
Example #4
0
def linkedin_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        return redirect(next_url)

    session['linkedin_token'] = (resp['oauth_token'],
                                 resp['oauth_token_secret'])

    #Fetch linkedin profile information
    info = linkedin.get(
        'v1/people/~:(id,first-name,last-name,public-profile-url,picture-url)',
        data={})
    if info.status == 200:
        xml = info.data
        # logging.info(ElementTree.tostring(xml))
        linkedin_id = xml.findtext(".//id")
        name = u'%s %s' % (xml.findtext(".//first-name"),
                           xml.findtext(".//last-name"))
        link = u'%s' % xml.findtext(".//public-profile-url")
        profile_image_url = u'%s' % xml.findtext(".//picture-url")
        hubid = u'linkedin-%s' % linkedin_id

        user = HubUser.find(hubid)
        if user is None:
            #This is the first time this LinkedIn user has signed in
            #to hub-ology.  We'll need to create a new HubUser for them.
            user = HubUser(socnet=u'linkedin',
                           userid=linkedin_id,
                           hubid=hubid,
                           name=name)

            user.profile_image_url = profile_image_url
            user.link = link

            #Save the user
            user.put()

        login_user(user)
        #Redirect the user to the 'hub'
        return redirect(url_for('hub', _external=True))

    else:
        logging.error('Unable to load profile information for linkedin user')
        return redirect(next_url)
Example #5
0
def linkedin_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        return redirect(next_url)


    session['linkedin_token'] = (
        resp['oauth_token'],
        resp['oauth_token_secret']
    )

    #Fetch linkedin profile information
    info = linkedin.get('v1/people/~:(id,first-name,last-name,public-profile-url,picture-url)', data={})
    if info.status == 200:        
        xml = info.data
        # logging.info(ElementTree.tostring(xml))
        linkedin_id = xml.findtext(".//id")
        name = u'%s %s' % (xml.findtext(".//first-name"), xml.findtext(".//last-name"))
        link = u'%s' % xml.findtext(".//public-profile-url")
        profile_image_url = u'%s' % xml.findtext(".//picture-url")                
        hubid = u'linkedin-%s' % linkedin_id

        user = HubUser.find(hubid)
        if user is None:
            #This is the first time this LinkedIn user has signed in
            #to hub-ology.  We'll need to create a new HubUser for them.
            user = HubUser(socnet=u'linkedin', userid=linkedin_id,
                           hubid=hubid, name=name)

            user.profile_image_url = profile_image_url
            user.link = link
            
            #Save the user
            user.put()
        
        login_user(user)
        #Redirect the user to the 'hub'
        return redirect(url_for('hub', _external=True))
        
    else:
        logging.error('Unable to load profile information for linkedin user')
        return redirect(next_url)
Example #6
0
def people_json():
    """  Need to come up with a better way to get User info to client for mapping, etc.
    """
    users = HubUser.all_with_location()
    return dict(users=users)
Example #7
0
def people(page):
    user_query = PagedQuery(HubUser.all(), PAGESIZE)
    users = user_query.fetch_page(page)
    links = PageLinks(page, user_query.page_count(), '/people/').get_links()    
    return dict(current_user=current_user, users=users, links=links, page_number=str(page))
Example #8
0
def load_user(userid):
    return HubUser.find(userid)
Example #9
0
def twitter_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        return redirect(next_url)

    session['twitter_token'] = (
        resp['oauth_token'],
        resp['oauth_token_secret']
    )

    #Fetch twitter profile information
    info = twitter.get('users/show.json',
                        data={'user_id':resp['user_id']})
    if info.status == 200:        
        hubid = u'twitter-%s' % resp['user_id']

        user = HubUser.find(hubid)
        if user is None:
            #This is the first time this twitter user has signed in
            #to hub-ology.  We'll need to create a new HubUser for them.
            user = HubUser(socnet=u'twitter', userid=resp['user_id'],
                           hubid=hubid, name=info.data.get('name'))

            user.profile_image_url = info.data.get('profile_image_url')
            user.location_name = info.data.get('location')
            user.set_location(geocode_location(user.location_name))
            user.url = info.data.get('url')
            user.username = resp['screen_name']
            user.link = u'https://twitter.com/#!/%s' % resp['screen_name']
            
            #Save the user
            user.put()
        
        login_user(user)
        #Redirect the user to the 'hub'
        return redirect(url_for('hub', _external=True))
    else:
        logging.error('Unable to load profile information for twitter user: %s' % session['twitter_user'])
        return redirect(url_for('sign_in', _external=True))
Example #10
0
def twitter_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    if resp is None:
        return redirect(next_url)

    session['twitter_token'] = (resp['oauth_token'],
                                resp['oauth_token_secret'])

    #Fetch twitter profile information
    info = twitter.get('users/show.json', data={'user_id': resp['user_id']})
    if info.status == 200:
        hubid = u'twitter-%s' % resp['user_id']

        user = HubUser.find(hubid)
        if user is None:
            #This is the first time this twitter user has signed in
            #to hub-ology.  We'll need to create a new HubUser for them.
            user = HubUser(socnet=u'twitter',
                           userid=resp['user_id'],
                           hubid=hubid,
                           name=info.data.get('name'))

            user.profile_image_url = info.data.get('profile_image_url')
            user.location_name = info.data.get('location')
            user.set_location(geocode_location(user.location_name))
            user.url = info.data.get('url')
            user.username = resp['screen_name']
            user.link = u'https://twitter.com/#!/%s' % resp['screen_name']

            #Save the user
            user.put()

        login_user(user)
        #Redirect the user to the 'hub'
        return redirect(url_for('hub', _external=True))
    else:
        logging.error(
            'Unable to load profile information for twitter user: %s' %
            session['twitter_user'])
        return redirect(url_for('sign_in', _external=True))
Example #11
0
def people_json():
    """  Need to come up with a better way to get User info to client for mapping, etc.
    """
    users = HubUser.all_with_location()
    return dict(users=users)