[erlang-questions] Yaws user login
Torbjorn Tornkvist
tobbe@REDACTED
Thu Jun 7 12:39:35 CEST 2007
Patrick wrote:
> Hi i have a problem that i still can't understand :)
>
> Can someone decipher this for me(LOL) :
>
> Internal error, yaws code crashed
>
> ERROR erlang code crashed:
> File: /var/www/yaws-default/login.yaws:9
> Reason: {{badmatch,false},
> [{m26,kv,2},
> {m26,out,1},
> {yaws_server,deliver_dyn_part,8},
> {yaws_server,aloop,3},
> {yaws_server,acceptor0,2},
> {proc_lib,init_p,5}]}
> Req: {http_request,'GET',{abs_path,"/login.yaws"},{1,1}}
>
>
> The login.yaws code is following:
>
> <html>
> <erl>
>
> -export([out/1]).
>
>
> -record(login,
> {username,
> password}).
>
> formular(A, Feedback) ->
> {ehtml,
> [{form,
> [{enctype, "multipart/form-data"}, {action, "login.yaws"},
> {method, "post"}],
> [{p, [], "Upisi korisnicko ime i sifru."},
> {p, [], {input,[{type,"text"},{name,"username"}],[]}},
> {p, [], {input,[{type,"password"}, {name,"password"}], []}},
> {p, [], {input,[{type,"submit"}, {value, "Log in"}], []}}
> ]}]}.
>
> -include("../usr/lib/yaws/myapp.hrl").
>
> kv(K,L) ->
> {value, {K, V}} = lists:keysearch(K,1,L),
Probably here. The match fails.
Look at the error msg:
> Reason: {{badmatch,false},
> [{m26,kv,2},
--Tobbe
> V.
>
> out(A) ->
> L = yaws_api:parse_post(A),
> User = kv(username, L),
> Pwd = kv(password, L),
> case myapp:auth(User, Pwd) of
> ok ->
> S = #session{username = User,
> password = Pwd,
> udata = []},
>
> Cookie = yaws_api:new_cookie_session(S),
> [{redirect_local, kv(url, L)},
> yaws_api:setcookie("myapp_sid", Cookie)];
>
> Err ->
> {ehtml,
> {html, [],
> {p, [], f("Bad login: ~p",[Err])}}}
> end.
>
>
> </erl>
> </html>
>
> and the myapp.hrl code is:
>
> -record(session, {username,
> password,
> udata = []}).
>
> get_cookie_val(CookieName, Arg) ->
> H = Arg#arg.headers,
> yaws_api:find_cookie_val(CookieName, H#headers.cookie).
>
> check_cookie(A, CookieName) ->
> case get_cookie_val(CookieName, A) of
> [] ->
> {error, "nije ulogiran"};
> Cookie ->
> yaws_api:cookieval_to_opaque(Cookie)
> end.
>
> Where am i going wrong?
>
> Thanks,
> Patrick
More information about the erlang-questions
mailing list