コード例 #1
0
        public IHttpActionResult SaveMembers(UIAccounts groupAccounts)
        {
            string        mRetVal       = "false";
            Logger        mLog          = Logger.Instance();
            MSecurityInfo mSecurityInfo = new MSecurityInfo(FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_EditGroups", true)), AccountUtility.CurrentProfile());

            if (!mSecurityInfo.MayEdit)
            {
                Exception mError = new Exception("The account (" + AccountUtility.CurrentProfile().Account + ") being used does not have the correct permissions to add");
                mLog.Error(mError);
                return(this.InternalServerError(mError));
            }
            if (HttpContext.Current.Items["EditId"] == null || HttpContext.Current.Items["EditId"].ToString().ToLowerInvariant() != groupAccounts.SeqId.ToString().ToLowerInvariant())
            {
                Exception mError = new Exception("Identifier you have last looked at does not match the one passed in nothing has been saved!!!!");
                mLog.Error(mError);
                return(this.InternalServerError(mError));
            }
            MAccountProfile     accountProfile      = AccountUtility.CurrentProfile();
            MClientChoicesState mClientChoicesState = ClientChoicesUtility.GetClientChoicesState(accountProfile.Account);
            MGroupRoles         mProfile            = new MGroupRoles();

            mProfile.SecurityEntityId = SecurityEntityUtility.CurrentProfile().Id;
            mProfile.GroupSeqId       = groupAccounts.SeqId;
            mProfile.Roles            = String.Join(",", groupAccounts.Accounts);
            mProfile.AddedUpdatedBy   = accountProfile.Id;
            GroupUtility.UpdateGroupRoles(mProfile);
            return(Ok(mRetVal));
        }
コード例 #2
0
        /// <summary>
        /// AutoCreateAccount will automatically create an account based on infomration found both in the web.config file
        /// and the database.
        /// </summary>
        /// <returns>MAccountProfile</returns>
        public static MAccountProfile AutoCreateAccount()
        {
            MAccountProfile mCurrentAccountProfile = AccountUtility.GetProfile("System");
            MAccountProfile mAccountProfileToSave  = new MAccountProfile();
            Logger          mLog = Logger.Instance();

            mAccountProfileToSave.Id = -1;
            bool   mSaveGroups = true;
            bool   mSaveRoles  = true;
            string mGroups     = ConfigSettings.RegistrationGroups;
            string mRoles      = ConfigSettings.RegistrationRoles;

            if (string.IsNullOrEmpty(mGroups))
            {
                mSaveGroups = false;
            }
            if (string.IsNullOrEmpty(mRoles))
            {
                mSaveRoles = false;
            }
            mAccountProfileToSave.Account       = AccountUtility.HttpContextUserName();
            mAccountProfileToSave.FirstName     = "Auto created";
            mAccountProfileToSave.MiddleName    = "";
            mAccountProfileToSave.LastName      = "Auto created";
            mAccountProfileToSave.PreferredName = "Auto created";
            mAccountProfileToSave.Email         = "*****@*****.**";
            mAccountProfileToSave.Location      = "Hawaii";
            mAccountProfileToSave.TimeZone      = -8;
            mAccountProfileToSave.AddedBy       = mCurrentAccountProfile.Id;
            mAccountProfileToSave.AddedDate     = DateTime.Now;
            mAccountProfileToSave.SetGroups(mGroups);
            mAccountProfileToSave.SetRoles(mRoles);
            mAccountProfileToSave.PasswordLastSet = DateTime.Now;
            mAccountProfileToSave.LastLogOn       = DateTime.Now;
            mAccountProfileToSave.Password        = CryptoUtility.Encrypt(ConfigSettings.RegistrationPassword, ConfigSettings.EncryptionType);
            mAccountProfileToSave.Status          = (int)SystemStatus.SetAccountDetails;
            MClientChoicesState    mClientChoiceState     = ClientChoicesUtility.GetClientChoicesState(ConfigSettings.RegistrationAccountChoicesAccount, true);
            MSecurityEntityProfile mSecurityEntityProfile = SecurityEntityUtility.GetProfile(ConfigSettings.RegistrationSecurityEntityId);

            mClientChoiceState.IsDirty = false;
            mClientChoiceState[MClientChoices.AccountName]        = mAccountProfileToSave.Account;
            mClientChoiceState[MClientChoices.SecurityEntityId]   = mSecurityEntityProfile.Id.ToString(CultureInfo.InvariantCulture);
            mClientChoiceState[MClientChoices.SecurityEntityName] = mSecurityEntityProfile.Name;
            try
            {
                AccountUtility.Save(mAccountProfileToSave, mSaveRoles, mSaveGroups, mSecurityEntityProfile);
                ClientChoicesUtility.Save(mClientChoiceState, false);
                AccountUtility.SetPrincipal(mAccountProfileToSave);
            }
            catch (Exception ex)
            {
                mLog.Error(ex);
                throw;
            }
            return(mAccountProfileToSave);
        }
コード例 #3
0
 /// <summary>
 /// Saves the choices a client may have made during usage of the application.
 /// </summary>
 /// <param name="clientChoicesState">A populated MClientChoicesState object.</param>
 /// <remarks>MClientChoicesState can be found in the GrowthWare.Framework.Model.Profiles namespace.</remarks>
 public void Save(MClientChoicesState clientChoicesState)
 {
     if (clientChoicesState != null)
     {
         Hashtable mChoices = clientChoicesState.ChoicesHashtable;
         m_DClientChoices.Save(mChoices);
     }
     else
     {
         throw new ArgumentNullException("clientChoicesState", "clientChoicesState cannot be a null reference (Nothing in Visual Basic)!");
     }
 }
コード例 #4
0
        /// <summary>
        /// Gets the selected security entity.
        /// </summary>
        /// <returns>System.Int32.</returns>
        public static int SelectedSecurityEntity()
        {
            MClientChoicesState myClientChoicesState = (MClientChoicesState)HttpContext.Current.Items[MClientChoices.SessionName];

            if ((myClientChoicesState != null))
            {
                return(int.Parse(myClientChoicesState[MClientChoices.SecurityEntityId], CultureInfo.InvariantCulture));
            }
            else
            {
                return(ConfigSettings.DefaultSecurityEntityId);
            }
        }
コード例 #5
0
        /// <summary>
        /// Keeps the MClientChoicesState in context.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="eventArgs">EventArgs</param>
        public void AcquireRequestState(object sender, EventArgs eventArgs)
        {
            if (ConfigSettings.DBStatus.ToUpper(CultureInfo.InvariantCulture) != ConfigSettings.DBStatus.ToUpper(CultureInfo.InvariantCulture))
            {
                return;
            }
            //if (HttpContext.Current.Session == null) return;
            String mAccountName = AccountUtility.HttpContextUserName();
            MClientChoicesState mClientChoicesState = null;

            mClientChoicesState = ClientChoicesUtility.GetClientChoicesState(mAccountName);
            // Add ClientChoicesState object to the context items for use
            // throughout the application.
            HttpContext.Current.Items[MClientChoices.SessionName] = mClientChoicesState;
        }
コード例 #6
0
        public MUIAccountChoices GetPreferences()
        {
            MAccountProfile     mAccountProfile     = AccountUtility.CurrentProfile();
            MClientChoicesState mClientChoicesState = null;
            MUIAccountChoices   mRetVal             = null;

            if (mAccountProfile != null)
            {
                mClientChoicesState      = ClientChoicesUtility.GetClientChoicesState(mAccountProfile.Account.ToString(CultureInfo.InvariantCulture));
                mRetVal                  = new MUIAccountChoices(mClientChoicesState);
                mRetVal.Environment      = GWWebHelper.DisplayEnvironment;
                mRetVal.Version          = GWWebHelper.Version;
                mRetVal.FrameWorkVersion = GWWebHelper.FrameworkVersion;
            }
            return(mRetVal);
        }
コード例 #7
0
        /// <summary>
        /// Returns the current MSecurityEntityProfile from context.  If one is not found in context then
        /// the default values from the config file will be returned.
        /// </summary>
        /// <returns>MSecurityEntityProfile</returns>
        public static MSecurityEntityProfile CurrentProfile()
        {
            MSecurityEntityProfile mRetProfile = null;
            String mAccount = AccountUtility.HttpContextUserName();
            MClientChoicesState mClientChoicesState = ClientChoicesUtility.GetClientChoicesState(mAccount);

            if (mClientChoicesState != null)
            {
                int mSecurityEntity = int.Parse(mClientChoicesState[MClientChoices.SecurityEntityId].ToString(), CultureInfo.InvariantCulture);
                mRetProfile = GetProfile(mSecurityEntity);
            }
            if (mRetProfile == null)
            {
                mRetProfile = DefaultProfile();
            }
            return(mRetProfile);
        }
コード例 #8
0
        /// <summary>
        /// Retrieves a data row from the data store and populates a MClientChoicesState object.
        /// </summary>
        /// <param name="account">The desired account in which to base the MClientChoicesState model object</param>
        /// <returns>A populated MClientChoicesState</returns>
        /// <remarks>None.</remarks>
        public MClientChoicesState GetClientChoicesState(string account)
        {
            MClientChoicesState mRetVal = null;

            try
            {
                if (DatabaseIsOnline())
                {
                    mRetVal = new MClientChoicesState(m_DClientChoices.GetChoices(account));
                }
            }
            catch (Exception ex)
            {
                throw new BusinessLogicLayerException("Could not retrieve the client choices state", ex);
            }
            return(mRetVal);
        }
コード例 #9
0
        /// <summary>
        /// Saves changes to MClientChoicesState to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        public void EndRequest(object sender, EventArgs eventArgs)
        {
            if (!processRequest())
            {
                return;
            }
            MClientChoicesState mState = (MClientChoicesState)HttpContext.Current.Items[MClientChoices.SessionName];

            //Save ClientChoicesState back to data store
            if (mState != null)
            {
                if (mState.IsDirty)
                {
                    ClientChoicesUtility.Save(mState);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Save the client choices to the database.
        /// </summary>
        /// <param name="clientChoicesState">MClientChoicesState</param>
        /// <param name="updateContext">bool</param>
        /// <remarks></remarks>
        public static void Save(MClientChoicesState clientChoicesState, bool updateContext)
        {
            if (clientChoicesState == null)
            {
                throw new ArgumentNullException("clientChoicesState", "clientChoicesState cannot be a null reference (Nothing in Visual Basic)! (Nothing in VB)!");
            }
            MSecurityEntityProfile mSecurityEntityProfile = SecurityEntityUtility.DefaultProfile();
            BClientChoices         mBClientChoices        = new BClientChoices(mSecurityEntityProfile, ConfigSettings.CentralManagement);

            mBClientChoices.Save(clientChoicesState);
            if (updateContext)
            {
                if (HttpContext.Current.Cache != null)
                {
                    HttpContext.Current.Cache[MClientChoices.SessionName] = clientChoicesState;
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MUIAccountChoices"/> class.
 /// </summary>
 /// <param name="clientChoicesState">State of the client choices.</param>
 public MUIAccountChoices(MClientChoicesState clientChoicesState)
 {
     if (clientChoicesState[MClientChoices.AccountName] != null)
     {
         AccountName = clientChoicesState[MClientChoices.AccountName].ToString(CultureInfo.InvariantCulture);
     }
     if (clientChoicesState[MClientChoices.Action] != null)
     {
         Action = clientChoicesState[MClientChoices.Action].ToString(CultureInfo.InvariantCulture);
     }
     if (clientChoicesState[MClientChoices.BackColor] != null)
     {
         BackColor = clientChoicesState[MClientChoices.BackColor].ToString(CultureInfo.InvariantCulture);
     }
     if (clientChoicesState[MClientChoices.ColorScheme] != null)
     {
         ColorScheme = clientChoicesState[MClientChoices.ColorScheme].ToString(CultureInfo.InvariantCulture);
     }
     if (clientChoicesState[MClientChoices.HeadColor] != null)
     {
         HeadColor = clientChoicesState[MClientChoices.HeadColor].ToString(CultureInfo.InvariantCulture);
     }
     if (clientChoicesState[MClientChoices.LeftColor] != null)
     {
         LeftColor = clientChoicesState[MClientChoices.LeftColor].ToString(CultureInfo.InvariantCulture);
     }
     if (clientChoicesState[MClientChoices.RecordsPerPage] != null)
     {
         RecordsPerPage = int.Parse(clientChoicesState[MClientChoices.RecordsPerPage].ToString(CultureInfo.InvariantCulture));
     }
     if (clientChoicesState[MClientChoices.SecurityEntityId] != null)
     {
         SecurityEntityID = int.Parse(clientChoicesState[MClientChoices.SecurityEntityId].ToString(CultureInfo.InvariantCulture));
     }
     if (clientChoicesState[MClientChoices.SecurityEntityName] != null)
     {
         SecurityEntityName = clientChoicesState[MClientChoices.SecurityEntityName].ToString(CultureInfo.InvariantCulture);
     }
     if (clientChoicesState[MClientChoices.SubheadColor] != null)
     {
         SubheadColor = clientChoicesState[MClientChoices.SubheadColor].ToString(CultureInfo.InvariantCulture);
     }
 }
コード例 #12
0
        public IHttpActionResult SelectSecurityEntity([FromUri] int selectedSecurityEntityId)
        {
            MSecurityEntityProfile targetSEProfile     = SecurityEntityUtility.GetProfile(selectedSecurityEntityId);
            MSecurityEntityProfile currentSEProfile    = SecurityEntityUtility.CurrentProfile();
            MClientChoicesState    mClientChoicesState = ClientChoicesUtility.GetClientChoicesState(AccountUtility.CurrentProfile().Account);
            MMessageProfile        mMessageProfile     = null;

            try
            {
                if (!ConfigSettings.CentralManagement)
                {
                    mClientChoicesState[MClientChoices.SecurityEntityId]   = targetSEProfile.Id.ToString();
                    mClientChoicesState[MClientChoices.SecurityEntityName] = targetSEProfile.Name;
                }
                else
                {
                    if (currentSEProfile.ConnectionString == targetSEProfile.ConnectionString)
                    {
                        mClientChoicesState[MClientChoices.SecurityEntityId]   = targetSEProfile.Id.ToString();
                        mClientChoicesState[MClientChoices.SecurityEntityName] = targetSEProfile.Name;
                    }
                    else
                    {
                        mClientChoicesState[MClientChoices.SecurityEntityId]   = ConfigSettings.DefaultSecurityEntityId.ToString();
                        mClientChoicesState[MClientChoices.SecurityEntityName] = "System";
                    }
                }
                MMessageProfile myMessageProfile = new MMessageProfile();
                // update all of your in memory information
                AccountUtility.RemoveInMemoryInformation(true);
                ClientChoicesUtility.Save(mClientChoicesState);
                mMessageProfile = MessageUtility.GetProfile("ChangedSelectedSecurityEntity");
            }
            catch (Exception ex)
            {
                Logger mLog = Logger.Instance();
                mMessageProfile = MessageUtility.GetProfile("NoDataFound");
                Exception myEx = new Exception("SelectSecurityEntity:: reported an error.", ex);
                mLog.Error(myEx);
            }
            // refresh the view
            return(Ok(mMessageProfile.Body));
        }
コード例 #13
0
        public string SetSelectedSecurityEntity(int selectedSecurityEntityId)
        {
            MSecurityEntityProfile targetSEProfile     = SecurityEntityUtility.GetProfile(selectedSecurityEntityId);
            MSecurityEntityProfile currentSEProfile    = SecurityEntityUtility.CurrentProfile();
            MClientChoicesState    mClientChoicesState = (MClientChoicesState)HttpContext.Current.Cache[MClientChoices.SessionName];
            MMessageProfile        mMessageProfile     = null;

            try
            {
                if (!ConfigSettings.CentralManagement)
                {
                    //SecurityEntityUtility.SetSessionSecurityEntity(targetSEProfile)
                    mClientChoicesState[MClientChoices.SecurityEntityId]   = targetSEProfile.Id.ToString(CultureInfo.InvariantCulture);
                    mClientChoicesState[MClientChoices.SecurityEntityName] = targetSEProfile.Name;
                }
                else
                {
                    if (currentSEProfile.ConnectionString == targetSEProfile.ConnectionString)
                    {
                        mClientChoicesState[MClientChoices.SecurityEntityId]   = targetSEProfile.Id.ToString(CultureInfo.InvariantCulture);
                        mClientChoicesState[MClientChoices.SecurityEntityName] = targetSEProfile.Name;
                    }
                    else
                    {
                        mClientChoicesState[MClientChoices.SecurityEntityId]   = ConfigSettings.DefaultSecurityEntityId.ToString(CultureInfo.InvariantCulture);
                        mClientChoicesState[MClientChoices.SecurityEntityName] = "System";
                    }
                }
                ClientChoicesUtility.Save(mClientChoicesState);
                AccountUtility.RemoveInMemoryInformation(true);
                mMessageProfile = MessageUtility.GetProfile("ChangedSelectedSecurityEntity");
            }
            catch (Exception ex)
            {
                MMessageProfile myMessageProfile = new MMessageProfile();
                Logger          mLog             = Logger.Instance();
                mMessageProfile = MessageUtility.GetProfile("NoDataFound");
                Exception myEx = new Exception("SelectSecurityEntity:: reported an error.", ex);
                mLog.Error(myEx);
            }
            // update all of your in memory information
            return(mMessageProfile.Body);
        }
コード例 #14
0
        /// <summary>
        /// Gets the state of the client choices.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <param name="fromDB">if set to <c>true</c> [from database].</param>
        /// <returns>MClientChoicesState.</returns>
        public static MClientChoicesState GetClientChoicesState(String account, bool fromDB)
        {
            if (string.IsNullOrEmpty(account))
            {
                throw new ArgumentNullException("account", "account cannot be a null reference (Nothing in VB) or empty!");
            }
            MClientChoicesState    mRetVal = null;
            MSecurityEntityProfile mSecurityEntityProfile = SecurityEntityUtility.DefaultProfile();
            BClientChoices         mBClientChoices        = new BClientChoices(mSecurityEntityProfile, ConfigSettings.CentralManagement);

            if (fromDB)
            {
                return(mBClientChoices.GetClientChoicesState(account));
            }
            if (account.Trim().ToLower(CultureInfo.CurrentCulture) != "anonymous")
            {
                if (HttpContext.Current.Session != null)
                {
                    mRetVal = (MClientChoicesState)HttpContext.Current.Session[MClientChoices.SessionName];
                    if (mRetVal == null)
                    {
                        mRetVal = mBClientChoices.GetClientChoicesState(account);
                        HttpContext.Current.Session[MClientChoices.SessionName] = mRetVal;
                    }
                    else if (mRetVal.AccountName.Trim().ToUpper(CultureInfo.InvariantCulture) != account.Trim().ToUpper(CultureInfo.InvariantCulture))
                    {
                        mRetVal = mBClientChoices.GetClientChoicesState(account);
                        HttpContext.Current.Session[MClientChoices.SessionName] = mRetVal;
                    }
                }
            }
            else
            {
                mRetVal = (MClientChoicesState)HttpContext.Current.Cache[s_CachedAnonymousChoicesState];
                if (mRetVal == null)
                {
                    mRetVal = mBClientChoices.GetClientChoicesState(account);
                    CacheController.AddToCacheDependency(ClientChoicesUtility.s_CachedAnonymousChoicesState, mRetVal);
                }
            }
            return(mRetVal);
        }
コード例 #15
0
        public IHttpActionResult SaveClientChoices(MUIAccountChoices choices)
        {
            if (choices == null)
            {
                throw new ArgumentNullException("choices", "choices cannot be a null reference (Nothing in Visual Basic)!");
            }
            string mRetVal = "false";
            MClientChoicesState mClientChoicesState = ClientChoicesUtility.GetClientChoicesState(AccountUtility.CurrentProfile().Account);

            mClientChoicesState[MClientChoices.Action]                  = choices.Action;
            mClientChoicesState[MClientChoices.BackColor]               = choices.BackColor;
            mClientChoicesState[MClientChoices.ColorScheme]             = choices.ColorScheme;
            mClientChoicesState[MClientChoices.HeadColor]               = choices.HeadColor;
            mClientChoicesState[MClientChoices.HeaderForeColor]         = choices.HeaderForeColor;
            mClientChoicesState[MClientChoices.RowBackColor]            = choices.RowBackColor;
            mClientChoicesState[MClientChoices.AlternatingRowBackColor] = choices.AlternatingRowBackColor;
            mClientChoicesState[MClientChoices.LeftColor]               = choices.LeftColor;
            mClientChoicesState[MClientChoices.RecordsPerPage]          = choices.RecordsPerPage.ToString();
            mClientChoicesState[MClientChoices.SubheadColor]            = choices.SubheadColor;
            ClientChoicesUtility.Save(mClientChoicesState);
            AccountUtility.RemoveInMemoryInformation(true);
            return(Ok(mRetVal));
        }
コード例 #16
0
        public IHttpActionResult SaveMembers(UIAccounts roleAccounts)
        {
            string        mRetVal       = "false";
            Logger        mLog          = Logger.Instance();
            MSecurityInfo mSecurityInfo = new MSecurityInfo(FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_EditRoles", true)), AccountUtility.CurrentProfile());

            if (!mSecurityInfo.MayEdit)
            {
                Exception mError = new Exception("The account (" + AccountUtility.CurrentProfile().Account + ") being used does not have the correct permissions to add");
                mLog.Error(mError);
                return(this.InternalServerError(mError));
            }
            if (HttpContext.Current.Items["EditId"] == null)
            {
                Exception mError = new Exception("Identifier you have last looked at does not match the one passed in nothing has been saved!!!!");
                mLog.Error(mError);
                return(this.InternalServerError(mError));
            }
            MAccountProfile     accountProfile      = AccountUtility.CurrentProfile();
            MClientChoicesState mClientChoicesState = ClientChoicesUtility.GetClientChoicesState(accountProfile.Account);
            bool success = RoleUtility.UpdateAllAccountsForRole(roleAccounts.SeqId, int.Parse(mClientChoicesState[MClientChoices.SecurityEntityId]), roleAccounts.Accounts, accountProfile.Id);

            return(Ok(mRetVal));
        }
コード例 #17
0
 /// <summary>
 /// Save the client choices to the database.
 /// </summary>
 /// <param name="clientChoicesState">MClientChoicesState</param>
 /// <remarks></remarks>
 public static void Save(MClientChoicesState clientChoicesState)
 {
     Save(clientChoicesState, true);
 }
コード例 #18
0
        /// <summary>
        /// Ons the state of the acquire request.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void onAcquireRequestState(object sender, EventArgs e)
        {
            Logger mLog         = Logger.Instance();
            string mAccountName = AccountUtility.HttpContextUserName();

            mLog.Debug("Started");
            mLog.Debug("CurrentExecutionFilePath " + HttpContext.Current.Request.CurrentExecutionFilePath);
            mLog.Debug("HttpContextUserName: "******"ANONYMOUS")
            {
                string mMessage = "Could not find account '" + mAccountName + "'";
                mLog.Info(mMessage);
                if (ConfigSettings.AutoCreateAccount)
                {
                    mMessage = "Creating new account for '" + mAccountName + "'";
                    mLog.Info(mMessage);
                    AccountUtility.AutoCreateAccount();
                }
            }
            if (mAccountName.ToUpper(CultureInfo.InvariantCulture) != "ANONYMOUS" & (mAccountProfile.LastLogOn.ToShortDateString() != DateTime.Now.ToShortDateString()))
            {
                mAccountProfile.LastLogOn = DateTime.Now;
                AccountUtility.Save(mAccountProfile, false, false);
            }
            if (HttpContext.Current.Session == null)
            {
                mLog.Debug("No Session!");
                mLog.Debug("Ended");
                return;
            }
            if (!processRequest())
            {
                mLog.Debug("Request not for processing!");
                mLog.Debug("Ended");
                return;
            }
            if ((HttpContext.Current.Session["EditId"] != null))
            {
                HttpContext.Current.Items["EditId"] = HttpContext.Current.Session["EditId"];
            }
            MClientChoicesState mClientChoicesState = ClientChoicesUtility.GetClientChoicesState(mAccountName);

            HttpContext.Current.Items[MClientChoices.SessionName] = mClientChoicesState;
            string mAction = GWWebHelper.GetQueryValue(HttpContext.Current.Request, "Action");

            if (string.IsNullOrEmpty(mAction))
            {
                mLog.Debug("No Action!");
                mLog.Debug("Ended");
                return;
            }
            MFunctionProfile mFunctionProfile = FunctionUtility.CurrentProfile();

            if (mFunctionProfile == null)
            {
                mFunctionProfile = FunctionUtility.GetProfile(mAction);
            }
            if (!mFunctionProfile.Source.ToUpper(CultureInfo.InvariantCulture).Contains("MENUS") && !(mAction.ToUpper(CultureInfo.InvariantCulture) == "LOGOFF" | mAction.ToUpper(CultureInfo.InvariantCulture) == "LOGON" | mAction.ToUpper(CultureInfo.InvariantCulture) == "CHANGEPASSWORD"))
            {
                FunctionUtility.SetCurrentProfile(mFunctionProfile);
                dynamic mSecurityInfo = new MSecurityInfo(mFunctionProfile, mAccountProfile);
                HttpContext.Current.Items["SecurityInfo"] = mSecurityInfo;
                switch (mAccountProfile.Status)
                {
                case (int)SystemStatus.ChangePassword:
                    mException = new WebSupportException("Your password needs to be changed before any other action can be performed.");
                    GWWebHelper.ExceptionError = mException;
                    mFunctionProfile           = FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_ChangePassword", true));
                    string mChangePasswordPage = GWWebHelper.RootSite + ConfigSettings.AppName + mFunctionProfile.Source;
                    HttpContext.Current.Response.Redirect(mChangePasswordPage + "?Action=" + mFunctionProfile.Action);
                    break;

                case (int)SystemStatus.SetAccountDetails:
                    if (HttpContext.Current.Request.Path.ToUpper(CultureInfo.InvariantCulture).IndexOf("/API/", StringComparison.OrdinalIgnoreCase) == -1)
                    {
                        mFunctionProfile = FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_EditAccount", true));
                        if (mAction.ToUpper(CultureInfo.InvariantCulture) != mFunctionProfile.Action.ToUpper(CultureInfo.InvariantCulture))
                        {
                            mException = new WebSupportException("Your account details need to be set.");
                            GWWebHelper.ExceptionError = mException;
                            string mEditAccountPage = GWWebHelper.RootSite + ConfigSettings.AppName + mFunctionProfile.Source;
                            HttpContext.Current.Response.Redirect(mEditAccountPage + "?Action=" + mFunctionProfile.Action);
                        }
                    }
                    break;

                default:
                    string mPage = string.Empty;
                    if (!mSecurityInfo.MayView)
                    {
                        if (mAccountProfile.Account.ToUpper(CultureInfo.InvariantCulture) == "ANONYMOUS")
                        {
                            mException = new WebSupportException("Your session has timed out.<br/>Please sign in.");
                            GWWebHelper.ExceptionError = mException;
                            mFunctionProfile           = FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_Logon", true));
                            mPage = GWWebHelper.RootSite + ConfigSettings.AppName + mFunctionProfile.Source;
                            HttpContext.Current.Response.Redirect(mPage + "?Action=" + mFunctionProfile.Action);
                        }
                        mFunctionProfile = FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_AccessDenied", true));
                        mLog.Warn("Access was denied to Account: " + mAccountProfile.Account + " for Action: " + mFunctionProfile.Action);
                        mPage = GWWebHelper.RootSite + ConfigSettings.AppName + mFunctionProfile.Source;
                        HttpContext.Current.Response.Redirect(mPage + "?Action=" + mFunctionProfile.Action);
                    }
                    break;
                }
            }
            else
            {
                mLog.Debug("Menu data or Logoff/Logon or ChangePassword requested");
            }
            //processOverridePage(mFunctionProfile);
        }
コード例 #19
0
 /// <summary>
 /// Ons the end request.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
 /// <exception cref="System.Exception"></exception>
 private void onEndRequest(Object sender, EventArgs e)
 {
     if (processRequest())
     {
         MClientChoicesState mState = (MClientChoicesState)HttpContext.Current.Items[MClientChoices.SessionName];
         //Save ClientChoicesState back to data store
         if (mState != null)
         {
             if (mState.IsDirty)
             {
                 ClientChoicesUtility.Save(mState);
             }
         }
         HttpContext mContext   = (sender as HttpApplication).Context;
         bool        mSendError = false;
         try
         {
             if (mContext.Response.Headers["jsonerror"] != null)
             {
                 string mError = string.Empty;
                 if (m_Filter != null)
                 {
                     mError = m_Filter.ReadStream();
                     if (mContext.Response.Headers["jsonerror"].ToString().ToUpperInvariant().Trim() == "TRUE")
                     {
                         mSendError = true;
                         formatError(ref mError);
                         throw (new WebSupportException(String.Concat("An AJAX error has occurred: ", Environment.NewLine, mError)));
                     }
                 }
                 else
                 {
                     if (mContext.Response.Headers["jsonerror"].ToString().ToUpperInvariant().Trim() == "TRUE")
                     {
                         mSendError = true;
                         throw (new WebSupportException(String.Concat("An AJAX error has occurred: ", Environment.NewLine)));
                     }
                 }
             }
         }
         catch (WebSupportException ex)
         {
             if (mSendError)
             {
                 if (!ex.ToString().Contains("Invalid JSON primitive"))
                 {
                     Logger mLog = Logger.Instance();
                     mLog.Error(ex);
                 }
                 if (mContext != null)
                 {
                     HttpResponse mCurrentResponse = mContext.Response;
                     if (mCurrentResponse != null)
                     {
                         mCurrentResponse.Clear();
                         mCurrentResponse.Write("{\"Message\":\"We are very sorry but an error has occurred, please try your request again.\"}");
                         mCurrentResponse.ContentType            = "text/html";
                         mCurrentResponse.StatusDescription      = "500 Internal Error";
                         mCurrentResponse.StatusCode             = 500;
                         mCurrentResponse.TrySkipIisCustomErrors = true;
                         mCurrentResponse.Flush();
                         HttpContext.Current.Server.ClearError();
                         HttpContext.Current.ApplicationInstance.CompleteRequest();
                     }
                 }
             }
         }
         finally
         {
             if (m_Filter != null)
             {
                 m_Filter.Dispose();
                 m_Filter = null;
             }
         }
     }
 }
コード例 #20
0
        public IHttpActionResult Save(UIAccountProfile uiProfile)
        {
            if (uiProfile == null)
            {
                throw new ArgumentNullException("uiProfile", "uiProfile cannot be a null reference (Nothing in Visual Basic)!");
            }
            string          mRetVal                = "false";
            bool            mSaveGroups            = false;
            bool            mSaveRoles             = false;
            MAccountProfile mCurrentAccountProfile = AccountUtility.CurrentProfile();
            MAccountProfile mAccountProfileToSave  = new MAccountProfile();
            Logger          mLog = Logger.Instance();

            if (HttpContext.Current.Request.QueryString["Action"].ToString().ToUpper(CultureInfo.InvariantCulture).IndexOf("REGISTER") > -1)
            {
                MAccountProfile mExistingAccount = AccountUtility.GetProfile(uiProfile.Account);
                if (mExistingAccount == null)
                {
                    mAccountProfileToSave    = populateAccountProfile(uiProfile, mAccountProfileToSave);
                    mAccountProfileToSave.Id = uiProfile.Id;
                    string mGroups = ConfigSettings.RegistrationGroups;
                    string mRoles  = ConfigSettings.RegistrationRoles;
                    if (!string.IsNullOrEmpty(mGroups))
                    {
                        mSaveGroups = true;
                    }
                    if (!string.IsNullOrEmpty(mRoles))
                    {
                        mSaveRoles = true;
                    }
                    mAccountProfileToSave.AddedBy   = mCurrentAccountProfile.Id;
                    mAccountProfileToSave.AddedDate = DateTime.Now;
                    mAccountProfileToSave.SetGroups(mGroups);
                    mAccountProfileToSave.SetRoles(mRoles);
                    mAccountProfileToSave.PasswordLastSet = DateTime.Now;
                    mAccountProfileToSave.LastLogOn       = DateTime.Now;
                    mAccountProfileToSave.Password        = CryptoUtility.Encrypt(ConfigSettings.RegistrationPassword, ConfigSettings.EncryptionType);
                    mAccountProfileToSave.Status          = int.Parse(ConfigSettings.RegistrationStatusId);
                    if (HttpContext.Current.Request.QueryString["Action"].ToString().ToUpper(CultureInfo.InvariantCulture).IndexOf("REGISTER") > -1)
                    {
                        mAccountProfileToSave.Status = (int)SystemStatus.Active;
                    }
                    MClientChoicesState    mClientChoiceState     = ClientChoicesUtility.GetClientChoicesState(ConfigSettings.RegistrationAccountChoicesAccount, true);
                    MSecurityEntityProfile mSecurityEntityProfile = SecurityEntityUtility.GetProfile(ConfigSettings.RegistrationSecurityEntityId);
                    string mCurrentSecurityEntityId = mClientChoiceState[MClientChoices.SecurityEntityId];

                    mClientChoiceState.IsDirty = false;
                    mClientChoiceState[MClientChoices.AccountName]        = mAccountProfileToSave.Account;
                    mClientChoiceState[MClientChoices.SecurityEntityId]   = mSecurityEntityProfile.Id.ToString(CultureInfo.InvariantCulture);
                    mClientChoiceState[MClientChoices.SecurityEntityName] = mSecurityEntityProfile.Name;
                    try
                    {
                        AccountUtility.Save(mAccountProfileToSave, mSaveRoles, mSaveGroups, mSecurityEntityProfile);
                        ClientChoicesUtility.Save(mClientChoiceState, false);
                        AccountUtility.SetPrincipal(mAccountProfileToSave);
                        mRetVal = "Your account has been created";
                    }
                    catch (Exception ex)
                    {
                        mLog.Error(ex);
                    }
                }
                else
                {
                    mRetVal = "The account '" + uiProfile.Account + "' already exists please choose a different account/email";
                }
            }
            else
            {
                if ((HttpContext.Current.Items["EditId"] != null) | mCurrentAccountProfile.Status == (int)SystemStatus.SetAccountDetails)
                {
                    int mEditId = 0;
                    if ((HttpContext.Current.Items["EditId"] != null))
                    {
                        mEditId = int.Parse(HttpContext.Current.Items["EditId"].ToString());
                    }
                    else
                    {
                        mEditId = mCurrentAccountProfile.Id;
                    }
                    if (mEditId == uiProfile.Id)
                    {
                        MSecurityInfo mSecurityInfo = new MSecurityInfo(FunctionUtility.CurrentProfile(), AccountUtility.CurrentProfile());
                        if ((mSecurityInfo != null))
                        {
                            if (mEditId != -1)
                            {
                                if (mCurrentAccountProfile.Id != uiProfile.Id)
                                {
                                    mSecurityInfo = new MSecurityInfo(FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_EditOtherAccount", true)), mCurrentAccountProfile);
                                }
                                if (mSecurityInfo.MayEdit | mCurrentAccountProfile.Status == (int)SystemStatus.SetAccountDetails)
                                {
                                    MSecurityInfo mGroupTabSecurity = new MSecurityInfo(FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_View_Account_Group_Tab", true)), mCurrentAccountProfile);
                                    MSecurityInfo mRoleTabSecurity  = new MSecurityInfo(FunctionUtility.GetProfile(ConfigSettings.GetAppSettingValue("Actions_View_Account_Role_Tab", true)), mCurrentAccountProfile);
                                    mAccountProfileToSave    = AccountUtility.GetProfile(mEditId);
                                    mAccountProfileToSave    = populateAccountProfile(uiProfile, mAccountProfileToSave);
                                    mAccountProfileToSave.Id = uiProfile.Id;
                                    string mGroups = string.Join(",", uiProfile.AccountGroups.Groups);
                                    string mRoles  = string.Join(",", uiProfile.AccountRoles.Roles);
                                    if (mGroupTabSecurity.MayView & FunctionUtility.CurrentProfile().Action.ToLowerInvariant() == ConfigSettings.GetAppSettingValue("Actions_EditOtherAccount", true).ToLower(CultureInfo.InvariantCulture))
                                    {
                                        if (mAccountProfileToSave.GetCommaSeparatedAssignedGroups != mGroups)
                                        {
                                            mSaveGroups = true;
                                            mAccountProfileToSave.SetGroups(mGroups);
                                        }
                                    }
                                    if (mRoleTabSecurity.MayView & FunctionUtility.CurrentProfile().Action.ToLowerInvariant() == ConfigSettings.GetAppSettingValue("Actions_EditOtherAccount", true).ToLower(CultureInfo.InvariantCulture))
                                    {
                                        if (mAccountProfileToSave.GetCommaSeparatedAssignedRoles != mRoles)
                                        {
                                            mSaveRoles = true;
                                            mAccountProfileToSave.SetRoles(mRoles);
                                        }
                                    }
                                    mAccountProfileToSave.AddedBy   = mCurrentAccountProfile.Id;
                                    mAccountProfileToSave.AddedDate = DateTime.Now;
                                    AccountUtility.Save(mAccountProfileToSave, mSaveRoles, mSaveGroups);
                                    mLog.Debug("Saved account " + mAccountProfileToSave.Account + " by " + mCurrentAccountProfile.Account);
                                    mRetVal = "true";
                                }
                                else
                                {
                                    Exception mError = new Exception("The account (" + AccountUtility.CurrentProfile().Account + ") being used does not have the correct permissions to edit");
                                    mLog.Error(mError);
                                    return(this.InternalServerError(mError));
                                }
                            }
                            else
                            {
                                if (mSecurityInfo.MayAdd)
                                {
                                    mSaveGroups                     = true;
                                    mSaveRoles                      = true;
                                    mAccountProfileToSave           = populateAccountProfile(uiProfile, mAccountProfileToSave);
                                    mAccountProfileToSave.Id        = -1;
                                    mAccountProfileToSave.AddedBy   = mCurrentAccountProfile.Id;
                                    mAccountProfileToSave.AddedDate = DateTime.Now;

                                    mAccountProfileToSave.AddedBy         = mCurrentAccountProfile.Id;
                                    mAccountProfileToSave.AddedDate       = DateTime.Now;
                                    mAccountProfileToSave.PasswordLastSet = DateTime.Now;
                                    mAccountProfileToSave.LastLogOn       = DateTime.Now;
                                    mAccountProfileToSave.Password        = CryptoUtility.Encrypt(ConfigSettings.RegistrationPassword, ConfigSettings.EncryptionType);
                                    mAccountProfileToSave.Status          = ConfigSettings.AutoCreateAccountStatusId;
                                    string mGroups = string.Join(",", uiProfile.AccountGroups.Groups);
                                    string mRoles  = string.Join(",", uiProfile.AccountRoles.Roles);
                                    mAccountProfileToSave.SetGroups(mGroups);
                                    mAccountProfileToSave.SetRoles(mRoles);
                                    try
                                    {
                                        AccountUtility.Save(mAccountProfileToSave, mSaveRoles, mSaveGroups);
                                    }
                                    catch (Exception ex)
                                    {
                                        mLog.Error(ex);
                                    }
                                    mLog.Debug("Added account " + mAccountProfileToSave.Account + " by " + mCurrentAccountProfile.Account);
                                    mRetVal = "true";
                                }
                                else
                                {
                                    Exception mError = new Exception("The account (" + AccountUtility.CurrentProfile().Account + ") being used does not have the correct permissions to add");
                                    mLog.Error(mError);
                                    return(this.InternalServerError(mError));
                                }
                            }
                        }
                        else
                        {
                            Exception mError = new Exception("Security Info is not in context nothing has been saved!!!!");
                            mLog.Error(mError);
                            return(this.InternalServerError(mError));
                        }
                    }
                    else
                    {
                        Exception mError = new Exception("Identifier you have last looked at does not match the one passed in nothing has been saved!!!!");
                        mLog.Error(mError);
                        return(this.InternalServerError(mError));
                    }
                }
            }

            return(Ok(mRetVal));
        }