1
我正在使用Nitrogen/Inets为我的家庭使用建立一个简单的网站。 只要我有一个客户端连接到Web服务器,当前版本就可以按预期工作。如何管理氮/ inets erlang中的几个用户
如果我尝试连接一个新的用户,2个会话似乎共享相同的状态变量:
- 浏览器1:读取索引页面,点击连接,并登录为USER1。
- 浏览器2:读取索引页面,用户是user1 - >不正确 - 去登录并输入为user2。看起来没问题。
- 浏览器1:重新加载首页 - >非常糟糕 - >用户变更为用户2:除了O(
我已经包括显示器,以显示超时计数器 - >值是同步的?两个浏览器
你能告诉我,我必须做的同时管理多个用户我写的代码如下:index.erl的
提取
header() ->
% if the user is not defined, show in the header a button to connect, change the title and display a reduced menu (thanks to common module)
% if the user is defined, show in the header a button to disconnect, change the title and display a complete menu (thanks to common module)
User = wf:user(),
Msg = case User of
undefined ->
"Pas connecté";
User ->
"Welcome " ++ User
end,
case User of
undefined ->
common:header(Msg, #button { id=dcnx, text="Connexion", postback=connexion , class = rightalign});
User ->
common:header(Msg, #button { id=dcnx, text="Deconnexion", postback=deconnexion , class = rightalign})
end.
body() ->
#container_12 { body= #grid_8 { alpha=true, prefix=2, suffix=2, omega=true, body=inner_body(wf:user()) }}.
inner_body(User) ->
Msg = case User of
undefined -> "Pas connecté";
_ -> User ++ " home"
end,
[
#h2{ text= Msg },
#p{}
].
event(deconnexion) ->
% a temporary popup just to display the user name and check the function call
wf:wire(#alert { text="Bye bye " ++ wf:user() }),
wf:clear_session(), % erase the session information
wf:redirect("index"); % redisplay the index page
event(connexion) ->
wf:redirect_to_login("login");
event(E) -> common:event(E).
login.erl的提取物:
body() ->
% the login requires a name and a password,
% checks that {name,password} exists
Body = [
#label { text="Name" },
#textbox { id=nameTextBox, next=passwordTextBox },
#p{},
#label { text="Password" },
#password { id=passwordTextBox, next=continueButton },
#p{},
#button { id=continueButton, text="Continue", postback=continue }
],
wf:wire(continueButton, nameTextBox, #validate { validators=[
#is_required { text="Obligatoire." },
#custom { text="utilisateur invalide.", tag=tag_name, function=fun name_validator/2 }
]}),
wf:wire(continueButton, passwordTextBox, #validate { validators=[
#is_required { text="Obligatoire." },
#custom { text="mot de passe incorrect.", tag=tag_password, function=fun password_validator/2 }
]}),
Body.
event(continue) ->
Name = wf:q(nameTextBox), % retreive the name
wf:user(Name), % define as user
wf:role(admin,is_admin(Name)), % define role
wf:session(logged,true), % define as logged
wf:redirect_from_login("index"); % go back to the calling page or index if not defined
event(_) -> ok.
谢谢你,我正在测试来自同一浏览器的2个选项卡的代码。我在同一台PC上使用了2种不同的浏览器进行了测试,结果很好。顺便说一句,我没想象会有麻烦,因为这是我用成功的方式连接到谷歌时使用不同的标识符... – Pascal
我很高兴听到这就是它。 – chops