示例#1
0
        /// <summary>
        /// Removes users created by anonymous checkout process
        /// </summary>
        private static void MaintainAnonymousCheckouts()
        {
            Store store = Token.Instance.Store;
            StoreSettingCollection settings = store.Settings;

            if (settings.AnonymousUserLifespan > 0)
            {
                DateTime expireDate = DateTime.UtcNow.AddDays(-1 * settings.AnonymousUserLifespan);
                Database database   = Token.Instance.Database;

                //GET ANONYMOUS CHECKOUT USER IDS
                string    sql       = "SELECT UserId FROM ac_Users WHERE StoreId = @storeId AND UserName LIKE 'zz_anonymous_%' AND (LastActivityDate IS NULL OR LastActivityDate < @expireDate)";
                DbCommand dbCommand = database.GetSqlStringCommand(sql);
                database.AddInParameter(dbCommand, "@storeId", System.Data.DbType.Int32, store.StoreId);
                database.AddInParameter(dbCommand, "@expireDate", System.Data.DbType.DateTime, expireDate);
                List <int> idList = GetIdList(dbCommand);

                //DELETE THE USERS WITH GIVEN IDS
                DeleteUsers(idList);

                int expiredCount = idList.Count;

                //LOG RESULTS
                if (expiredCount > 0)
                {
                    Logger.Info("Anonymous checkout maintenance cleared " + expiredCount.ToString() + " expired anonymous users, last active before " + expireDate.ToString());
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initializes the user context for this token.
        /// </summary>
        /// <param name="context">The HttpContext to obtain the user data from</param>
        public void InitUserContext(HttpContext context)
        {
            //INITIALIZE THE TOKEN FOR THIS REQUEST
            if (context != null)
            {
                //GET THE USER CONTEXT
                HttpRequest request = context.Request;
                if (request.IsAuthenticated)
                {
                    //FOR MULTISTORE, IF AUTHENTICATED MAKE SURE THE USER IS VALID FOR THE STORE
                    _User = UserDataSource.LoadForUserName(context.User.Identity.Name);
                    if ((_User == null) || (_User.StoreId != this.StoreId))
                    {
                        //store mismatch, expire the forms ticket
                        User.Logout();
                        //redirect to this page to start over
                        context.Response.Redirect(request.RawUrl, true);
                    }
                }
                else
                {
                    _User = UserDataSource.LoadForUserName(request.AnonymousID, true);
                }

                // UPDATE LAST ACTIVITY DATE
                _User.LastActivityDate = LocaleHelper.LocalNow;

                // CHECK FOR AN AFFILIATE INDICATOR
                Affiliate affiliate = AffiliateDataSource.Load(AlwaysConvert.ToInt(context.Request.QueryString[Store.GetCachedSettings().AffiliateParameterName]));
                if (affiliate != null && affiliate.AffiliateId != _User.AffiliateId)
                {
                    // A VALID AFFILIATE WAS PASSED AND IS NOT THE ONE ASSOCIATED WITH USER
                    // SHOULD WE UPDATE THE USER?
                    StoreSettingCollection settings = Store.GetCachedSettings();
                    if (settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersOverrideAffiliate ||
                        _User.AffiliateId == 0)
                    {
                        // THE RULE IS TO ALWAYS OVERRIDE
                        // OR AN EXISTING USER WITH NO AFFILIATE SET WITH EXISTING USERS NO OVERRIDE OPTION
                        // (IF IT WERE A NEW USER CREATED BY THIS REQUEST, AFFILIATEID WOULD ALREADY BE SET)
                        // AFFILIATE SHOULD BE UPDATED FOR THE TARGET USER
                        _User.AffiliateId           = affiliate.AffiliateId;
                        _User.AffiliateReferralDate = _User.LastActivityDate;
                    }
                }

                this.UserId = _User.UserId;
                if (_User.UserId != 0)
                {
                    _User.Save();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Finds out whether image verification is required for the given user
        /// </summary>
        /// <param name="user">The user to check for</param>
        /// <returns>true if image verification is required, false otherwise</returns>
        public static bool ImageVerificationRequired(User user)
        {
            StoreSettingCollection settings = Token.Instance.Store.Settings;

            switch (settings.ProductReviewImageVerification)
            {
            case UserAuthFilter.None: return(false);

            case UserAuthFilter.Anonymous: return((user == null) || user.IsAnonymous);

            case UserAuthFilter.Registered: return((user == null) || !user.IsAnonymous);

            default: return(true);
            }
        }
示例#4
0
        /// <summary>
        /// Load feed options using the given option keys
        /// </summary>
        /// <param name="settingKeys">Feed Option Setting Keys</param>
        public void Load(IFeedOptionKeys settingKeys)
        {
            StoreSettingCollection settings = Token.Instance.Store.Settings;

            _CompressedFeedFileName = settings.GetValueByKey(settingKeys.CompressedFeedFileName);
            _FeedDataPath           = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\Feeds");
            _FeedFileName           = settings.GetValueByKey(settingKeys.FeedFileName);
            _FtpHost                 = settings.GetValueByKey(settingKeys.FtpHost);
            _FtpPassword             = settings.GetValueByKey(settingKeys.FtpPassword);
            _FtpUser                 = settings.GetValueByKey(settingKeys.FtpUser);
            _IncludeAllProducts      = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.IncludeAllProducts), false);
            _OverwriteCompressedFile = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.OverwriteCompressedFile), true);
            _OverwriteFeedFile       = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.OverwriteFeedFile), true);
            _RemoteFileName          = settings.GetValueByKey(settingKeys.RemoteFileName);
            IsDirty = false;
        }
        public void Load(ISiteMapOptionKeys settingKeys)
        {
            StoreSettingCollection settings = Token.Instance.Store.Settings;

            _CompressedSiteMapFileName = settings.GetValueByKey(settingKeys.CompressedSiteMapFileName);
            _SiteMapDataPath           = settings.GetValueByKey(settingKeys.SiteMapDataPath);
            _SiteMapFileName           = settings.GetValueByKey(settingKeys.SiteMapFileName);
            _IncludeProducts           = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.IncludeProducts), true);
            _IncludeCategories         = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.IncludeCategories), true);
            _IncludeWebpages           = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.IncludeWebpages), true);
            _OverwriteCompressedFile   = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.OverwriteCompressedFile), true);
            _OverwriteSiteMapFile      = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.OverwriteSiteMapFile), true);
            _DefaultChangeFrequency    = (changefreq)AlwaysConvert.ToEnum(typeof(changefreq), settings.GetValueByKey(settingKeys.DefaultChangeFrequency), changefreq.weekly);
            _DefaultUrlPriority        = AlwaysConvert.ToDecimal(settings.GetValueByKey(settingKeys.DefaultUrlPriority), 0.5M);
            IsDirty = false;
        }
示例#6
0
 /// <summary>
 /// Save the feed options using the given feed option keys
 /// </summary>
 /// <param name="settingKeys">Feed Option Setting Keys</param>
 public void Save(IFeedOptionKeys settingKeys)
 {
     if (IsDirty)
     {
         StoreSettingCollection settings = Token.Instance.Store.Settings;
         settings.SetValueByKey(settingKeys.CompressedFeedFileName, CompressedFeedFileName);
         settings.SetValueByKey(settingKeys.FeedFileName, FeedFileName);
         settings.SetValueByKey(settingKeys.FtpHost, FtpHost);
         settings.SetValueByKey(settingKeys.FtpPassword, FtpPassword);
         settings.SetValueByKey(settingKeys.FtpUser, FtpUser);
         settings.SetValueByKey(settingKeys.IncludeAllProducts, IncludeAllProducts.ToString());
         settings.SetValueByKey(settingKeys.OverwriteCompressedFile, OverwriteCompressedFile.ToString());
         settings.SetValueByKey(settingKeys.OverwriteFeedFile, OverwriteFeedFile.ToString());
         settings.SetValueByKey(settingKeys.RemoteFileName, RemoteFileName);
         settings.Save();
     }
 }
 public void Save(ISiteMapOptionKeys settingKeys)
 {
     if (IsDirty)
     {
         StoreSettingCollection settings = Token.Instance.Store.Settings;
         settings.SetValueByKey(settingKeys.CompressedSiteMapFileName, CompressedSiteMapFileName);
         settings.SetValueByKey(settingKeys.SiteMapDataPath, SiteMapDataPath);
         settings.SetValueByKey(settingKeys.SiteMapFileName, SiteMapFileName);
         settings.SetValueByKey(settingKeys.IncludeProducts, IncludeProducts.ToString());
         settings.SetValueByKey(settingKeys.IncludeCategories, IncludeCategories.ToString());
         settings.SetValueByKey(settingKeys.IncludeWebpages, IncludeWebpages.ToString());
         settings.SetValueByKey(settingKeys.OverwriteCompressedFile, OverwriteCompressedFile.ToString());
         settings.SetValueByKey(settingKeys.OverwriteSiteMapFile, OverwriteSiteMapFile.ToString());
         settings.SetValueByKey(settingKeys.DefaultChangeFrequency, DefaultChangeFrequency.ToString());
         settings.SetValueByKey(settingKeys.DefaultUrlPriority, DefaultUrlPriority.ToString());
         settings.Save();
     }
 }
示例#8
0
        /// <summary>
        /// Finds out if email verification is required for given user
        /// </summary>
        /// <param name="profile">The reviewer profile to check for</param>
        /// <param name="user">The user to check for</param>
        /// <returns>true if email verification is required, false otherwise</returns>
        public static bool EmailVerificationRequired(ReviewerProfile profile, User user)
        {
            if (profile.EmailVerified)
            {
                return(false);
            }
            StoreSettingCollection settings = Token.Instance.Store.Settings;

            switch (settings.ProductReviewEmailVerification)
            {
            case UserAuthFilter.None: return(false);

            case UserAuthFilter.Anonymous: return(user.IsAnonymous);

            case UserAuthFilter.Registered: return(!user.IsAnonymous);

            default: return(true);
            }
        }
示例#9
0
        /// <summary>
        /// Saves this payment object to the database
        /// <param name="triggerEvents">If true events are triggered on change of associated order's payment status</param>
        /// </summary>
        /// <returns><b>SaveResult</b> enumeration that represents the result of the save operation.</returns>
        public virtual SaveResult Save(bool triggerEvents)
        {
            //save the payment method name for future reference
            if (string.IsNullOrEmpty(this.PaymentMethodName) && (this.PaymentMethod != null))
            {
                this.PaymentMethodName = this.PaymentMethod.Name;
            }
            //Check whether the payment is in a finalized state
            if (this.PaymentStatus == PaymentStatus.Captured || this.PaymentStatus == PaymentStatus.Completed || this.PaymentStatus == PaymentStatus.Refunded || this.PaymentStatus == PaymentStatus.Void)
            {
                //Payment is finalized.  Start tracking the date of completion if not done already.
                if (this.CompletedDate == DateTime.MinValue)
                {
                    this.CompletedDate = LocaleHelper.LocalNow;
                }
            }
            else
            {
                //this payment is not finalized, make sure a completion date is not set
                this.CompletedDate = DateTime.MinValue;
            }
            //get store settings to process payment
            StoreSettingCollection storeSettings = Store.GetCachedSettings();

            //if the payment has been completed, calculate whether the lifespan is elapsed
            if (this.CompletedDate > DateTime.MinValue)
            {
                //get the payment lifepsan
                Store store = Token.Instance.Store;
                if (LocaleHelper.LocalNow >= this.CompletedDate.Add(new TimeSpan(storeSettings.PaymentLifespan, 0, 0, 0)))
                {
                    //the payment lifespan is elapsed, remove any account data
                    this.AccountData = string.Empty;
                }
            }
            //ENSURE THAT CREDIT CARDS RESPECT CARD STORAGE SETTING
            if ((!string.IsNullOrEmpty(this.EncryptedAccountData)) && (this.PaymentMethod != null) &&
                (this.PaymentMethod.IsCreditOrDebitCard()) && (!storeSettings.EnableCreditCardStorage))
            {
                this.EncryptedAccountData = string.Empty;
            }
            //ENSURE THAT CARD SECURITY CODE IS NEVER STORED
            if (!string.IsNullOrEmpty(this.EncryptedAccountData) && (this.AccountData.ToLowerInvariant().Contains("securitycode")))
            {
                AccountDataDictionary accountData = new AccountDataDictionary(this.AccountData);
                accountData.Remove("SecurityCode");
                this.AccountData = accountData.ToString();
            }
            //ACTIVATE SUBSCRIPTIONS IF THIS PAYMENT IS COMPLETED (ARB PAYMENT)
            if ((this.PaymentStatus == PaymentStatus.Completed) && (this.Subscription != null) && (!this.Subscription.IsActive))
            {
                this.Subscription.Activate();
            }
            //CALL THE BASE SAVE METHOD
            SaveResult result = BaseSave();

            //TRIGGER UPDATE OF ORDER TOTAL PAYMENTS
            this.Order.RecalculatePaymentStatus(triggerEvents);
            //RETURN THE RESULT
            return(result);
        }
示例#10
0
 /// <summary>
 /// Constructor
 /// </summary>
 protected PasswordPolicy()
 {
     StoreSettings = Token.Instance.Store.Settings;
 }
示例#11
0
        /// <summary>
        /// Migrates data such as profile settings and basket contents from one user to another.
        /// </summary>
        /// <param name="oldUser">The user that provides the source data.</param>
        /// <param name="newUser">The user to receive the data.</param>
        /// <param name="includeOrderData">If true, order history and address book are migrated.</param>
        /// <param name="isNewUserAccount">If true, newUser represents an account just created.</param>
        public static void Migrate(User oldUser, User newUser, bool includeOrderData, bool isNewUserAccount)
        {
            //FAIL MIGRATION IF REQUIRED PARAMETERS MISSING
            if (oldUser == null)
            {
                throw new ArgumentNullException("oldUser");
            }
            if (newUser == null)
            {
                throw new ArgumentNullException("newUser");
            }

            //ONLY MIGRATE IF USERID DOES NOT MATCH
            if (oldUser.UserId != newUser.UserId)
            {
                //MIGRATE AFFILIATE SETTINGS
                if (oldUser.Affiliate != null && oldUser.AffiliateId != newUser.AffiliateId)
                {
                    // A VALID AFFILIATE WAS SET ON THE OLD USER AND IS NOT THE ONE ASSOCIATED WITH NEW USER
                    // SHOULD WE UPDATE THE USER?
                    StoreSettingCollection settings = Store.GetCachedSettings();
                    if (isNewUserAccount ||
                        settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersOverrideAffiliate ||
                        (settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersNoOverride && newUser.AffiliateId == 0))
                    {
                        // EITHER A NEW SIGNUP
                        // OR THE RULE IS TO ALWAYS OVERRIDE
                        // OR AN EXISTING USER WITH NO AFFILIATE SET WITH EXISTING USERS NO OVERRIDE OPTION
                        // AFFILIATE SHOULD BE UPDATED FOR THE TARGET USER
                        newUser.AffiliateId           = oldUser.AffiliateId;
                        newUser.AffiliateReferralDate = oldUser.AffiliateReferralDate;
                    }

                    // UPDATE USERS WITH NEW AFFILIATE ASSOCIATIONS
                    newUser.Save();
                    oldUser.AffiliateId           = 0;
                    oldUser.AffiliateReferralDate = DateTime.MinValue;
                    oldUser.Save();
                }

                //TRANSFER BASKET IF NEEDED
                Basket.Transfer(oldUser.UserId, newUser.UserId);
                Wishlist.Transfer(oldUser.UserId, newUser.UserId);

                // TRANSFER PAGE VIEW HISTORY
                PageViewDataSource.UpdateUser(oldUser.UserId, newUser.UserId);

                //SHOULD WE TRANSFER ORDER DATA?
                if (includeOrderData)
                {
                    //REASSIGN ORDERS AND ADDRESSES TO NEW USER
                    OrderDataSource.UpdateUser(oldUser.UserId, newUser.UserId);
                    AddressDataSource.UpdateUser(oldUser.UserId, newUser.UserId);
                }
                else if (oldUser.IsAnonymous)
                {
                    //BUG 7740, ERASE ANY ADDRESS INFO ASSOCIATED WITH ANON ACCOUNT
                    oldUser.Addresses.DeleteAll();
                    oldUser.PrimaryAddressId = 0;
                    oldUser.Save();
                }
            }
        }
示例#12
0
        /// <summary>
        /// Removes inactive users that have passed their lifespan for the current store
        /// </summary>
        private static void MaintainUsers()
        {
            Store    store = Token.Instance.Store;
            DateTime expireDate;
            StoreSettingCollection settings = store.Settings;
            Database   database             = Token.Instance.Database;
            string     sql;
            List <int> idList;

            if (settings.AnonymousUserLifespan > 0)
            {
                expireDate = DateTime.UtcNow.AddDays(-1 * settings.AnonymousUserLifespan);

                //GET USER IDS FOR ANONYMOUS USERS WITHOUT AFFILIATE ASSOCIATION
                sql = "SELECT UserId FROM ac_Users WHERE StoreId = @storeId AND IsAnonymous = 1 AND AffiliateId IS NULL AND (LastActivityDate IS NULL OR LastActivityDate < @expireDate)";
                DbCommand dbCommand = database.GetSqlStringCommand(sql);
                database.AddInParameter(dbCommand, "@storeId", System.Data.DbType.Int32, store.StoreId);
                database.AddInParameter(dbCommand, "@expireDate", System.Data.DbType.DateTime, expireDate);
                idList = GetIdList(dbCommand);

                //DELETE THE USERS FOUND
                DeleteUsers(idList);

                int expiredCount = idList.Count;

                //LOG RESULTS
                if (expiredCount > 0)
                {
                    Logger.Info("User maintenance cleared " + expiredCount.ToString() + " expired anonymous users, last active before " + expireDate.ToString());
                }
            }

            if (settings.AnonymousAffiliateUserLifespan > 0)
            {
                expireDate = DateTime.UtcNow.AddDays(-1 * settings.AnonymousAffiliateUserLifespan);

                //GET USER IDS FOR ANONYMOUS USERS WITH AFFILIATE ASSOCIATION
                sql = "SELECT UserId FROM ac_Users WHERE StoreId = @storeId AND IsAnonymous = 1 AND AffiliateId IS NOT NULL AND (LastActivityDate IS NULL OR LastActivityDate < @expireDate)";
                DbCommand dbCommand = database.GetSqlStringCommand(sql);
                database.AddInParameter(dbCommand, "@storeId", System.Data.DbType.Int32, store.StoreId);
                database.AddInParameter(dbCommand, "@expireDate", System.Data.DbType.DateTime, expireDate);
                idList = GetIdList(dbCommand);

                //DELETE THE USERS FOUND
                DeleteUsers(idList);

                int expiredCount = idList.Count;

                //LOG RESULTS
                if (expiredCount > 0)
                {
                    Logger.Info("User maintenance cleared " + expiredCount.ToString() + " expired affiliate anonymous users, last active before " + expireDate.ToString());
                }
            }

            MerchantPasswordPolicy policy = new MerchantPasswordPolicy();

            if (policy.InactivePeriod > 0)
            {
                //LOOK FOR INACTIVE USERS IN NON-CONSUMER GROUPS (I.E. HAVE ROLES ASSIGNED)
                sql = "SELECT UserId FROM ac_Users WHERE LastActivityDate < @expireDate AND IsApproved = 1 AND UserId IN (SELECT DISTINCT U.UserId FROM (ac_Users U INNER JOIN ac_UserGroups UG ON U.UserId = UG.UserId) INNER JOIN ac_GroupRoles GR ON UG.GroupId = GR.GroupId WHERE U.StoreId = @storeId)";
                DbCommand selCommand = database.GetSqlStringCommand(sql);
                database.AddInParameter(selCommand, "@storeId", System.Data.DbType.Int32, store.StoreId);
                database.AddInParameter(selCommand, "@expireDate", System.Data.DbType.DateTime, DateTime.UtcNow.AddMonths(-1 * policy.InactivePeriod));
                idList = GetIdList(selCommand);

                int       expiredCount = 0;
                DbCommand updCommand;
                foreach (int id in idList)
                {
                    sql        = "UPDATE ac_Users SET IsApproved = 0 WHERE UserId = @userId";
                    updCommand = database.GetSqlStringCommand(sql);
                    database.AddInParameter(updCommand, "@userId", System.Data.DbType.Int32, id);
                    expiredCount += database.ExecuteNonQuery(updCommand);
                }

                if (expiredCount > 0)
                {
                    Logger.Info("User maintenance disabled " + expiredCount.ToString() + " expired merchant accounts.");
                }
            }
        }
示例#13
0
 public Store()
 {
     IsActive  = true;
     IsDeleted = false;
     Settings  = new StoreSettingCollection();
 }