retrive user rights from sql table
-
I am using the following code to store public variables:
using System;
using System.Collections.Generic;
using System.Text;namespace Takhlees
{
class public_class
{
// login;
private static string user_login;public string login\_user\_login { get { return user\_login; } set { user\_login = value; } } }
}
and I want to create a table called user_rights with user_right_code and user_right_value fields..... The user_right_value field will be a bit with True or False and the user_right_code will have something like:
ADD_OCCUPATION
EDIT_OCCUPATION
DELETE_OCCUPATION
BROWSE _OCCUPATIONS
BROWSE _GENDER
BROWSE_NATIONALITY
BROWSE_USERS
ADD_USER
EDIT_USER
RESET_PASSWORDI want to know how can automatiocally retrive the user_right_code and user_right_value into public variables? do i have to create each and every code in the public_class?!!
-
I am using the following code to store public variables:
using System;
using System.Collections.Generic;
using System.Text;namespace Takhlees
{
class public_class
{
// login;
private static string user_login;public string login\_user\_login { get { return user\_login; } set { user\_login = value; } } }
}
and I want to create a table called user_rights with user_right_code and user_right_value fields..... The user_right_value field will be a bit with True or False and the user_right_code will have something like:
ADD_OCCUPATION
EDIT_OCCUPATION
DELETE_OCCUPATION
BROWSE _OCCUPATIONS
BROWSE _GENDER
BROWSE_NATIONALITY
BROWSE_USERS
ADD_USER
EDIT_USER
RESET_PASSWORDI want to know how can automatiocally retrive the user_right_code and user_right_value into public variables? do i have to create each and every code in the public_class?!!
Yes, in some form or fashion you need to have properties that tell you whether a particular user has a particular right. In this case you are relating a set of rights directly to a user. It is common, and may be beneficial, to use 'roles' where you construct a set of roles and each role has a set of rights associated with it, then a user is assigned a role rather than a set of individual priviledges. For example, a role named 'Admin' which has all the rights and one named 'ReadOnly' that only has the BROWSE rights. Choose whichever method works best for your needs. As far as retrieving the rights, the best OOP way would be to have a User class and some kind of security class that would contain information about the user's rights. The User class would be a composite in that it would contain a copy of the security class. It would seem pretty straight-forward to have the User class create and fill the security object when the User class is filled with the User data (perhaps invoking a query or stored procedure to retrieve the rights data where UserID=X). There are a myriad of ways of accomplishing this, I just gave one example to illustrate one way it could be done.
Hold on a second here... Don't you think you might be putting the horse ahead of the cart?
-
Yes, in some form or fashion you need to have properties that tell you whether a particular user has a particular right. In this case you are relating a set of rights directly to a user. It is common, and may be beneficial, to use 'roles' where you construct a set of roles and each role has a set of rights associated with it, then a user is assigned a role rather than a set of individual priviledges. For example, a role named 'Admin' which has all the rights and one named 'ReadOnly' that only has the BROWSE rights. Choose whichever method works best for your needs. As far as retrieving the rights, the best OOP way would be to have a User class and some kind of security class that would contain information about the user's rights. The User class would be a composite in that it would contain a copy of the security class. It would seem pretty straight-forward to have the User class create and fill the security object when the User class is filled with the User data (perhaps invoking a query or stored procedure to retrieve the rights data where UserID=X). There are a myriad of ways of accomplishing this, I just gave one example to illustrate one way it could be done.
Hold on a second here... Don't you think you might be putting the horse ahead of the cart?
but can you please explain a bit how can i use my properties to store the user rights? now if I have sql reader to read all the rights wheer user_id = 7 for example... I should read two columns, user_right_code and user_right_value?!! sorry but even after 10 cups of coffee I am still confused....!!
-
but can you please explain a bit how can i use my properties to store the user rights? now if I have sql reader to read all the rights wheer user_id = 7 for example... I should read two columns, user_right_code and user_right_value?!! sorry but even after 10 cups of coffee I am still confused....!!
I have a question.. is thete any way to have a variable called user_rights with a property for every right and its value? if that's possible then I can read the rights from the user_rights table and retrieve the following: user_rights[ALLOW_CREATE_CLIENT, True) user_rights[ALLOW_DELETE_CLIENT, False) where ALLOW_CREATE_CLIENT and ALLOW_DELETE_CLIENT are properties of user_rights where True and False are values for every property.