Example #1
0
        public string CreateNonce(BidPart bid, TimeSpan delay)
        {
            var challengeToken = new XElement("n", new XAttribute("c", bid.Id), new XAttribute("v", _clock.UtcNow.ToUniversalTime().Add(delay).ToString(CultureInfo.InvariantCulture))).ToString();
            var data           = Encoding.UTF8.GetBytes(challengeToken);

            return(Convert.ToBase64String(_encryptionService.Encode(data)));
        }
Example #2
0
 private BidEntry CreateBidEntry(BidPart item)
 {
     return(new BidEntry {
         Bid = item.Record,
         BidedOn = _bidService.GetBidedContent(item.BidedOn),
         IsChecked = false,
         IsHeighest = _bidService.IsHeighestBid(item.Record.Id)
     });
 }
Example #3
0
        private string CreateProtectedUrl(string action, BidPart part) {
            var workContext = _workContextAccessor.GetContext();
            if (workContext.HttpContext != null) {
                var url = new UrlHelper(workContext.HttpContext.Request.RequestContext);
                return url.AbsoluteAction(action, "Bid", new {area = "Devq.Bids", nonce = _bidService.CreateNonce(part, TimeSpan.FromDays(7))});
            }

            return null;
        }
Example #4
0
        private string CreateProtectedUrl(string action, BidPart part)
        {
            var workContext = _workContextAccessor.GetContext();

            if (workContext.HttpContext != null)
            {
                var url = new UrlHelper(workContext.HttpContext.Request.RequestContext);
                return(url.AbsoluteAction(action, "Bid", new { area = "Devq.Bids", nonce = _bidService.CreateNonce(part, TimeSpan.FromDays(7)) }));
            }

            return(null);
        }
Example #5
0
        public bool CanCreateBid(BidPart bidPart)
        {
            if (bidPart == null)
            {
                return(false);
            }

            var bidsPart = GetContainer(bidPart);

            if (bidsPart == null)
            {
                return(false);
            }

            var settings = bidsPart.TypePartDefinition.Settings.GetModel <BidsPartSettings>();

            if (!bidsPart.BidsActive)
            {
                return(false);
            }

            if (bidsPart.BidsDisabled)
            {
                return(false);
            }

            if (settings.MustBeAuthenticated && _orchardServices.WorkContext.CurrentUser == null)
            {
                return(false);
            }

            if (bidPart.BidPrice < bidsPart.MinimumBidPrice)
            {
                return(false);
            }

            if (!CanStillBidOn(bidsPart))
            {
                return(false);
            }

            return(true);
        }
Example #6
0
        public void SendNotificationEmail(BidPart bidPart)
        {
            try
            {
                var bidedOn = _orchardServices.ContentManager.Get(bidPart.BidedOn);
                if (bidedOn == null)
                {
                    return;
                }

                var owner = bidedOn.As <CommonPart>().Owner;
                if (owner == null)
                {
                    return;
                }

                var template = _shapeFactory.Create("Template_Bid_Notification", Arguments.From(new
                {
                    ContentItem = bidedOn,
                    BidPart     = bidPart,
                    BidUrl      = CreateUrl(bidedOn),
                }));

                var parameters = new Dictionary <string, object> {
                    { "Subject", T("Bid notification").Text },
                    { "Body", _shapeDisplay.Display(template) },
                    { "Recipients", owner.Email }
                };

                _messageService.Send("Email", parameters);
            }
            catch (Exception e)
            {
                Logger.Error(e, "An unexpected error occured while sending a notification email");
            }
        }
Example #7
0
        public void SendNotificationEmail(BidPart bidPart)
        {
            try
            {
                var bidedOn = _orchardServices.ContentManager.Get(bidPart.BidedOn);
                if (bidedOn == null)
                {
                    return;
                }

                var owner = bidedOn.As<CommonPart>().Owner;
                if (owner == null)
                {
                    return;
                }

                var template = _shapeFactory.Create("Template_Bid_Notification", Arguments.From(new
                {
                    ContentItem = bidedOn,
                    BidPart = bidPart,
                    BidUrl = CreateUrl(bidedOn),
                }));

                var parameters = new Dictionary<string, object> {
                    {"Subject", T("Bid notification").Text},
                    {"Body", _shapeDisplay.Display(template)},
                    {"Recipients", owner.Email}
                };

                _messageService.Send("Email", parameters);
            }
            catch (Exception e)
            {
                Logger.Error(e, "An unexpected error occured while sending a notification email");
            }
        }
Example #8
0
        public bool CanCreateBid(BidPart bidPart) {
            if (bidPart == null) {
                return false;
            }

            var bidsPart = GetContainer(bidPart);
            
            if (bidsPart == null) {
                return false;
            }

            var settings = bidsPart.TypePartDefinition.Settings.GetModel<BidsPartSettings>();
            if (!bidsPart.BidsActive) {
                return false;
            }

            if (bidsPart.BidsDisabled) {
                return false;
            }

            if (settings.MustBeAuthenticated && _orchardServices.WorkContext.CurrentUser == null) {
                return false;
            }

            if (bidPart.BidPrice < bidsPart.MinimumBidPrice) {
                return false;
            }
            
            if (!CanStillBidOn(bidsPart)) {
                return false;
            }

            return true;
        }
Example #9
0
 public decimal GetMinimumBidPrice(BidPart bidPart) {
     var bidsPart = GetContainer(bidPart);
     return bidsPart.MinimumBidPrice;
 }
Example #10
0
 public BidsPart GetContainer(BidPart bidPart) {
     return _orchardServices.ContentManager.Get<BidsPart>(bidPart.BidedOn);
 }
Example #11
0
 public string CreateNonce(BidPart bid, TimeSpan delay) {
     var challengeToken = new XElement("n", new XAttribute("c", bid.Id), new XAttribute("v", _clock.UtcNow.ToUniversalTime().Add(delay).ToString(CultureInfo.InvariantCulture))).ToString();
     var data = Encoding.UTF8.GetBytes(challengeToken);
     return Convert.ToBase64String(_encryptionService.Encode(data));
 }
Example #12
0
        public decimal GetMinimumBidPrice(BidPart bidPart)
        {
            var bidsPart = GetContainer(bidPart);

            return(bidsPart.MinimumBidPrice);
        }
Example #13
0
 public BidsPart GetContainer(BidPart bidPart)
 {
     return(_orchardServices.ContentManager.Get <BidsPart>(bidPart.BidedOn));
 }