示例#1
0
def facebook_authorized(resp):
    expires = datetime.utcnow() + timedelta(seconds=long(resp['expires']))
    oauth_authorized(provider='facebook', token=resp['access_token'], expires=expires)
    
    # Update service with user id and name
    me = facebook.get('/me')
    current_user.service('facebook').service_user_id = me.data['id']
    current_user.service('facebook').screen_name = me.data['name']
    db.session.commit()
    
    import_albums(current_user.service('facebook'))
    
    return redirect(url_for('account.profile'))
示例#2
0
def google_authorized(resp):
    current_app.logger.debug(resp)
    
    oauth_authorized(provider='google', token=resp['access_token'])
    
    # Update service with user id and name
    info = google.get(endpoints['profile'], headers={'Authorization': 'OAuth ' + resp['access_token']})
    current_app.logger.debug(json.dumps(info.data))
    
    current_user.service('google').service_user_id = info.data['id']
    current_user.service('google').screen_name = info.data['email']
    current_user.service('google').first_name = info.data['given_name']
    current_user.service('google').last_name = info.data['family_name']
    
    if info.data['email'] and not current_user.email:
        current_user.email = info.data['email']
        
    db.session.commit()
    
    import_photos(current_user.service('google'))
    
    return redirect(url_for('account.profile'))
示例#3
0
def foursquare_authorized(resp):
    current_app.logger.debug(resp)
    
    oauth_authorized(provider='foursquare', token=resp['access_token'])
    
    # Update service with user id and name
    current_app.logger.debug(_get_endpoint('users/self'))
    info = foursquare.get(_get_endpoint('users/self'))
    current_app.logger.debug(json.dumps(info.data))
    
    current_user.service('foursquare').service_user_id = info.data['response']['user']['id']
    current_user.service('foursquare').first_name = info.data['response']['user']['firstName']
    current_user.service('foursquare').last_name = info.data['response']['user']['lastName']
    
    if info.data['response']['user']['firstName'] and not current_user.first_name:
        current_user.first_name = info.data['response']['user']['firstName']
        current_user.last_name = info.data['response']['user']['lastName']
        
    if info.data['response']['user']['homeCity'] and not current_user.city:
        current_user.city = info.data['response']['user']['homeCity']
        
    db.session.commit()
    
    return redirect(url_for('account.profile'))
示例#4
0
def twitter_authorized(resp):    
    oauth_authorized(provider='twitter', service_user_id=resp['user_id'], screen_name=resp['screen_name'], token=resp['oauth_token'], secret=resp['oauth_token_secret'])
    return redirect(url_for('account.profile'))