public void Add(string RoleName, string UserName)
        {
            RoleUser ru = new RoleUser();

            ru.Dp          = _LoginObj.Dp;
            ru.ProductName = BaseFramework.ProductName;
            ru.RoleName    = RoleName;
            ru.UserName    = UserName;
            ru.SaveNew();
        }
Esempio n. 2
0
 public DataTable GetListRole(string UserName)
 {
     return(RoleUser.GetListRole(Dp, UserName));
 }
Esempio n. 3
0
 public DataTable GetListUser(string RoleName)
 {
     return(RoleUser.GetListRole(Dp, RoleName));
 }
Esempio n. 4
0
        public bool Login(string CurrentConnection, string RoleName,
                          string UserName, string UserPassword)
        {
            Dp.ValidateTableDef <RoleUser>();
            Dp.ValidateTableDef <Role>();
            Dp.ValidateTableDef <User>();
            Dp.ValidateTableDef <UserVariable>();
            Dp.ValidateTableDef <RoleVariable>();
            Dp.ValidateTableDef <RoleUserVariable>();

            if (RoleUser.CanLogin(Dp, RoleName, UserName, UserPassword))
            {
                if (_CurrentUser.Length > 0 && OnLogout != null)
                {
                    string TmpUser = _CurrentUser;
                    _CurrentUser = string.Empty;
                    try
                    {
                        OnLogout();
                    }
                    catch (Exception ex)
                    {
                        _CurrentUser = TmpUser;
                        throw ex;
                    }
                }
                _CurrentUser       = UserName;
                _CurrentPassword   = UserPassword;
                _IsUserAdmin       = User.IsUserAdmin(Dp, UserName);
                _CurrentConnection = CurrentConnection;

                IList <RoleModule> RAMList;

                if (BaseSecurity.LoginWithRole)
                {
                    RAMList = Dp.ListLoadEntities <RoleModule>(null,
                                                               "RoleName=@0 AND ProductName=@1",
                                                               string.Empty, false, new FieldParam("0", RoleName),
                                                               new FieldParam("1", BaseFramework.ProductName));
                    _CurrentRole = RoleName;
                }
                else
                {
                    RAMList = Dp.ListFastLoadEntitiesUsingSqlSelect <RoleModule>(null,
                                                                                 string.Concat(@"SELECT DISTINCT ModuleName, AllDocumentData, 
                        DataSecurity FROM _System_RoleModule rm 
                        INNER JOIN _System_RoleUser ru ON
                        rm.ProductName=ru.ProductName AND rm.RoleName=ru.RoleName
                        INNER JOIN _System_Role r ON
                        r.ProductName=rm.ProductName AND rm.RoleName=r.RoleName
                        WHERE r.IsActive=@0 AND (UseDateLimit=@1 OR ",
                                                                                               Dp.GetSqlDate(), @" BETWEEN r.StartDate AND r.EndDate) 
                        AND ru.UserName=@2 AND ru.ProductName=@3 AND ",
                                                                                               Dp.GetSqlLen("DataSecurity"), ">0"),
                                                                                 string.Empty, false, new FieldParam("0", true),
                                                                                 new FieldParam("1", false), new FieldParam("2", UserName),
                                                                                 new FieldParam("3", BaseFramework.ProductName));
                    _CurrentRole = "(Peran Aktif)";
                }

                BaseSecurity.ClearModuleAccessList();

                foreach (RoleModule ram in RAMList)
                {
                    ModuleAccess ma = BaseSecurity.GetModuleAccess(ram.ModuleName);
                    if (ma != null)
                    {
                        Dictionary <string, object> TmpVars = new Dictionary <string, object>();
                        BaseUtility.String2Dictionary(ram.DataSecurity, TmpVars);
                        foreach (KeyValuePair <string, object> kvp in TmpVars)
                        {
                            if (kvp.Value.GetType() == typeof(bool))
                            {
                                if ((bool)kvp.Value)
                                {
                                    ma.Variables[kvp.Key] = true;
                                }
                                else if (!ma.Variables.ContainsKey(kvp.Key))
                                {
                                    ma.Variables[kvp.Key] = false;
                                }
                            }
                            else
                            {
                                ma.Variables[kvp.Key] = kvp.Value;
                            }
                        }
                        ma.AllDocumentData = ma.AllDocumentData || ram.AllDocumentData;
                    }
                }
            }
            else if (UserName == "Admin" &&
                     !User.IsUserAdminExist(Dp))
            {
                if (_CurrentUser.Length > 0 && OnLogout != null)
                {
                    string TmpUser = _CurrentUser;
                    _CurrentUser = string.Empty;
                    try
                    {
                        OnLogout();
                    }
                    catch (Exception ex)
                    {
                        _CurrentUser = TmpUser;
                        throw ex;
                    }
                }
                _CurrentRole       = string.Empty;
                _CurrentUser       = UserName;
                _CurrentPassword   = UserPassword;
                _IsUserAdmin       = true;
                _CurrentConnection = CurrentConnection;

                foreach (ModuleAccess ma in BaseSecurity
                         .ModuleAccessList.Values)
                {
                    ma.AllDocumentData = true;
                }
            }
            else
            {
                return(false);
            }

            Dp.ValidateTableDef <RoleModule>();
            Dp.ValidateTableDef <RoleModuleDocument>();

            foreach (BusinessEntity Service in BaseService.ListObjService
                     .Values)
            {
                if (!Service.LoadEntity())
                {
                    Service.SetDefaultValue();
                }
            }

            if (onLogon != null)
            {
                onLogon();
            }
            return(true);
        }