public override void ProcessRequest(HttpContext context)
        {
            long attachmentId = context.Request.QueryString.Get<long>("attachmentId", 0);
            if (attachmentId <= 0)
            {
                WebUtility.Return404(context);
                return;
            }

            string tenantTypeId = context.Request.QueryString.Get<string>("tenantTypeId", null);

            if (string.IsNullOrEmpty(tenantTypeId))
            {
                WebUtility.Return404(context);
                return;
            }
            AttachmentService<Attachment> attachmentService = new AttachmentService<Attachment>(tenantTypeId);
            Attachment attachment = attachmentService.Get(attachmentId);
            if (attachment == null)
            {
                WebUtility.Return404(context);
                return;
            }

            IUser currentUser = UserContext.CurrentUser;

            //判断是否有附件的购买权限或下载权限,有下载权限肯定有购买权限,目前只有未登录或积分不够时才判定为没有权限
            if (!DIContainer.Resolve<Authorizer>().Attachment_Buy(attachment))
            {
                WebUtility.Return403(context);
                return;
            }

            //如果还没有下载权限,则说明积分可以支付附件售价,但是还未购买,则先进行积分交易
            if (!DIContainer.Resolve<Authorizer>().Attachment_Download(attachment))
            {
                //积分交易
                PointService pointService = new PointService();
                pointService.Trade(currentUser.UserId, attachment.UserId, attachment.Price, string.Format("购买附件{0}", attachment.FriendlyFileName), true);
            }

            //创建下载记录
            AttachmentDownloadService attachmentDownloadService = new AttachmentDownloadService();
            attachmentDownloadService.Create(currentUser == null ? 0 : currentUser.UserId, attachment.AttachmentId);

            //下载计数
            CountService countService = new CountService(TenantTypeIds.Instance().Attachment());
            countService.ChangeCount(CountTypes.Instance().DownloadCount(), attachment.AttachmentId, attachment.UserId, 1, false);

            bool enableCaching = context.Request.QueryString.GetBool("enableCaching", true);

            context.Response.Status = "302 Object Moved";
            context.Response.StatusCode = 302;

            LinktimelinessSettings linktimelinessSettings = DIContainer.Resolve<ISettingsManager<LinktimelinessSettings>>().Get();
            string token = Utility.EncryptTokenForAttachmentDownload(linktimelinessSettings.Highlinktimeliness, attachmentId);
            context.Response.Redirect(SiteUrls.Instance().AttachmentTempUrl(attachment.AttachmentId, tenantTypeId, token, enableCaching), true);
            context.Response.Flush();
            context.Response.End();
        }
Beispiel #2
0
        public static bool BarAttachement_Download(this IUser currentUser, Attachment attachment)
        {
            if (DIContainer.Resolve<Authorizer>().Attachment_Edit(attachment))
                return true;

            //处理仅允许注册用户下载
            //if (thread.OnlyAllowRegisteredUserDownload && currentUser == null)
            //    return false;

            //处理售价
            if (attachment.Price <= 0)
                return true;
            AttachmentDownloadService attachementDownloadService = new AttachmentDownloadService();
            if (currentUser != null && attachementDownloadService.IsDownloaded(currentUser.UserId, attachment.AttachmentId))
                return true;
            if (currentUser != null && attachment.Price < currentUser.TradePoints)
                return true;
            return false;
        }
Beispiel #3
0
        /// <summary>
        /// 是否拥有下载的权限
        /// </summary>
        /// <param name="attachment"></param>
        /// <returns></returns>
        public bool Attachment_Download(Attachment attachment)
        {
            //处理仅允许注册用户下载
            //if (thread.OnlyAllowRegisteredUserDownload && currentUser == null)
            //    return false;

            //处理售价
            if (attachment.Price <= 0)
                return true;

            //if (DIContainer.Resolve<Authorizer>().Attachment_Edit(attachment))
            //    return true;
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;
            if (AuthorizationService.IsOwner(currentUser, attachment.UserId))
                return true;

            AttachmentDownloadService attachementDownloadService = new AttachmentDownloadService();
            if (UserContext.CurrentUser != null && attachementDownloadService.IsDownloaded(UserContext.CurrentUser.UserId, attachment.AttachmentId))
                return true;

            return false;
        }