Пример #1
0
  def get(self):
    """Handle code exchange."""
    code = self.request.get('code')
    if not code:
      # TODO: Display error.
      return None
    oauth_flow = self.create_oauth_flow()

    # Perform the exchange of the code. If there is a failure with exchanging
    # the code, return None.
    try:
      creds = oauth_flow.step2_exchange(code)
    except FlowExchangeError:
      # TODO: Display error.
      return None

    users_service = util.create_service('oauth2', 'v2', creds)
    # TODO: Check for errors.
    user = users_service.userinfo().get().execute()

    userid = user.get('id')

    # Store the credentials in the data store using the userid as the key.
    # TODO: Hash the userid the same way the userToken is.
    StorageByKeyName(Credentials, userid, 'credentials').put(creds)
    logging.info('Successfully stored credentials for user: %s', userid)
    util.store_userid(self, userid)

    self._perform_post_auth_tasks(userid, creds)
    self.redirect('/')
Пример #2
0
	def get(self):
		""" handle code exchange """
		code = self.request.get('code')
		if not code:
			return None
		
		oauth_flow = self.create_oauth_flow()
		
		# perform the exchange of the code. if there is a failure with the exchange, return None
		try:
			creds = oauth_flow.step2_exchange(code)
		except FlowExchangeError:
			return None
			
		users_service = util.create_service('oauth2', 'v2', creds)
		user = users_service.userinfo().get().execute()
		userid = user.get('id')
		
		# store the credentials in the data store using the 'userid' as the key.
		StorageByKeyName(Credentials, userid, 'credentials').put(creds)
		logging.info('Successfully stored credentials for user: %s', userid)
		util.store_userid(self, userid)
		
		self.perform_post_auth_tasks(userid, creds)
		self.redirect('/')
Пример #3
0
    def get(self):
        """Handle code exchange."""
        code = self.request.get('code')
        if not code:
            # TODO: Display error.
            return None
        oauth_flow = self.create_oauth_flow()

        # Perform the exchange of the code. If there is a failure with exchanging
        # the code, return None.
        try:
            creds = oauth_flow.step2_exchange(code)
        except FlowExchangeError:
            # TODO: Display error.
            return None

        users_service = util.create_service('oauth2', 'v2', creds)
        # TODO: Check for errors.
        user = users_service.userinfo().get().execute()

        userid = user.get('id')

        # Store the credentials in the data store using the userid as the key.
        # TODO: Hash the userid the same way the userToken is.
        StorageByKeyName(Credentials, userid, 'credentials').put(creds)
        logging.info('Successfully stored credentials for user: %s', userid)
        util.store_userid(self, userid)

        self._perform_post_auth_tasks(userid, creds)
        self.redirect('http://www.glasseats.com/thank-you/')
Пример #4
0
 def post(self):
     """Delete the user's credentials from the datastore."""
     urlfetch.fetch(OAUTH2_REVOKE_ENDPOINT % self.credentials.refresh_token)
     util.store_userid(self, '')
     credentials_entity = Credentials.get_by_key_name(self.userid)
     if credentials_entity:
         credentials_entity.delete()
     self.redirect('/')
 def post(self):
   """Delete the user's credentials from the datastore."""
   urlfetch.fetch(OAUTH2_REVOKE_ENDPOINT % self.credentials.refresh_token)
   util.store_userid(self, '')
   credentials_entity = Credentials.get_by_key_name(self.userid)
   if credentials_entity:
     credentials_entity.delete()
   self.redirect('/')
Пример #6
0
  def post(self):
    """Delete the user's credentials from the datastore."""
    urlfetch.fetch(OAUTH2_REVOKE_ENDPOINT % self.credentials.refresh_token)
    util.store_userid(self, '')

    #clear datastore object for tasklists
    q = TasklistStore.all()
    q.filter("owner = ",self.userid)

    for p in q.run():
      p.delete()

    credentials_entity = Credentials.get_by_key_name(self.userid)
    if credentials_entity:
      credentials_entity.delete()
      
    self.redirect('/')
Пример #7
0
  def get(self):
    """Handle code exchange."""
    code = self.request.get('code')
    if not code:
      # TODO: Display error.
      return None
    oauth_flow = self.create_oauth_flow()

    # Perform the exchange of the code. If there is a failure with exchanging
    # the code, return None.
    try:
      creds = oauth_flow.step2_exchange(code)
    except FlowExchangeError:
      # TODO: Display error.
      return None

    users_service = util.create_service('oauth2', 'v2', creds)
    # TODO: Check for errors.
    user = users_service.userinfo().get().execute()

    userid = user.get('id')

    # Store the credentials in the data store using the userid as the key.
    # TODO: Hash the userid the same way the userToken is.
    StorageByKeyName(Credentials, userid, 'credentials').put(creds)
    logging.info('Successfully stored credentials for user: %s', userid)
    util.store_userid(self, userid)
    User(
        family_name=user.get('family_name'),
        given_name=user.get('given_name'),
        name=user.get('name'),
        email=user.get('email'),
        userid=userid,
        created_at=datetime.now().date(),
        birthday=user.get('birthday'),
        ).put()

    self._perform_post_auth_tasks(userid, creds)
    self.redirect('/')
Пример #8
0
  def get(self):
    """Handle code exchange."""
    code = self.request.get('code')
    if not code:
      # TODO: Display error.
      return None
    oauth_flow = self.create_oauth_flow()

    # Perform the exchange of the code. If there is a failure with exchanging
    # the code, return None.
    try:
      creds = oauth_flow.step2_exchange(code)
    except FlowExchangeError:
      # TODO: Display error.
      return None

    users_service = util.create_service('oauth2', 'v2', creds)
    # TODO: Check for errors.
    user = users_service.userinfo().get().execute()

    userid = user.get('id')
    name = user.get('name')

    # Store the credentials in the data store using the userid as the key.
    # TODO: Hash the userid the same way the userToken is.

    if StorageByKeyName(Credentials, userid, 'approved').get() is not None: # if there's a user in the DB already, just save new creds
      StorageByKeyName(Credentials, userid, 'credentials').put(creds)
    else: # if it's really a new user, establish the fields:
      StorageByKeyName(Credentials, userid, 'credentials').put(creds)
      StorageByKeyName(Credentials, userid, 'approved').put(False)
      StorageByKeyName(Credentials, userid, 'displayName').put(name)

    logging.info('Successfully stored credentials for user: %s', userid)
    util.store_userid(self, userid)

    self._perform_post_auth_tasks(userid, creds)
    self.redirect('/contributor')