在我的新项目中,我想使用webmachine和mochiweb。我想要做的第一件事是认证。webmachine和重定向未经身份验证的用户
我编辑“dispatch.conf”,并提出一些资源,如:
{["auth"], my_res_auth, []}.
{["protected"], my_res_protected, []}.
{['*'], my_res_default, []}.
当有人访问“受保护”的资源,我想他重定向到“权威性”资源,如果他没有登录“ auth“资源包含带有用户名和密码的Web表单,它执行所有认证工作。
我把这样的代码my_res_protected.erl内:
is_authorized(ReqData, State) ->
case my_auth:is_authorized(ReqData) of
true -> {true, ReqData, State};
false ->
% here should be something to redirect user to "auth" resource
% currently i put such thing, which is incorrect:
{true, wrq:do_redirect(true, wrq:set_resp_header("location", "/auth", ReqData)), State}
% dont know what should i put instead of "true"
end.
我GOOGLE的如何做到这一点一些example,但不喜欢,我应该把这个函数中的所有资源,这需要身份验证。
有没有办法做到这一点?
为什么不为你的状态变量使用记录/结构?那么它是: 'case State#state.do_redirect' – seancribbs
我认为这并不是什么大事来改变它的记录,我发现proplist的方式符合我的需要。虽然我在其他webmachine的资源中使用记录。 – danechkin