登录和用户权限分配的最佳方法 [英] Login and user rights distribution best method

查看:146
本文介绍了登录和用户权限分配的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录窗口和主窗口,基于登录用户的角色,只想在mainwindow中看到特定的控件。这些权利分配数据来自数据库。



我已经完成了这个方法,一旦我根据提到的数据和每个tabitem和tabitem的控件(添加,删除,编辑,打印等选项)登录主窗口中检查数据库数据并使控件可见和折叠,我就完成了这种方法,意味着我硬编码控件名称和检查数据库数据。假设将来我想添加一些tabitem或控件,我需要更改我为这种正确的分发方法编写的代码。因为我在每个tabitem内有5个主要的tabitems我还有8个tabitems和控件。



你能告诉我最好的方法或过程我应该遵循它来实现这个场景而不是硬编码。

解决方案

有很多方法可以解决ieve this - 你已经成为一体的方式 - 除非你可能会定期添加更多控件,你可以坚持使用当前的方法。



另一种选择是用一个值(比如10,20,30等)标记每个控件,并让你的用户角色分配一个安全值(例如10个用于只读,20个用于编辑,30个用于管理等),然后根据用户是否具有等于或大于控件中标记的权限,让代码逐步执行控件,检查标记并显示/隐藏控件(禁用/启用,无论你想做什么)。 BLOCKQUOTE>

I have a login window and mainwindow based on the role of login user want to visible only particular control in mainwindow.These rights distribution data coming from database.

I have done this approach, once i login based on the role mentioned fetching data and for each tabitem and tabitem's controls(options like add, delete,edit,print) in mainwindow checking with the database data and making control visible and collapsed, means am hard coding the control names and checking with database data.Suppose in future i want to added some more tabitem or control to it,i need to change the code i have written for this right distribution method.Because i have 5 main tabitems inside each tabitem i have 8 more tabitems and control in it.

Could you please let me know the best approach or process i should follow it to achieve this scenario instead of hard coding it.

解决方案

There are a number of ways to achieve this - the way you have gone about it being one - unless you are likely to add more controls on a regular basis, you could stick with the current method.

Another option would be to tag each control with a value (say 10, 20, 30 etc), and have your user roles have a security value assigned to them (say 10 for read only, 20 for edit, 30 for admin etc), then simply have your code step through the controls, check the tag and show/hide the control (disable/enable, whatever you want to do) based on whether the user has permissions equal to or greater than the tag in the control.


这篇关于登录和用户权限分配的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆