Beispiel #1
0
def login_view(request):
    if request.GET.has_key('bounceback'):
        request.session['bounceback'] = request.GET['bounceback']
    
    if request.user.is_authenticated():
        return __bounceback__(request)
    
    api = TroveAPI(TROVE['KEY'], TROVE['SECRET'], TROVE['CONTENT_REQUESTED'])
    request_token = api.get_request_token()
    url = api.get_authorization_url(request_token)
    request.session['request_token'] = request_token
    return HttpResponseRedirect(url)
Beispiel #2
0
def home(request):
    template = 'welcome.html'
    context_vars = {}
    context = None
    if request.user.is_authenticated():
        return get_started_or_go_home(request)
    else:
        api = TroveAPI(settings.TROVE_APP_KEY, settings.TROVE_APP_SECRET, ['photos'])
        if request.GET:
            try:
                oauth_token_key = request.GET['oauth_token']
                request_token = request.session['trove_request_token']
                oauth_token = api.get_access_token(request_token)
                user = authenticate(oauth_token = oauth_token)
                if user is not None:
                    if user.is_active:
                        login(request, user)
                        return get_started_or_go_home(request)
                    else:
                        # Return a 'disabled account' error message
                        pass
                else:
                    # TODO FIXME failed login
                    pass
            except KeyError:
                pass
        else:
            try:
                request_token = request.session['trove_request_token']
            except:
                request_token = api.get_request_token()
                request.session['trove_request_token']=request_token
            url = api.get_authorization_url(request_token)
            context_vars['trove_connect_url']=url
    context = RequestContext(request,context_vars)

    return render_to_response(template,context,mimetype="text/html")
#Some Sample code for how Trove Client APIs work

from troveclient import TroveAPI

# You need a consumer.  Make one in the db. Consumers have call back URLs, which are not overridable (a-la Twitter and Fb)  
c = { 
	key: 'some_key_here',
	secret: 'sssh, it\'s a secret!'
}
# Initialize the TroveAPI with the consumer's key and secret
api = TroveAPI(c.key, c.secret, ['photo'])

rt = api.get_request_token()  
# We get the request token -- returns back an 'OAuthToken'
 
url = api.get_authorization_url(rt)  
print url
raw_input()

# Returns back the URL to redirect the user  (Looks like 'http://brooklyn.vlku.com:8000/multi/login?next=/oauth/authorize/%3Foauth_token%3DdtKaXn5JXRWNndTa')

# callback URL  AUTHORIZES (SAME) token and redirects to a page for you to act on token to get access token
# to promote a request token to an access token call this method

at = api.get_access_token(rt)  
# This returns back the access_token (at) as an OAuthToken.  You want to save this somewhere for reuse later
# access_token also conveniently makes this the access_token for the instantiated API

# so you can call this easily right away with no setup
results = api.get_photos()