【发布时间】:2015-12-31 15:13:54
【问题描述】:
我使用addict 和phoenix 进行用户身份验证。我创建了一个登录页面,它以电子邮件和密码作为输入,并使用以下 ajax 调用,使 POST 调用由 addict 提供的 /login API。
$(document).ready(function () {
$('#btn-login').click(function() {
var email = $('#lg_email').val();
var password = $('#lg_password').val();
$.post('/login', {
email: email,
password: password
})
.then(function(data) {
alert(data.responseText.toSource());
})
.fail(function(data) {
alert(data.responseText);
})
});
});
当我从应用程序中点击POST /login 控制器时出现以下错误:
[error] #PID<0.300.0> running MyApp.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /login
** (exit) an exception was raised:
** (ArgumentError) argument error
(stdlib) binary.erl:242: :binary.split/3
lib/comeonin/pbkdf2.ex:66: Comeonin.Pbkdf2.checkpw/2
lib/addict/interactors/addict_manager_interactor.ex:161: Addict.ManagerInteractor.verify_password/4
lib/addict/controller.ex:95: Addict.Controller.login/2
lib/addict/controller.ex:89: Addict.Controller.action/2
lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
(my_app) lib/phoenix/router.ex:255: MyApp.Router.dispatch/2
(my_app) web/router.ex:1: MyApp.Router.do_call/2
(my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
(my_app) lib/plug/debugger.ex:90: MyApp.Endpoint."call (overridable 3)"/2
(my_app) lib/phoenix/endpoint/render_errors.ex:34: MyApp.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
请帮忙。
设置登录路由的参数有:
email: xyz.saurabh@gmail.com
password: asd
我的 mix.lock 文件是:
%{"addict": {:hex, :addict, "0.0.5"},
"comeonin": {:hex, :comeonin, "0.11.3"},
"cowboy": {:hex, :cowboy, "1.0.3"},
"cowlib": {:hex, :cowlib, "1.0.1"},
"decimal": {:hex, :decimal, "1.1.0"},
"ecto": {:hex, :ecto, "1.0.4"},
"fs": {:hex, :fs, "0.9.2"},
"mailgun": {:hex, :mailgun, "0.0.2"},
"phoenix": {:hex, :phoenix, "1.0.3"},
"phoenix_ecto": {:hex, :phoenix_ecto, "1.2.0"},
"phoenix_html": {:hex, :phoenix_html, "2.2.0"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.1"},
"plug": {:hex, :plug, "1.0.2"},
"poison": {:hex, :poison, "1.5.0"},
"poolboy": {:hex, :poolboy, "1.5.1"},
"postgrex": {:hex, :postgrex, "0.9.1"},
"ranch": {:hex, :ranch, "1.1.0"}}
【问题讨论】:
-
您能否显示提交给您的登录路由的参数以及传递给
checkpw的参数。 -
更新了参数,如何从deps代码打印?
-
能否请您也发布您的控制器操作?
-
@Gazler:感谢反馈,已更新。
-
看来问题出在此处:[_, _, rounds, salt, hash] = String.split(hash, "$")(在 Comeonin 源代码中)。由于没有调用 :binary.split/3 ,您可能想检查 Addict 所需的 ComeOnIn 版本。或者将这两个库的版本添加到您的问题中。
标签: authentication elixir phoenix-framework