コード例 #1
0
ファイル: oauth_util.py プロジェクト: CollabQ/CollabQ
def build_auth_url(request, request_token, url, callback=None, parameters=None):
  if not callback:
    callback = util.here(request)
  parameters = parameters and parameters or {}
  parameters.update({'oauth_token': request_token.key,
                     'oauth_callback': callback})
  auth_url = util.qsa(url, parameters)
  return auth_url
コード例 #2
0
def build_auth_url(request,
                   request_token,
                   url,
                   callback=None,
                   parameters=None):
    if not callback:
        callback = util.here(request)
    parameters = parameters and parameters or {}
    parameters.update({
        'oauth_token': request_token.key,
        'oauth_callback': callback
    })
    auth_url = util.qsa(url, parameters)
    return auth_url
コード例 #3
0
ファイル: views.py プロジェクト: webatat/webatat
def join_welcome_contacts(request):

  """
  if we have an access token for this user attempt to fetch the contacts
  else if we have a request token attempt to get an access token
  if we have neither
    if we are trying to authorize, grab a request token and redirect to authorize page
    else
      show the page
  """
  redirect_to = request.REQUEST.get('redirect_to', '/')
  next = '/welcome/done'


  # these are for the find more contacts bits
  start_index = int(request.REQUEST.get('index', 1))
  max = 100
  token = request.REQUEST.get('token')
  contacts_more = int(request.REQUEST.get('contacts_more', 0))
  # this won't be seen unless contacts_more is positive,
  # so no worries about the possible negative value
  contacts_so_far = contacts_more - 1


  try:
    if not settings.GOOGLE_CONTACTS_IMPORT_ENABLED:
      raise exception.FeatureDisabledError('Google Contacts import is currently disabled')
    
    if 'lookup_remote_contacts' in request.POST:
      validate.nonce(request, 'lookup_remote_contacts')

      next_url = util.qsa(util.here(request), 
                          {'redirect_to': redirect_to,
                           'upgrade_auth_token': '',
                           '_nonce': util.create_nonce(request.user, 
                                                       'upgrade_auth_token'),
                           }
                          )
      auth_url = google_contacts.auth_sub_url(next_url)
      return http.HttpResponseRedirect(auth_url)
    elif 'actor_add_contacts' in request.POST:
      validate.nonce(request, 'actor_add_contacts')

  
      targets = request.POST.getlist('targets')
      owner = request.POST.get('owner', '')

      rv = api.actor_add_contacts(request.user, owner, targets)

      next_url = util.qsa(util.here(request),
                          {'redirect_to': redirect_to,
                           'contacts_more': contacts_more,
                           'index': start_index,
                           'token': token,
                           }
                          )

      return util.RedirectFlash(next_url, 'Contacts added.')
  
    elif 'upgrade_auth_token' in request.GET:
      validate.nonce(request, 'upgrade_auth_token')
      
      auth_token = google_contacts.auth_sub_token_from_request(request)
      session_token = google_contacts.upgrade_to_session_token(auth_token)
      
      next_url = util.qsa(util.here(request),
                          {'redirect_to': redirect_to,
                           'fetch_contacts': '',
                           'token': session_token.get_token_string(),
                           '_nonce': util.create_nonce(request.user, 
                                                       'fetch_contacts'),
                           }
                          )
      
      return http.HttpResponseRedirect(next_url)

    elif 'fetch_contacts' in request.REQUEST:
      validate.nonce(request, 'fetch_contacts')
      
      # start_index and max are gathered above
      session_token = google_contacts.auth_sub_token_from_request(request)
      
      # check for the "My Contacts" group, otherwise, fetch it
      my_contacts = memcache.client.get('%s/my_contacts' % token)
      if not my_contacts:
        my_contacts = google_contacts.get_system_group(session_token, 
                                                       'Contacts')
        memcache.client.set('%s/my_contacts' % token, my_contacts)


      rv, more = google_contacts.get_contacts_emails(session_token,
                                                     group=my_contacts,
                                                     index=start_index,
                                                     max=max)

      contacts = []

      for name, email in rv:
        logging.info('looking up "%s" %s', name, email)
        contacts.append(api.actor_lookup_email(request.user, email))

      contacts = [x for x in contacts if x]

      # for the template
      contacts_found = True
      contacts_more = more
      contacts_so_far = contacts_more - 1
      token = session_token.get_token_string()
      contacts_emails = rv

      # if no contacts were found and more are available, try some more
      if not contacts and contacts_more:
        next_url = util.qsa(util.here(request),
                            {'fetch_contacts': '',
                             'contacts_more': contacts_more,
                             'index': contacts_more,
                             'token': token,
                             '_nonce': util.create_nonce(request.user,
                                                         'fetch_contacts'),
                             'redirect_to': redirect_to,
                             }
                            )
        # TODO(termie): this can take a really long time, probably not really
        #               viable until we can do it with javascript
        #return util.MetaRefresh(next_url, message='Still working...', second=1)
        #return http.HttpResponseRedirect(next_url)

  except:
    exception.handle_exception(request)


  # set the progress
  welcome_photo = True
  welcome_mobile = True

  view = request.user
  page = 'contacts'

  area = 'welcome'
  c = template.RequestContext(request, locals())
  
  t = loader.get_template('join/templates/welcome_%s.html' % page)
  return http.HttpResponse(t.render(c))
コード例 #4
0
def join_welcome_contacts(request):
    """
  if we have an access token for this user attempt to fetch the contacts
  else if we have a request token attempt to get an access token
  if we have neither
    if we are trying to authorize, grab a request token and redirect to authorize page
    else
      show the page
  """
    redirect_to = get_clean_redirect(request)
    next = '/welcome/done'

    # these are for the find more contacts bits
    start_index = int(request.REQUEST.get('index', 1))
    max = 100
    token = request.REQUEST.get('token')
    contacts_more = int(request.REQUEST.get('contacts_more', 0))
    # this won't be seen unless contacts_more is positive,
    # so no worries about the possible negative value
    contacts_so_far = contacts_more - 1

    try:
        if not settings.GOOGLE_CONTACTS_IMPORT_ENABLED:
            raise exception.FeatureDisabledError(
                'Google Contacts import is currently disabled')

        if 'lookup_remote_contacts' in request.POST:
            validate.nonce(request, 'lookup_remote_contacts')

            next_url = util.qsa(
                util.here(request), {
                    'redirect_to':
                    redirect_to,
                    'upgrade_auth_token':
                    '',
                    '_nonce':
                    util.create_nonce(request.user, 'upgrade_auth_token'),
                })
            auth_url = google_contacts.auth_sub_url(next_url)
            return http.HttpResponseRedirect(auth_url)
        elif 'actor_add_contacts' in request.POST:
            validate.nonce(request, 'actor_add_contacts')

            targets = request.POST.getlist('targets')
            owner = request.POST.get('owner', '')

            rv = api.actor_add_contacts(request.user, owner, targets)

            next_url = util.qsa(
                util.here(request), {
                    'redirect_to': redirect_to,
                    'contacts_more': contacts_more,
                    'index': start_index,
                    'token': token,
                })

            return util.RedirectFlash(next_url, 'Contacts added.')

        elif 'upgrade_auth_token' in request.GET:
            validate.nonce(request, 'upgrade_auth_token')

            auth_token = google_contacts.auth_sub_token_from_request(request)
            session_token = google_contacts.upgrade_to_session_token(
                auth_token)

            next_url = util.qsa(
                util.here(request), {
                    'redirect_to': redirect_to,
                    'fetch_contacts': '',
                    'token': session_token.get_token_string(),
                    '_nonce': util.create_nonce(request.user,
                                                'fetch_contacts'),
                })

            return http.HttpResponseRedirect(next_url)

        elif 'fetch_contacts' in request.REQUEST:
            validate.nonce(request, 'fetch_contacts')

            # start_index and max are gathered above
            session_token = google_contacts.auth_sub_token_from_request(
                request)

            # check for the "My Contacts" group, otherwise, fetch it
            my_contacts = memcache.client.get('%s/my_contacts' % token)
            if not my_contacts:
                my_contacts = google_contacts.get_system_group(
                    session_token, 'Contacts')
                memcache.client.set('%s/my_contacts' % token, my_contacts)

            rv, more = google_contacts.get_contacts_emails(session_token,
                                                           group=my_contacts,
                                                           index=start_index,
                                                           max=max)

            contacts = []

            for name, email in rv:
                logging.info('looking up "%s" %s', name, email)
                contacts.append(api.actor_lookup_email(request.user, email))

            contacts = [x for x in contacts if x]

            # for the template
            contacts_found = True
            contacts_more = more
            contacts_so_far = contacts_more - 1
            token = session_token.get_token_string()
            contacts_emails = rv

            # if no contacts were found and more are available, try some more
            if not contacts and contacts_more:
                next_url = util.qsa(
                    util.here(request), {
                        'fetch_contacts': '',
                        'contacts_more': contacts_more,
                        'index': contacts_more,
                        'token': token,
                        '_nonce': util.create_nonce(request.user,
                                                    'fetch_contacts'),
                        'redirect_to': redirect_to,
                    })
                # TODO(termie): this can take a really long time, probably not really
                #               viable until we can do it with javascript
                #return util.MetaRefresh(next_url, message='Still working...', second=1)
                #return http.HttpResponseRedirect(next_url)

    except:
        exception.handle_exception(request)

    # set the progress
    welcome_photo = True
    welcome_mobile = True

    view = request.user
    page = 'contacts'

    area = 'welcome'
    c = template.RequestContext(request, locals())

    t = loader.get_template('join/templates/welcome_%s.html' % page)
    return http.HttpResponse(t.render(c))