Ejemplo n.º 1
0
        public List<CSystemUser> GetUsers(DataContext Context)
        {
            var Links = cMenu.Metaobjects.Linq.CMetaobjectLink.sGetInternalLinksByClass(this._key, EnMetaobjectClass.ESystemUser, Context);
            foreach (cMenu.Metaobjects.Linq.CMetaobjectLink Link in Links)
            {
                CSystemUser User = new CSystemUser(Link.LinkedObjectKey, Context);
                User.Attributes.Context = Context;
                this._users.Add(User);
            }

            return this._users;
        }
Ejemplo n.º 2
0
        public static int CreateGroupsUsers()
        {
            CSystemUserGroup AdminGroup = new CSystemUserGroup(DatabaseContext)
            {
                FullDescription = "Группа администраторов",
                ShortDescription = "Группа администраторов",
                Name = "Администраторы",
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_KEY,
                ModificatonDate = DateTime.Now,                
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = true
            };
            var R = AdminGroup.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CSystemUserGroup ModeratorsGroup = new CSystemUserGroup(DatabaseContext)
            {
                FullDescription = "Группа модераторов",
                ShortDescription = "Группа модераторов",
                Name = "Модераторы",
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY,
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = true
            };
            R = AdminGroup.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CSystemUserGroup UsersGroup = new CSystemUserGroup(DatabaseContext)
            {
                FullDescription = "Группа пользователей",
                ShortDescription = "Группа пользователей",
                Name = "Пользователи",
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_KEY,
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = true
            };
            R = AdminGroup.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CSystemUser AdminUser = new CSystemUser(DatabaseContext)
            {
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_ADMINISTRATOR_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_ADMINISTRATOR_KEY,
                ShortDescription = "Главный администратор системы",
                Email = "*****@*****.**",
                EnterpriseType = -1,
                FirstName = "Administrator",
                SecondName = "",
                Surname = "",
                Login = "******",
                Name = "Администратор",
                MobilePhone = "89028087122",
                HomePhone = "",
                WorkPhone = "",
                Passhash = CSecurityHelper.sGeneratePasshash("Administrator", "q"),
                ModificatonDate = DateTime.Now,                
                Parent = CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_KEY,                
                Status = EnMetaobjectStatus.EEnabled,               
                System = true                
            };
            R = AdminUser.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            cMenu.Metaobjects.Linq.CMetaobjectLink Link = new Metaobjects.Linq.CMetaobjectLink()
            {
                LinkedObjectKey = AdminUser.Key,
                LinkType = EnMetaobjectLinkType.ESecurity,
                LinkValue = 1,
                SourceObjectKey = AdminGroup.Key
            };
            R = Link.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;
            try
            { DatabaseContext.SubmitChanges(); }
            catch (Exception Exception)
            {
                throw new Exception(Exception.Message);
                return CErrors.ERR_DB_INSERT_OBJECT;
            }            

            return CErrors.ERR_SUC;
        }
Ejemplo n.º 3
0
        protected CFunctionResult _userGetInformation(string UserIdentity, string Passhash, Guid SessionID, Guid ID)
        {
            Dictionary<string, object> InputParameters = new Dictionary<string, object>();
            InputParameters.Add("ID", ID);

            CFunctionResult R = new CFunctionResult()
            {
                FunctionID = "UserGetInformation",
                InputParameters = InputParameters,
                ResultType = Communication.EnFunctionResultType.ESuccess
            };

            CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID);
            if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess)
            {
                UserResult.FunctionID = "UserLogout";
                UserResult.InputParameters = InputParameters;
                return UserResult;
            }

            CSystemUser User = new CSystemUser(ID, CServerEnvironment.DataContext);
            if (User.Key == CDBConst.CONST_OBJECT_EMPTY_KEY|| User.Class != EnMetaobjectClass.ESystemUser)
                R = CServerHelper.sCompileFunctionResult("UserGetInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null);
            else
                R = CServerHelper.sCompileFunctionResult("UserGetInformation", Communication.EnFunctionResultType.ESuccess, InputParameters, "", User);

            return R;
        }        
Ejemplo n.º 4
0
        protected CFunctionResult _userRegister(string Login, string Email, string Phone, string Password)
        {
            var InputParameters = new Dictionary<string, object>();
            InputParameters.Add("Login", Login);
            InputParameters.Add("Email", Email);
            InputParameters.Add("Phone", Phone);
            InputParameters.Add("Password", Password);

            CFunctionResult R = new CFunctionResult()
            {
                FunctionID = "UserRegister",
                InputParameters = InputParameters,
                ResultType = Communication.EnFunctionResultType.ESuccess
            };

            CFunctionResult TempResult = null;

            if (Login.Trim() == "" && Email.Trim() == "" && Phone.Trim() == "")
            {
                R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_USER_INPUT_PARAMS_NULL", CultureInfo.CurrentCulture), null);
                return R;
            }

            if (Login.Trim() != "")
            {
                TempResult = this._userCheckLoginExistence(Login.Trim());
                if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess)
                {
                    R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content);
                    return R;
                }
            }
            if (Email.Trim() != "")
            {
                TempResult = this._userCheckEmailExistence(Email.Trim());
                if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess)
                {
                    R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content);
                    return R;
                }
            }
            if (Phone.Trim() != "")
            {
                TempResult = this._userCheckPhoneExistence(Phone.Trim());
                if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess)
                {
                    R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content);
                    return R;
                }
            }

            CSystemUser User = new CSystemUser(CServerEnvironment.DataContext)
            {
                Email = Email,
                Login = Login,
                MobilePhone = Phone,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY,
                Passhash = CSecurityHelper.sGeneratePasshash(Login.Trim(), Password.Trim()),
                Status = EnMetaobjectStatus.EEnabled,
                System = false,
                SystemType = EnSystemUserType.EUser,
                ID = Guid.NewGuid(),
                Key = CDatabaseSequence.sGetObjectKey(CServerEnvironment.DatabaseProvider)
            };

            var RR = User.ObjectInsert(CServerEnvironment.DataContext);
            if (RR != CErrors.ERR_SUC)
            {
                R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_INSERT_UNABLE", CultureInfo.CurrentCulture), null);
                return R;
            }

            try
            { CServerEnvironment.DataContext.SubmitChanges(); }
            catch (Exception Exception)
            {
                R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, Exception.Message, null);
                return R;
            }

            cMenu.Metaobjects.Linq.CMetaobjectLink L = new cMenu.Metaobjects.Linq.CMetaobjectLink()
            {
                LinkedObjectKey = User.Key,
                LinkType = EnMetaobjectLinkType.ESecurity,
                LinkValue = 1,
                SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_KEY
            };

            RR = L.LinkInsert(CServerEnvironment.DataContext);
            if (RR != CErrors.ERR_SUC)
            {
                /// Empty resource
                R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("", CultureInfo.CurrentCulture), null);
                return R;
            }

            try
            { CServerEnvironment.DataContext.SubmitChanges(); }
            catch (Exception Exception)
            {
                /// Empty resource
                return CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, Exception.Message, null);
            }

            R.Content = User;

            return R;
        }
Ejemplo n.º 5
0
        public static int TestGetMetaobjects()
        {
            CMetaobjectExtented C = new CMetaobjectExtented();

            var Asm = Assembly.LoadWithPartialName("cMenu.Resources");
            var S = Asm.GetManifestResourceStream("cMenu.Resources.LinqMapping.xml");
            TextReader R = new StreamReader(S);
            var XML = R.ReadToEnd();
            XmlMappingSource mapping = XmlMappingSource.FromXml(XML);
            DataContext DB = new DataContext("Data Source=.\\;Initial Catalog=DB_CMENU;User Id=sa;Password=Qwerty1;", mapping);

            CSystemUser User = new CSystemUser(5, DB);

            return -1;
        }