def login(context, request): """ Login Route Login route to authenticate a user against Plone. """ # extract the data __ac_name = request.form.get("__ac_name", None) __ac_password = request.form.get("__ac_password", None) logger.info("*** LOGIN %s ***" % __ac_name) if __ac_name is None: fail(400, "Username is missing") if __ac_password is None: fail(400, "Password is missing") acl_users = ploneapi.portal.get_tool("acl_users") # XXX hard coded acl_users.credentials_cookie_auth.login() # XXX amin user won't be logged in if I use this approach # acl_users.login() # response = request.response # acl_users.updateCredentials(request, response, __ac_name, __ac_password) if ploneapi.user.is_anonymous(): fail(401, "Invalid Credentials") # return the JSON in the same format like the user route return get_user(context, request, username=__ac_name)
def get_search_results(portal_type=None, uid=None, **kw): """Search the catalog and return the results :returns: Catalog search results :rtype: list or Products.ZCatalog.Lazy.LazyMap """ # If we have an UID, return the object immediately if uid is not None: logger.info("UID '%s' found, returning the object immediately" % uid) return u.to_list(get_object_by_uid(uid)) # allow to search search for the Plone Site with portal_type include_portal = False if u.to_string(portal_type) == "Plone Site": include_portal = True # The request may contain a list of portal_types, e.g. # `?portal_type=Document&portal_type=Plone Site` if "Plone Site" in u.to_list(req.get("portal_type")): include_portal = True # Build and execute a catalog query results = search(portal_type=portal_type, uid=uid, **kw) if include_portal: results = list(results) + u.to_list(get_portal()) return results
def logout(context, request): """ Logout Route """ logger.info("*** LOGOUT ***") acl_users = ploneapi.portal.get_tool("acl_users") acl_users.logout(request) return {"url": api.url_for("plone.jsonapi.routes.users"), "success": True}
def auth(context, request): """ Basic Authentication """ if ploneapi.user.is_anonymous(): request.response.setStatus(401) request.response.setHeader('WWW-Authenticate', 'basic realm="JSONAPI AUTH"', 1) logger.info("*** BASIC AUTHENTICATE ***") return {}
def logout(context, request): """ Logout Route """ logger.info("*** LOGOUT ***") acl_users = ploneapi.portal.get_tool("acl_users") acl_users.logout(request) return { "url": url_for("plone.jsonapi.routes.users"), "success": True }
def make_query(self, **kw): """create a query suitable for the catalog """ query = kw.pop("query", {}) query.update(self.get_request_query()) query.update(self.get_custom_query()) query.update(self.get_keyword_query(**kw)) sort_on, sort_order = self.get_sort_spec() if sort_on and "sort_on" not in query: query.update({"sort_on": sort_on}) if sort_order and "sort_order" not in query: query.update({"sort_order": sort_order}) logger.info("make_query:: query={} | catalog={}".format( query, self.catalog)) return query
def search(self, query): """search the catalog """ logger.info("Catalog query={}".format(query)) catalog = self.get_catalog() return catalog(query)