def wrapperResponseSupport(self, *args, **kwargs):
   self.REQUEST.response.setHeader('Content-Type', 'application/json')
   request_headers = self.REQUEST.getHeader('Access-Control-Request-Headers')
   if request_headers:
     self.REQUEST.response.setHeader('Access-Control-Allow-Headers',
       request_headers)
   self.REQUEST.response.setHeader('Access-Control-Allow-Origin', '*')
   self.REQUEST.response.setHeader('Access-Control-Allow-Methods', 'DELETE, PUT, POST, '
     'GET, OPTIONS')
   if not anonymous:
     if getSecurityManager().getUser().getId() is None:
       if self.REQUEST.get('USER_CREATION_IN_PROGRESS') is not None:
         # inform that user is not ready yet
         self.REQUEST.response.setStatus(202)
         self.REQUEST.response.setBody(jsonify(
           {'status':'User under creation.'}))
       else:
         # force login
         self.REQUEST.response.setStatus(401)
         self.REQUEST.response.setHeader('WWW-Authenticate', 'Bearer realm="%s"'%
           self.getAPIRoot())
         self.REQUEST.response.setHeader('Location', self.getPortalObject()\
           .portal_preferences.getPreferredRestApiTokenServerUrl())
       return self.REQUEST.response
     else:
       user_name = self.getPortalObject().portal_membership\
         .getAuthenticatedMember()
       user_document = getUserByLogin(self.getPortalObject(),
         str(user_name))
       if len(user_document) != 1:
         transaction.abort()
         LOG('SlapOSRestApiV1', ERROR,
           'Currenty logged in user %r wrong document list %r.'%
             (user_name, user_document))
         self.REQUEST.response.setStatus(500)
         self.REQUEST.response.setBody(jsonify({'error':
           'There is system issue, please try again later.'}))
         return self.REQUEST.response
       self.user_url = user_document[0].getRelativeUrl()
   return fn(self, *args, **kwargs)
Beispiel #2
0
def getUserDocument(self, username):
  portal = self.getPortalObject()
  user_document = getUserByLogin(portal, str(username))
  if len(user_document) != 1:
    return
  return user_document[0]