什么是氮验证API的正确用法?
-
21-09-2019 - |
题
只是想确认氮验证和授权 API的使用。 API的说明是:
wf:user() -> User or 'undefined'
Return the user value that was previously set by wf:user(User)
wf:user(User) -> ok
Set the user for the current session.
wf:clear_user() -> ok
Same as wf:user(undefined).
wf:role(Role) -> 'true' or 'false'
Check if the current user has a specified role.
wf:role(Role, IsInRole) -> ok
Set whether the current user is in a specified role.
wf:clear_roles() -> ok
Remove the user from all roles.
要使用这个API我首先验证对我的数据库中的用户的登录,其存储的凭证,则设置WF:用户(用户)的成功认证的用户?然后,我可以做这样的事情检查,如果告诉undefined = wf:user()
如果用户身份验证,以保护有限的页面?同样地,我将设置角色的用户,等等然后我可以对角色进行验证呢?和氮在后台存储的会话信息,我不知?
解决方案
你是正确的。氮会议只是一个Erlang进程存储会话信息。用法就像你描述。您可以查询到查看用户是否已经登录与否,也为用户的角色设置和查询。什么更复杂的,你必须做你自己。
不隶属于 StackOverflow