Пример #1
0
        protected override void Check(TransitAccountMessage t_instance, ManagedSecurityContext sec)
        {
            base.Check(t_instance, sec);

            // existing instance doesn't need to be rechecked
            if (t_instance.Id != 0)
            {
                return;
            }

            // verified e-mail required
            sec.CheckVerified();

            // is the sender a friend of the receiver?
            int            sender_id = t_instance.GetOwner(Session, t_instance.SenderAccountId, sec).Id;
            ManagedAccount sender    = new ManagedAccount(Session, sender_id);

            if (sender.HasFriend(t_instance.RecepientAccountId))
            {
                return;
            }

            // how many messages within the last hour?
            new ManagedQuota(DefaultHourlyLimit).Check <AccountMessage, ManagedAccount.QuotaExceededException>(
                GetAcountMessages(Session, sender_id, DateTime.UtcNow.AddHours(-1)));
            // how many messages within the last 24 hours?
            ManagedQuota.GetDefaultEnabledQuota().Check <AccountMessage, ManagedAccount.QuotaExceededException>(
                GetAcountMessages(Session, sender_id, DateTime.UtcNow.AddDays(-1)));

            // check whether the sender was flagged
            new ManagedQuota(ManagedAccountFlag.DefaultAccountFlagThreshold).Check <AccountFlag, ManagedAccountFlag.AccountFlaggedException>(
                ManagedAccountFlag.GetAccountFlagsByFlaggedAccountId(Session, sender_id));
        }
Пример #2
0
        protected virtual ManagedQuota GetQuota(ManagedSecurityContext sec)
        {
            // check whether the default quota was overridden
            IQuery query = Session.CreateQuery(string.Format(
                                                   "FROM AccountQuota AccountQuota WHERE AccountQuota.Account.Id = {0} AND AccountQuota.DataObject.Name = '{1}'",
                                                   sec.Account.Id, typeof(DatabaseType).Name));

            AccountQuota q = query.UniqueResult <AccountQuota>();

            if (q != null)
            {
                return(new ManagedQuota(q.Limit));
            }

            return(ManagedQuota.GetDefaultEnabledQuota());
        }
Пример #3
0
        protected override void Check(TransitDiscussionPost t_instance, ManagedSecurityContext sec)
        {
            base.Check(t_instance, sec);

            if (t_instance.Id != 0)
            {
                return;
            }

            sec.CheckVerified();

            int account_id = t_instance.GetOwner(Session, t_instance.AccountId, sec).Id;

            // how many posts within the last hour?
            new ManagedQuota(DefaultHourlyLimit).Check <DiscussionPost, ManagedAccount.QuotaExceededException>(
                GetDiscussionPosts(Session, account_id, DateTime.UtcNow.AddHours(-1)));
            // how many messages within the last 24 hours?
            ManagedQuota.GetDefaultEnabledQuota().Check <DiscussionPost, ManagedAccount.QuotaExceededException>(
                GetDiscussionPosts(Session, account_id, DateTime.UtcNow.AddDays(-1)));

            // check whether the sender was flagged
            new ManagedQuota(ManagedAccountFlag.DefaultAccountFlagThreshold).Check <AccountFlag, ManagedAccountFlag.AccountFlaggedException>(
                ManagedAccountFlag.GetAccountFlagsByFlaggedAccountId(Session, sec.Account.Id));
        }