Example #1
0
        public void Write()
        {
            var resource = _request.Get <T>();

            if (resource == null)
            {
                _writer.WriteResponseCode(HttpStatusCode.NotFound);
                _notFoundHandler.HandleResourceNotFound <T>();

                return;
            }

            var mimeTypes = _request.Get <CurrentMimeType>();
            var media     = SelectMedia(mimeTypes);

            if (media == null)
            {
                // TODO -- better error message?
                _writer.WriteResponseCode(HttpStatusCode.NotAcceptable);
                _writer.Write(MimeType.Text, "406:  Not acceptable");
            }
            else
            {
                var outputMimetype = mimeTypes.SelectFirstMatching(media.Mimetypes);
                media.Write(outputMimetype, resource);
            }

            WriteHeaders();
        }
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var customerId = request.Get <Customer>().Id;
            var productId  = request.Get <Product>().Id;

            var hasPurchasedProduct = _repository.Get <IPurchaseHistory>(customerId)
                                      .Any(x => x.ContainsProduct(productId));

            return(!hasPurchasedProduct ? AuthorizationRight.Deny : AuthorizationRight.Allow);
        }
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var customerId = request.Get<Customer>().Id;
            var productId = request.Get<Product>().Id;

            var hasPurchasedProduct = _repository.Get<IPurchaseHistory>(customerId)
                .Any(x => x.ContainsProduct(productId));

            return !hasPurchasedProduct ? AuthorizationRight.Deny : AuthorizationRight.Allow;
        }
Example #4
0
        public async Task <string> Invoke <T>(string categoryOrHttpMethod = null) where T : class
        {
            var output = string.Empty;
            var input  = _request.Get <T>();

            if (_authorization.IsAuthorized(input, categoryOrHttpMethod))
            {
                output = await invokeWrapped(typeof(T), categoryOrHttpMethod).ConfigureAwait(false);
            }
            return(output);
        }
Example #5
0
        public string Invoke <T>(string categoryOrHttpMethod = null) where T : class
        {
            var output = string.Empty;
            var input  = _request.Get <T>();

            if (_authorization.IsAuthorized(input, categoryOrHttpMethod))
            {
                output = invokeWrapped(typeof(T), categoryOrHttpMethod);
            }
            return(output);
        }
        public void Success()
        {
            var login = _request.Get <TwitterLoginRequest>();
            var url   = login.Url;

            if (url.IsEmpty())
            {
                url = "~/";
            }

            _writer.RedirectToUrl(url);
        }
        public void Success(IOAuth2Response response)
        {
            var login = _request.Get <T>();
            var url   = login.Url;

            if (url.IsEmpty())
            {
                url = "~/";
            }

            _writer.RedirectToUrl(url);
        }
        protected override DoNext performInvoke()
        {
            if (_fubuRequest.Has <TOutput>() && _fubuRequest.Get <TOutput>() != null)
            {
                return(DoNext.Continue);
            }
            var model = _fubuRequest.Get <NotFoundModel>();
            var url   = _urlRegistry.UrlFor(model);

            _outputWriter.RedirectToUrl(url);
            return(DoNext.Stop);
        }
Example #9
0
        protected override DoNext performInvoke()
        {
            // Might already be there from a different way
            if (_request.Has <T>())
            {
                return(DoNext.Continue);
            }

            var mimeTypes = _request.Get <CurrentMimeType>();


            var reader = ChooseReader(mimeTypes);

            _logger.DebugMessage(() => new ReaderChoice(mimeTypes, reader));

            if (reader == null)
            {
                failWithInvalidMimeType();
                return(DoNext.Stop);
            }

            var target = reader.Read(mimeTypes.ContentType);

            _request.Set(target);

            return(DoNext.Continue);
        }
Example #10
0
        protected override DoNext performInvoke()
        {
            var output = _request.Get <T>();

            _writer.Write(output);
            return(DoNext.Continue);
        }
        public void Invoke()
        {
            var features = _fubuRequest.Get <TInput>().GetFeatures();

            if (features.Any(x => !_featureValidator.IsActive(x)))
            {
                _handle404.Handle(_currentHttpRequest.FullUrl());

                return;
            }

            if (_innerBehavior != null)
            {
                _innerBehavior.Invoke();
            }
        }
        public void Write(string mimeType, TwitterLoginRequest resource)
        {
            var request = _request.Get <TwitterSignIn>();
            var tag     = new HtmlTag("a").Attr("href", _urls.UrlFor(request)).Text(TwitterLoginKeys.LoginWithTwitter);

            _writer.WriteHtml(tag.ToString());
        }
Example #13
0
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var entityFilter = new SingleEntityFilter <T>(request.Get <T>());

            _dataRestrictions.Each(entityFilter.ApplyRestriction);
            return(entityFilter.CanView ? AuthorizationRight.None : AuthorizationRight.Deny);
        }
        protected override DoNext performInvoke()
        {
            var mimeTypes = _request.Get <CurrentMimeType>();

            var writer = SelectWriter(mimeTypes);

            if (writer == null && InsideBehavior != null)
            {
                // TODO -- want this to be smarter later
                if (mimeTypes.AcceptsHtml() || mimeTypes.AcceptsAny())
                {
                    return(DoNext.Continue);
                }
            }

            if (writer == null)
            {
                _writer.WriteResponseCode(HttpStatusCode.NotAcceptable);
            }
            else
            {
                writer.Write(_source.FindValues(), _writer);
            }

            return(DoNext.Stop);
        }
Example #15
0
        protected override DoNext performInvoke()
        {
            var input = _request.Get <TInput>();

            _action(_controller, input);
            return(DoNext.Continue);
        }
Example #16
0
 private ElementGenerator(ITagGenerator <ElementRequest> tags, IFubuRequest request)
 {
     _tags  = tags;
     _model = new Lazy <T>(() => {
         return(request.Get <T>());
     });
 }
        public void Write(string mimeType, GoogleLoginRequest resource)
        {
            var     request = _request.Get <GoogleSignIn>();
            HtmlTag tag     = new HtmlTag("a").Attr("href", _urls.UrlFor(request)).Text(GoogleLoginKeys.LoginWithGoogle);

            _writer.WriteHtml(tag.ToString());
        }
Example #18
0
        public DiagnosticBehavior(IDebugReport report, IDebugDetector detector, IRequestHistoryCache history, IDebugCallHandler debugCallHandler, IFubuRequest request)
        {
            _report = report;
            _debugCallHandler = debugCallHandler;
            _detector = detector;

            _initialize = () => history.AddReport(report, request.Get<CurrentRequest>());
        }
Example #19
0
        public void HandleResourceNotFound <T>()
        {
            var messageNotFound = _fubuRequest.Get <QueueMessageNotFound>();

            _outputWriter.Write(MimeType.Html,
                                "Message with Id {0} cannot be found in queue {1}; message may have moved out of this queue."
                                .ToFormat(messageNotFound.Id.ToString(), messageNotFound.QueueName));
        }
        protected override DoNext performInvoke()
        {
            var item   = _request.Get <ItemRequest>();
            var entity = _repository.FindRequired <TEntity>(item.Id);

            _request.Set(entity);
            return(DoNext.Continue);
        }
 public override void Activate(ElementRequest request)
 {
     base.Activate(request);
     if (request.Model == null)
     {
         request.Model = _request.Get(request.HolderType());
     }
 }
Example #22
0
        protected override DoNext performInvoke()
        {
            var model = _request.Get <OtherInputModel>();

            model.HelloText = string.Format("You said: {0}", model.HelloText);

            return(DoNext.Continue);
        }
Example #23
0
        public void Invoke()
        {
            var input    = _fubuRequest.Get <TContextSupplier>();
            var contexts = input.GetContexts().ToDictionary(x => Guid.NewGuid(), x => x);

            foreach (var context in contexts)
            {
                _cmsContext.EnterContext(context.Key, context.Value);
            }

            _innerBehavior?.Invoke();

            foreach (var context in contexts)
            {
                _cmsContext.ExitContext(context.Key);
            }
        }
Example #24
0
        private void handleInvokation(Action invokation)
        {
            var model = _request.Get <TInputModel>();

            _cache.WithCache(model,
                             requestModel => _writer.Record(invokation),
                             cachedData => _writer.Write(cachedData.RecordedContentType, cachedData.Content));
        }
Example #25
0
        protected override Task <DoNext> performInvoke()
        {
            var model = _request.Get <OtherInputModel>();

            model.HelloText = $"You said: {model.HelloText}";

            return(Task.FromResult(DoNext.Continue));
        }
Example #26
0
        protected override DoNext performInvoke()
        {
            var output = _request.Get <DownloadFileModel>();

            _writer.WriteFile(output.ContentType, output.LocalFileName, output.FileNameToDisplay);

            return(DoNext.Continue);
        }
Example #27
0
        public DiagnosticBehavior(IDebugReport report, IDebugDetector detector, IRequestHistoryCache history, IDebugCallHandler debugCallHandler, IFubuRequest request)
        {
            _report           = report;
            _debugCallHandler = debugCallHandler;
            _detector         = detector;

            _initialize = () => history.AddReport(report, request.Get <CurrentRequest>());
        }
Example #28
0
        public void Invoke()
        {
            // There is a T Get<T>() method on IFubuRequest, but in
            // my infinite wisdom I made it so that it only works
            // for reference types
            var status = (HttpStatusCode)_request.Get(typeof(HttpStatusCode));

            _writer.WriteResponseCode(status);
        }
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var athleteId = request.Get<AthleteSpecific>().AthleteId;
            var athlete = session.Load<Athlete>(athleteId);

            if (athlete.UserName == secContext.CurrentIdentity.Name)
                return AuthorizationRight.Allow;
            return AuthorizationRight.Deny;
        }
Example #30
0
        protected override DoNext performInvoke()
        {
            // Extract the PrivateMessage to render.
            var message = _request.Get <PrivateMessage>();

            _writer.Write(MimeType.Text, message.Name);

            return(DoNext.Continue);
        }
Example #31
0
        public void Invoke <T>() where T : class
        {
            var input = _request.Get <T>();

            if (_authorization.IsAuthorized(input))
            {
                _factory.BuildPartial(typeof(T)).InvokePartial();
            }
        }
Example #32
0
        protected override Task <DoNext> performInvoke()
        {
            var output = _request.Get <DownloadFileModel>();

            // TODO -- definitely switch to async writing
            _writer.WriteFile(output.ContentType, output.LocalFileName, output.FileNameToDisplay);

            return(Task.FromResult(DoNext.Continue));
        }
Example #33
0
        private void execute(Action innerInvocation)
        {
            var currentRequest = _request.Get <CurrentRequest>();

            _inputHandler.ReadInput(currentRequest, _request);

            innerInvocation();

            _outputHandler.WriteOutput(currentRequest, _request);
        }
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var authToken = request.Get<AuthenticationTokenRequest>();

            //Workaround: RightsFor is getting called multiple times because of a Fubu bug
            if(request.Has<IAuthenticationToken>()) return AuthorizationRight.Allow;

            var token = authToken.authToken;

            if(token.IsEmpty())
            {
                if(_currentSdkUser.IsAuthenticated)
                {
                    _logger.LogDebug("No AuthToken was found in this request but a user is authenticated. Using the current user's credentials.");
                    return AuthorizationRight.Allow;
                }

                return AuthorizationRight.Deny;
            }

            _logger.LogDebug("Authentication token {0} found.", token);

            var authenticationToken = _tokenRepository.RetrieveByToken(token);
            if (authenticationToken == null)
            {
                return AuthorizationRight.Deny;

            }

            _logger.LogDebug("Authentication token {0} found and validated for user {1}.", authenticationToken, authenticationToken);
            request.Set(authenticationToken);

            _currentSdkUser.SetUser(_principalFactory.CreatePrincipal(authenticationToken.Username));

            return AuthorizationRight.Allow;
        }
 public SiteResourceAttacher(ISparkViewEngine engine, IFubuRequest request)
 {
     _engine = engine;
     _request = request.Get<CurrentRequest>();
 }