Exemple #1
0
    def get_google_contacts_service(self, user):
        if self.contact_service is None:
            storage = Storage(CredentialsModel, 'id', user, 'credential')
            auth_token = OAuth2TokenFromCredentials(storage.get())
            self.contact_service = gdata.contacts.client.ContactsClient()
            auth_token.authorize(self.contact_service)

        return self.contact_service
Exemple #2
0
 def get_google_contacts_service(self, user):
     if self.contact_service is None:
         storage = Storage(CredentialsModel, 'id', user, 'credential')
         auth_token = OAuth2TokenFromCredentials(storage.get())
         self.contact_service = gdata.contacts.client.ContactsClient()
         auth_token.authorize(self.contact_service)
         
     return self.contact_service
Exemple #3
0
def auth_return(request):
    if not xsrfutil.validate_token(settings.SECRET_KEY,
                                   str(request.GET['state']), request.user):

        return HttpResponseBadRequest()

    credential = FLOW.step2_exchange(request.GET)
    storage = Storage(CredentialsModel, 'id', request.user, 'credential')
    storage.put(credential)
    return HttpResponseRedirect("/main")
Exemple #4
0
def auth_return(request):
    if not xsrfutil.validate_token(settings.SECRET_KEY,
                                   str(request.GET['state']),
                                   request.user):

        return  HttpResponseBadRequest()

    credential = FLOW.step2_exchange(request.GET)
    storage = Storage(CredentialsModel, 'id', request.user, 'credential')
    storage.put(credential)
    return HttpResponseRedirect("/main")
Exemple #5
0
 def _get_calendar_service(self, user):
     if self.calendar_service:
         self.calendar_service
     else:
         
         storage = Storage(CredentialsModel, 'id', user, 'credential')
         credentials = storage.get()
     
         http = credentials.authorize(httplib2.Http())
         self.calendar_service = discovery.build('calendar', 'v3', http=http)
         
     return self.calendar_service
Exemple #6
0
def check_google_authenticated(request):
    storage = Storage(CredentialsModel, 'id', request.user, 'credential')
    credentials = storage.get()

    if credentials is None or credentials.invalid is True:
        FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY,
                                                       request.user)
        FLOW.params['access_type'] = 'offline'
        authorize_url = FLOW.step1_get_authorize_url()

        logger.debug(authorize_url)

        return HttpResponseRedirect(authorize_url)

    else:
        return HttpResponseRedirect('/main')
Exemple #7
0
def check_google_authenticated(request):
    storage = Storage(CredentialsModel, 'id', request.user, 'credential')
    credentials = storage.get()

    if credentials is None or credentials.invalid is True:
        FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY,
                                                       request.user)
        FLOW.params['access_type'] = 'offline'
        authorize_url = FLOW.step1_get_authorize_url()

        logger.debug(authorize_url)

        return HttpResponseRedirect(authorize_url)


    else:
        return HttpResponseRedirect('/main')
Exemple #8
0
    def _build_service(self, user=None):
        storage = Storage(CredentialsModel, 'id', user, 'credential')
        cred = storage.get()
        self.service = build('drive', 'v3', credentials=cred)

        return self.service