Exemplo n.º 1
0
def login_view(request):
  if (not 'fb_id' in request.POST or
      not 'fb_token' in request.POST):
    raise PermissionDenied

  fb_id = request.POST['fb_id']

  graph = Graph(request.POST['fb_token'])
  personal_data = graph.get_personal_data()

  if personal_data.get(u'id', None) != unicode(fb_id):
    raise PermissionDenied

  try:
    user_profile = Person.objects.get(fbid=fb_id)
    user_profile.update_info(personal_data)
  except Person.DoesNotExist:
    user_profile = Person.create_user(personal_data)
    update_movies(user_profile, graph)

    all_friend_data = graph.get_personal_data_multi(graph.get_friends(fb_id))
    for friend_id, friend_data in all_friend_data.iteritems():
      try:
        friend_profile = Person.objects.get(fbid=friend_id)
        friend_profile.update_info(friend_data)
      except Person.DoesNotExist:
        friend_profile = Person.create_user(friend_data)
        update_movies(friend_profile, graph)

      user_profile.friends.add(friend_profile)

  user = authenticate(username=fb_id,
                      password=Person.get_user_password(fb_id))
  login(request, user)
  return HttpResponse("OK")
Exemplo n.º 2
0
def test(request):
  #TODO: this seems broken
  #TODO: mb look into fixing this so that we get friend's movies
  #user = request.user.get_profile()
  #fbid = user.fbid
  #TODO: UNHACK
  fbid = 100000003935672
  user_profile = Person.objects.get(fbid=fbid)
  graph = Graph('AAAAAAITEghMBALnZCyaZBHvSHmcjOCffC2nZA4vrLG0aRh9ZCDpNMW7YnGLBmzWPZBRQ3VAazIdvh0SCxRQuLbiOOAe2LS44gIj2ymTg0QuuNUHZCSu1Yr')

  update_movies(user_profile, graph)
  friends = graph.get_friends(fbid)
  for f in friends:
    friend_profile = Person.objects.get(fbid=f)
    update_movies(friend_profile, graph)
  return HttpResponse(json.dumps(friends),
      content_type='application/json')