我在论坛上工作,我想在数据库中保存用户权限。我的想法是这样的:
USER TABLE HAS: (besides name, login etc)
fk_role_id
ROLE TABLE HAS:
role_id
role_name
role_rights
然后我有一个Enum
用户权限和一个用户类:
[Flags] public enum PermissionTypes : int {
None = 0,
Register = 1,
ThreadCreate = 2,
ThreadEdit = 4,
ThreadDelete = 8,
ReplyCreate = 16,
ReplyEdit = 32,
ReplyDelete = 64,
CatCreate = 128,
CatEdit = 256,
CatDelete = 512,
UserCreate = 1024,
UserEdit = 2048,
UserDelete = 4096,
All = Register | ThreadCreate | ThreadEdit | ThreadDelete | ReplyCreate | ReplyEdit | ReplyDelete | CatCreate | CatEdit | CatDelete | UserCreate | UserEdit | UserDelete
}
public class User {
public PermissionTypes Permissions = PermissionTypes.None;
}
现在可以将用户权限保存为 int inrole_rights
吗?然后让他们再次离开?
更新:
只是为了澄清我的问题是什么...... Fx。如果我有一个具有权限的用户:CatCreate 和 UserCreate,那将给我总共:1152... 现在我将如何使用该数字来测试用户拥有哪些权限?现在它是一个小数