Esempio n. 1
0
 def init_gclient(self):
     storage = Storage(CredentialsModel, 'id', self._user, 'credential')
     credential = storage.get()
     if credential is None or credential.invalid == True:
         raise InvalidCredentialException()
     else:
         self.client = get_gclient(credential)
Esempio n. 2
0
    def wrapper(request, *args, **kwargs):
        storage = Storage(CredentialsModel, 'id', request.user,
                'credential')
        credential = storage.get()
        if credential is None or credential.access_token_expired:
            flow = OAuth2WebServerFlow(
                client_id=settings.GOOGLE_CONSUMER_KEY,
                client_secret=settings.GOOGLE_CONSUMER_SECRET,
                scope=SCOPES,
                user_agent=USER_AGENT,
                state=request.build_absolute_uri()
                )
            protocol = 'https://' if request.is_secure() else "http://"
            uri = STEP2_URI % request.get_host()
            authorize_url = flow.step1_get_authorize_url(protocol + uri)
            flow_model = FlowModel(id=request.user, flow=flow)
            flow_model.save()
            return HttpResponseRedirect(authorize_url)

        client = get_gclient(credential)
        return func(request, client, *args, **kwargs)