Exemplo n.º 1
0
        public static int BindPoliciesToModerators()
        {
            cMenu.Metaobjects.Linq.CMetaobjectLink PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_EDIT_USERS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            var R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_VIEW_USERS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_EDIT_SESSIONS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_VIEW_SESSIONS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_EDIT_OBJECTS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_VIEW_OBJECTS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_VIEW_ORDERS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_EDIT_ORDERS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_VIEW_COMMENTS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            PolicyLink = new cMenu.Metaobjects.Linq.CMetaobjectLink();
            PolicyLink.LinkedObjectKey = CEmbeddedSecurityConsts.CONST_POLICY_EDIT_COMMENTS_KEY;
            PolicyLink.LinkType = EnMetaobjectLinkType.ESecurity;
            PolicyLink.LinkValue = 1;
            PolicyLink.SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY;
            R = PolicyLink.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;
        }
Exemplo n.º 2
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;
        }