public void Render <T>(IFubuPage view, T viewModel, string prefix, TextWriter writer, int?index = null) where T : class { var page = new Page(); page.Controls.Add(view as Control); var shouldClearModel = false; if (viewModel != null) { shouldClearModel = !_request.Has(viewModel.GetType()); _request.Set(viewModel.GetType(), viewModel); } _activator.Activate(view); setParentPageIfNotAlreadySet(view, page); if (index.HasValue) { prefix = "{0}[{1}]".ToFormat(prefix, index); } view.ElementPrefix = prefix; _builder.ExecuteControl(page, writer); writer.Flush(); if (shouldClearModel) { _request.Clear(viewModel.GetType()); } }
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); }
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); }
public object InvokeFast(BehaviorChain chain, object input = null) { _request.Set(OutputPartialBehavior.None); if (input != null) { _request.Set(chain.InputType(), input); } try { var partial = _factory.BuildPartial(chain); partial.InvokePartial(); // TODO -- how to detect authorization failures here? var resourceType = chain.ResourceType(); return(_request.Has(resourceType) ? _request.Get(resourceType) : null); } finally { _request.Set(OutputPartialBehavior.Write); } }
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); }
// SAMPLE: input-behavior-mechanics protected override DoNext performInvoke() { // Might already be there from a different way if (_request.Has <T>()) { return(DoNext.Continue); } // Resolve our CurrentMimeType object from the // HTTP request that we use to represent // the mimetypes of the current request var mimeTypes = _request.Get <CurrentMimeType>(); // Choose the first reader that says it // can read the mimetype from the // 'content-type' header in the request var reader = ChooseReader(mimeTypes); _logger.DebugMessage(() => new ReaderChoice(mimeTypes, reader)); if (reader == null) { // If we don't find a matching Reader for the // content-type of the request, this request fails // with an HTTP 415 return code failWithInvalidMimeType(); return(DoNext.Stop); } // Use the selected reader var target = reader.Read(mimeTypes.ContentType); _request.Set(target); return(DoNext.Continue); }
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 RegisterModel Register(RegisterInput input) { return(_request.Has <RegisterModel>() ? _request.Get <RegisterModel>() : new RegisterModel()); }