Friend authentication empty param

北城以北 提交于 2019-12-13 03:36:49

问题


I am trying to implement friend authentication on my web app but when i try to login i get this */login?&login_failed=Y&username=*...my param is empty and i cant login,what am i doing wrong?

these are my routes...

(defroutes routes

(GET "/" [] (index))
(GET "/indexMessage" [] (indexMessage))
(GET "/login" req (index))

(POST "/insert-user" {params :params}
   (let [firstname (get params "firstname")
         lastname (get params "lastname")
         email (get params "email")
         password (get params "password")
         sex (get params "sex")
         year (get params "year")
         month (get params "month")
         day (get params "day")]
     (def date (str year"-"month"-"day))
     (insert-user firstname lastname email password sex date)))

(route/resources "/public")
(route/not-found "Page not found")
)

i used all the middleware needed...

(def page (handler/site
        (friend/authenticate
          routes
          {:allow-anon? true
           :login-uri "/login"
           :default-landing-uri "/"
           :unauthorized-handler #(-> (html5 [:h2 "You do not have sufficient privileges to access " (:uri %)])
                                    resp/response
                                    (resp/status 401))
           :credential-fn #(creds/bcrypt-credential-fn @users %)
           :workflows [(workflows/interactive-form)]})
           (wrap-keyword-params routes)
           (wrap-nested-params routes)
           (wrap-params routes)
           (wrap-session routes)


        ))

and this is how i start up my jetty server...

(defn -main []
(run-jetty page {:port 8080 :join? false}))

users is a map like this...

 {"username" {:username "username" :password "password"}}

is :roles a must in the map?maybe it's because of that?


回答1:


I am pretty new to Friend as well but from the Friend source code I can say that the parameters name of your POST request matters. I guess you are following this example, if not, it's the best hint you can get actually. Notice the name of the form fields

https://github.com/cemerick/friend-demo/blob/master/src/clj/cemerick/friend_demo/interactive_form.clj#L22-l24

All credential functions take a single argument, a map containing the available credentials, so as there is no explicit POST "/login" route, the Friend midleware is catching and using them as credentials for your credential-fn as shown here https://github.com/cemerick/friend/blob/master/src/cemerick/friend/workflows.clj#L76-78

So "username" and "password" should be the names of the parameters POSTed to the :login-uri

For newcomers that example is runnable here http://friend-demo.herokuapp.com/interactive-form/



来源:https://stackoverflow.com/questions/21189236/friend-authentication-empty-param

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!