【问题标题】:n2o Erlang framework email authenticationn2o Erlang 框架电子邮件身份验证
【发布时间】:2014-06-21 21:12:37
【问题描述】:

我是 Erlang 和 N2O 的新手,但在 python web 开发方面有一些经验。我想在我的应用程序中通过电子邮件地址(电子邮件 - 密码)而不是使用 AVZ 创建身份验证。我已经使用此代码创建了注册页面(其他代码为 n2o_sample)。但是我没有把用户放到kvs,而是{error, no_container}

-module(signup_page).
-compile(export_all).
-include_lib("n2o/include/wf.hrl").
-include_lib("n2o_sample/include/users.hrl").

 title() -> [ <<"Sign Up Page">> ].
 main() -> #dtl{file = "login", app = n2o_sample,
                bindings = [{title,title()},{body,body()}]}.

 body() ->
   [ #span{id=display}, #br{},
     #span{body="Email: "}, #textbox{id=user}, #br{},
     #span{body="Password: "}, #password{id=pass}, #br{},
     #span{body="Confirm Password"}, #password{id=confirm}, #br{},
     #button{id=signup, body="Sign Up",
             postback=signup,source=[user,pass,confirm]}].

 event(signup) ->
   User = wf:q(user), Password = wf:q(pass), Confirm = wf:q(confirm),
   U = kvs:get(user, User, undefined),
   case U of
     {ok, undefined} ->
       case Password of
            undefined -> wf:update(display, <<"No pass">>);
            Confirm -> Status = kvs:put(#user{id=User}), 
                       % -> {error, no_container}
                       io:format("~w~n", [Status]);
            B -> io:format("~w~n", [B]) end;
      A ->  io:format("~w~n", [A]),
            wf:update(display, <<"Already registered!">>) end;

 event(_) -> [].

【问题讨论】:

  • 这似乎源于同一个 KVS 错误:github.com/synrc/kvs/issues/7 我不认为这是您代码中的错误。
  • 这个bug只针对KAI后端。
  • 你能接受答案吗?

标签: erlang n2o


【解决方案1】:

你做的一切都是对的。

问题本质上与 KVS 配置有关。要使 KVS 正常工作,您应该执行以下几个步骤:

1。将 kvs 放入 rebar.config

    {kvs, ".*", {git, "git://github.com/synrc/kvs", {tag,"1.5.0"}}},

使用冻结的标签版本,例如“1.5.0”是最新的稳定版。

2。在 sys.config 中配置 KVS 应用

    {n2o, [{port,8000},{transition_port, 8000}]},
    {kvs, [{dba,store_mnesia},
           {schema, [kvs_user, kvs_acl, kvs_feed, kvs_subscription ]} ]},

我放了 N2O 配置的例子,看看应该放在哪里。

3。在第一次启动“make console”之后,你应该在 Erlang shell 中初始化数据库:

1> kvs:join().

这将实例化 MNESIA 表。

4。然后在 Erlang shell 中检查您的问题:

2> rr(kvs_user).

首先从 kvs_user 模块加载所有记录。 然后进行检查:

3> kvs:put(#user{id="maxim@synrc.com"}).

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 2012-08-10
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多