2

如何对发送的每个请求执行身份验证过程。我目前面临的问题是我无法访问作为请求参数发送的用户数据。这是我尝试过的

(pre-route[:any "/mainpage/*"] {:keys[data]}
 (when (not(contains? data "userid"))
   //false response
  )
)

和中间件

(defn for-auth [handler]

  (fn [req]
    (if (contains? (:body (:params req)))
      (handler req)
      (handler (assoc req :body {})
    )
   )
)

我也添加了中间件。但它们都不起作用..访问用户参数的任何想法..

谢谢

4

2 回答 2

0

你在使用包装参数吗?

.. (:use [ring.middleware params])

(def app (-> (handler/site main-routes) (wrap-base-url) (wrap-params)))

于 2012-07-09T19:17:15.813 回答
0

好的,这就是我所做的,它解决了我的问题..

(pre-route [:any "/mainroute/*"] {{:keys [jsondata]}:params}
  (let [data (httputil/parse-json-data jsondata)]

  (cond
    (not (true? valid_req)) "false"
    (not (true? version_check)) "false"
    (not (true? user_valid)) "false"
    )
   )
  )

在这里,我已经在中间件中解析了我的 json 数据,并将其添加到带有键名的“params”中:jsondata .. 它工作得很好..

于 2012-07-25T12:27:44.367 回答