我试图在JSON对象中存储Web请求的规则,并且很难考虑良好的结构。下面是我的一些规则的例子:构建JSON结构以存储Web请求的规则
可能条件下
the user must be logged in
the user must belong to an account of type [____]
the user must belong to an account named [___]
the user must have a username [___]
the user must have the account role [___]
the current time must be between [___] and [___]
the variable [___] must be set to [___]
可能成功操作
allow access to the requested view
redirect to download a specific file
可能的失败操作
redirect to a certain view to display reasons why access was denied
redirect to a purchase page
redirect to a login page with a notice explaining why access was denied
我需要在一个对象中存储多个规则。我还需要能够存储这样的布尔关系:
(rule1 && rule2) || rule3
对象结构通常都得来不易给我,但我挣扎把这个在一起。以下是JSON对象可以存储的要求示例:
用户可以访问控制面板(如果他们已登录并属于名为“所有者”的帐户)。如果用户具有账户角色“员工”,那么他们只能在星期一至星期五登录,而不能在周末登录。如果用户拥有“root”这个名称,他们可以登录而不管其他任何规则。如果没有规则成功,那么将用户重定向到一个页面,告诉他们为什么他们无法进入控制面板。例如,“这是周末,你只能在周一到周五登录。”
你想使用它进行客户端验证吗?或保持服务器端和客户端验证同步?或者只是一种便利的存储格式?你可以例如看看asp.net数据注释和mvc2客户端验证是如何工作的。 – VolkerK 2010-09-08 05:26:13