朋友认证为空参数 [英] Friend authentication empty param

查看:297
本文介绍了朋友认证为空参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网络应用程序实现朋友认证,但当我尝试登录我获得这个* /登录?& login_failed = Y& username = * ...我的参数是空的,我不能登录,我做错了?



这些是我的路线...

  (取消路由

(GET/[](index))
(GET/ indexMessage[](indexMessage))
索引)

(POST/ insert-user{params:params}
(let [firstname(get paramsfirstname)
lastname(get paramslastname )
email(get paramsemail)
password(get paramspassword)
sex(get paramssex)
year(get paramsyear)
month(get paramsmonth)
day(get paramsday)]
(def date(str year - month - day))
-user firstname lastname email password sex date)))

(route / resources/ public)
(route / not-foundPage not found)

我使用了所有中间件...

 (def page(handler / site 
(friend / authenticate
routes
{:allow-anon? true
:login-uri/ login
:default-landing-uri/
:unauthorized-handler#( - >(html5 [:h2权限访问(:uri%)])
resp / response
(resp / status 401))
:credential-fn#(creds / bcrypt-credential-fn @users%
:工作流[(workflows / interactive-form)]})
(wrap-keyword-params routes)
(wrap-nested-params routes)

(换行会话路由)


))


$ b b

这是我如何启动我的jetty服务器...

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

像这样...

  {username{:usernameusername:passwordpassword}} 

is:roles a must必须在地图中?也许是因为?

解决方案

我对Friend也很新鲜,但是从Friend的源代码我可以说你的POST请求的参数名称很重要。我想你是遵循这个例子,如果不是,这是你可以得到的最好的提示实际上。请注意表单字段的名称



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



所有凭证函数都有一个参数,一个包含可用凭证的映射,因此
因为没有明确的POST/ login路由,朋友midleware正在捕获并使用它们作为您的凭据的凭据-fn,如此处所示 https://github.com/cemerick/friend/blob/master/src/cemerick/friend/workflows.clj#L76-78



所以username和password应该是posted到:login-uri


$ b $ p的参数名称。可在此处运行 http://friend-demo.herokuapp.com/interactive-form/


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?

解决方案

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/

这篇关于朋友认证为空参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆