Exemple #1
0
 public void Logout()
 {
     _CurrentConnection = string.Empty;
     _CurrentUser       = string.Empty;
     _CurrentPassword   = string.Empty;
     _CurrentRole       = string.Empty;
     _IsUserAdmin       = false;
     _Admin             = null;
     BaseSecurity.ClearModuleAccessList();
     if (OnLogout != null)
     {
         OnLogout();
     }
 }
Exemple #2
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);
        }