Beispiel #1
0
def json_login(request):
    cl = request.session.get('dropbox_client', False)
    sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
    mime_type = 'application/json'
    print request.session.keys()
    if not cl:
        # user haven't logged in yet
        if request.session.has_key('oauth_token'):
            # user has just allowed dropbox, create a session
            print "oauth token var"
            try:
                print request.session['oauth_token']
                access_token = sess.obtain_access_token(request.session['oauth_token'])
                cl = client.DropboxClient(sess)
            except client.ErrorResponse as e:
                print e
                # delete oauth_token and try again from beginning
                print "oauth token hata"
                del request.session['oauth_token']
                return json_login(request)
            else:
                request.session['dropbox_client'] = cl
                user_info = cl.account_info()
                user_info['gravatar_url'] = create_gravatar_link(user_info['email'])
                request.session['user_info'] = user_info
                return HttpResponse(json.dumps({'response': 'ok'}), mime_type)
                # return HttpResponseRedirect('/app/home')
        else:
            request_token = sess.obtain_request_token()
            url = sess.build_authorize_url(request_token)

            # request.session['oauth_token'] = request_token.to_string()
            request.session['oauth_token'] = request_token
            return HttpResponse(json.dumps({'response': 'fail', 'url': url}), mime_type)
Beispiel #2
0
 def gravatar_link(self):
     return create_gravatar_link(self.email)