Example #1
0
        public async Task <IHttpActionResult> GetOneTimeToken(int orderItemId)
        {
            var access = this.GetManagementAccess();
            var userId = access.UserId;

            if (!access.HasFeature(ApplicationFeature.AuftragsuebersichtAuftraegeKannDownloadGebrauchskopieAusfuehren))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            var orderItem = (await orderManagerClient.FindOrderItems(new[] { orderItemId })).FirstOrDefault();

            if (orderItem == null)
            {
                return(BadRequest("OrderItem does not exist in DB"));
            }

            var doesExistInCacheResponse = (await doesExistInCacheClient.GetResponse <DoesExistInCacheResponse>(new DoesExistInCacheRequest
            {
                Id = orderItemId.ToString(),
                RetentionCategory = CacheRetentionCategory.UsageCopyBenutzungskopie
            })).Message;

            if (!doesExistInCacheResponse.Exists)
            {
                return(StatusCode(HttpStatusCode.Gone));
            }

            var ipAddress = downloadHelper.GetClientIp(Request);
            var expires   = DateTime.Now.AddMinutes(downloadHelper.GetConfigValueTokenValidTime());
            var token     = downloadHelper.CreateDownloadToken();

            downloadTokenDataAccess.CreateToken(token, orderItemId, DownloadTokenType.OrderItem, expires, ipAddress, userId);
            return(Content(HttpStatusCode.OK, token));
        }
Example #2
0
        public IHttpActionResult GetOneTimeToken(int archiveRecordId)
        {
            var access = GetUserAccessFunc(null);
            var userId = access.UserId;
            var user   = userDataAccess.GetUser(userId);

            if (!CheckUserHasDownloadTokensForVe(access, archiveRecordId))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            if (user.DownloadLimitDisabledUntil == null || user.DownloadLimitDisabledUntil < DateTime.Today)
            {
                usageAnalyzer.UpdateUsageStatistic(userId, Request, 1);
                var exceededThreshold = usageAnalyzer.GetExceededThreshold(userId, Request);
                if (exceededThreshold != null)
                {
                    var usageInterval   = usageAnalyzer.GetText(exceededThreshold.Value.UsageInterval, access.Language);
                    var isEndingIn      = usageAnalyzer.GetText(exceededThreshold.Value.IsEndingIn, access.Language);
                    var messageTemplate = translator.GetTranslation(access.Language,
                                                                    "download.thresholdExceeded",
                                                                    "Sie haben in den letzten {0} bereits {1} Dateien heruntergeladen. Die Maximal erlaubte Anzahl von Dateien ist damit erschöpft. Ein weiterer Download wird in {2} wieder möglich sein. Alternativ können Sie beim Applikationseigner ein Gesuch auf Anhebung Ihrer Download-Quota stellen.");

                    return(Content(HttpStatusCode.PreconditionFailed,
                                   string.Format(messageTemplate, usageInterval, exceededThreshold.Value.Usages, isEndingIn)));
                }
            }

            var ipAdress = downloadHelper.GetClientIp(Request);
            var expires  = DateTime.Now.AddMinutes(downloadHelper.GetConfigValueTokenValidTime());
            var token    = downloadHelper.CreateDownloadToken();

            LogTokenGeneration(archiveRecordId, token);

            downloadTokenDataAccess.CreateToken(token, archiveRecordId, DownloadTokenType.ArchiveRecord, expires, ipAdress, userId);
            return(Content(HttpStatusCode.OK, token));
        }