示例#1
0
def twitter_request(request):
  one_user = TwitterAccount.get_account(request_id=request.user.id)
  return_dict = {'success': False}
  if one_user is not None:
    request_json = request.POST
    if request_json.get('type') == 'upload':
      message = request_json.get('message')
      if len(message) <= 140:
        twitter_api.twitter_post(
            one_user.access_token,
            one_user.access_secret,
            message
        )
        return_dict['success'] = True
    elif request_json.get('type') == 'feedRequest':
      twitter_post = twitter_api.twitter_home_timeline(
          one_user.access_token,
          one_user.access_secret,
          30
      )
      return_dict['tweets'] = twitter_post
      return_dict['success'] = True
    elif request_json.get('type') == 'retweet':
      postId = request_json.get('postId')
      success = twitter_api.twitter_retweet(
          one_user.access_token,
          one_user.access_secret,
          postId
      )
      return_dict['success'] = success
  return_json = json.dumps(return_dict)
  return HttpResponse(return_json, mimetype="application/json")
示例#2
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})
示例#3
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})
示例#4
0
def twitter_request(request):
    one_user = TwitterAccount.get_account(request_id=request.user.id)
    return_dict = {'success': False}
    if one_user is not None:
        request_json = request.POST
        if request_json.get('type') == 'upload':
            message = request_json.get('message')
            if len(message) <= 140:
                twitter_api.twitter_post(one_user.access_token,
                                         one_user.access_secret, message)
                return_dict['success'] = True
        elif request_json.get('type') == 'feedRequest':
            twitter_post = twitter_api.twitter_home_timeline(
                one_user.access_token, one_user.access_secret, 30)
            return_dict['tweets'] = twitter_post
            return_dict['success'] = True
        elif request_json.get('type') == 'retweet':
            postId = request_json.get('postId')
            success = twitter_api.twitter_retweet(one_user.access_token,
                                                  one_user.access_secret,
                                                  postId)
            return_dict['success'] = success
    return_json = json.dumps(return_dict)
    return HttpResponse(return_json, mimetype="application/json")