Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

n2o Erlang framework email authentication

Tags:

erlang

n2o

I'm new to Erlang and N2O but have some experience in python web development. I want to create authentication by email address (email - password) in my application instead of using AVZ. I've created Sign Up page with this code (other code is as n2o_sample). But instead of putting user to kvs I have {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(_) -> [].
like image 837
beatt Avatar asked Jan 11 '23 11:01

beatt


1 Answers

You do everything right.

The question is essentially with KVS configuring. To make KVS properly working you should do several steps:

1. Put the kvs into rebar.config

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

Use frozen tag version, e.g. "1.5.0" is the latest stable.

2. Configure KVS application in sys.config

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

I put in example N2O configuring to see where is should be placed.

3. Just after first launch of "make console" you should initialize the DB in Erlang shell:

1> kvs:join().

This will instantiate MNESIA tables.

4. After that in Erlang shell please do the check of your problem:

2> rr(kvs_user).

First load all records from kvs_user module. Then perform your check:

3> kvs:put(#user{id="[email protected]"}).
like image 126
Namdak Tönpa Avatar answered Feb 09 '23 06:02

Namdak Tönpa