Example #1
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);
        }
Example #2
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);
        }