Пример #1
0
def facebook_comment(request):
  response = {}
  fb_account = FacebookAccount.get_account(request.user.id)
  if fb_account is None:
    response['success'] = 'false'
    response['message'] = 'Failed to get data for user'
    return response
  response['success'] = 'true'
  try:
    facebook_api.facebook_comment_post(request.POST.get('postId'), request.POST.get('message'), fb_account.access_token)
  except urllib2.HTTPError:
    print "Error: Token is invalid"
    return get_fb_url(1)
  return response
Пример #2
0
def facebook_like(request):
    response = {}
    fb_account = FacebookAccount.get_account(request.user.id)
    if fb_account is None:
        response['success'] = 'false'
        response['message'] = 'Failed to get data for user'
        return response
    response['success'] = 'true'
    try:
        facebook_api.facebook_like_post(request.POST.get('postId'),
                                        fb_account.access_token)
    except urllib2.HTTPError:
        print "Error: Token is invalid"
        return get_fb_url(1)
    return response
Пример #3
0
def facebook_access(request):
  print "got to fb access"
  fb_access_token = request.POST.get('token')
  print "trying to get user data from db"
  fb_account = FacebookAccount.get_account(request.user.id)
  if fb_account is None:
    print "was not able to get user data from db"
    fb_account = FacebookAccount(user_id=request.user, access_token=fb_access_token)
  else:
    fb_account.access_token = fb_access_token
  fb_account.save()
  print "should be returning success"
  return_dict = {}
  return_dict['success'] = 'true'
  return HttpResponse(json.dumps(return_dict))
Пример #4
0
def facebook_access(request):
    print "got to fb access"
    fb_access_token = request.POST.get('token')
    print "trying to get user data from db"
    fb_account = FacebookAccount.get_account(request.user.id)
    if fb_account is None:
        print "was not able to get user data from db"
        fb_account = FacebookAccount(user_id=request.user,
                                     access_token=fb_access_token)
    else:
        fb_account.access_token = fb_access_token
    fb_account.save()
    print "should be returning success"
    return_dict = {}
    return_dict['success'] = 'true'
    return HttpResponse(json.dumps(return_dict))
Пример #5
0
def facebook_feed_request(request):
  response = {}
  fb_account = FacebookAccount.get_account(request.user.id)
  #case where user has not added FB account yet
  if fb_account is None:
    response['success'] = 'false'
    response['message'] = 'Failed to get data for user'
    return response
  try:
  #success case, we can get their
    print "trying to get stuff from fb"
    response['success'] = 'true'
    response['updates'] = facebook_api.facebook_read_user_status_updates(fb_account.access_token)
  except Exception:
    #invalid token
    print "FB Error: Token is invalid"
    return get_fb_url(1)
  return response
Пример #6
0
def facebook_feed_request(request):
    response = {}
    fb_account = FacebookAccount.get_account(request.user.id)
    #case where user has not added FB account yet
    if fb_account is None:
        response['success'] = 'false'
        response['message'] = 'Failed to get data for user'
        return response
    try:
        #success case, we can get their
        print "trying to get stuff from fb"
        response['success'] = 'true'
        response['updates'] = facebook_api.facebook_read_user_status_updates(
            fb_account.access_token)
    except Exception:
        #invalid token
        print "FB Error: Token is invalid"
        return get_fb_url(1)
    return response
Пример #7
0
def signin(request):
  if request.method == 'POST':
    email = request.POST['email']
    password = request.POST['password']
    user = authenticate(email=email, password=password)

    if (user is not None) and (user.is_active):
      login(request, user)
      facebook_account = FacebookAccount.get_account(request_id=request.user.id)
      twitter_account = TwitterAccount.get_account(request_id=request.user.id)
      if facebook_account is None and twitter_account is None:
        return redirect('/feed/', {'username': email})
      else:
        return redirect('/feed/', {'username': email})
    else:
      form = EmailAuthenticationForm()
      form.non_field_errors = 'Your email and password were incorrect.'
      return render(request, 'index.html', {'form': form})
  else:
    form = EmailAuthenticationForm()

  return render(request, 'index.html', {'form': form})
Пример #8
0
def signin(request):
    if request.method == 'POST':
        email = request.POST['email']
        password = request.POST['password']
        user = authenticate(email=email, password=password)

        if (user is not None) and (user.is_active):
            login(request, user)
            facebook_account = FacebookAccount.get_account(
                request_id=request.user.id)
            twitter_account = TwitterAccount.get_account(
                request_id=request.user.id)
            if facebook_account is None and twitter_account is None:
                return redirect('/feed/', {'username': email})
            else:
                return redirect('/feed/', {'username': email})
        else:
            form = EmailAuthenticationForm()
            form.non_field_errors = 'Your email and password were incorrect.'
            return render(request, 'index.html', {'form': form})
    else:
        form = EmailAuthenticationForm()

    return render(request, 'index.html', {'form': form})