/// <summary> /// Indicates whether the specified url matches this routing rule. /// </summary> /// <param name="url">The url to test</param> /// <param name="pageRoute">The page route already matched to this url.</param> public bool MatchesRule(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var routingPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(routingPart)) { return(false); } var match = Regex.Match(routingPart, ROUTE_REGEX); if (!match.Success) { return(false); } var isMatch = IntParser.ParseOrDefault(match.Groups[1].Value) > 0; return(isMatch); }
/// <summary> /// Returns a query that can be used to look up the CustomEntityRoute relating /// to the matched entity. Throws an exception if the MatchesRule returns false, so /// check this before calling this method. /// </summary> /// <param name="url">The url to parse custom entity key data from</param> /// <param name="pageRoute">The page route matched to the url</param> /// <returns>An IQuery object that can used to query for the CustomEntityRoute</returns> public IQuery <CustomEntityRoute> ExtractRoutingQuery(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } if (!MatchesRule(url, pageRoute)) { throw new ArgumentException(nameof(url) + $" does not match the specified page route. {nameof(ExtractRoutingQuery)} can only be called after a successful page route match.", nameof(url)); } var routingPart = GetRoutingPart(url, pageRoute); var customEntityId = IntParser.ParseOrDefault(routingPart); var query = new GetCustomEntityRouteByPathQuery(); query.CustomEntityDefinitionCode = pageRoute.CustomEntityDefinitionCode; query.CustomEntityId = customEntityId; if (pageRoute.Locale != null) { query.LocaleId = pageRoute.Locale.LocaleId; } return(query); }
private AddUserCommand MapCommand(AddUserWithTemporaryPasswordCommand command) { // The password policy should be configured with the definitive min-length // as an attribute, but otherwise fall-back to the configured option var passwordPolicy = _passwordPolicyService.GetDescription(command.UserAreaCode); var minLengthAttribute = passwordPolicy.Attributes.GetOrDefault(PasswordPolicyAttributes.MinLength); var options = _userAreaDefinitionRepository.GetOptionsByCode(command.UserAreaCode); var minLength = IntParser.ParseOrDefault(minLengthAttribute, options.Password.MinLength); var newUserCommand = new AddUserCommand() { FirstName = command.FirstName, LastName = command.LastName, DisplayName = command.DisplayName, Email = command.Email, Username = command.Username, Password = _passwordGenerationService.Generate(minLength), RequirePasswordChange = true, UserAreaCode = command.UserAreaCode, RoleId = command.RoleId, RoleCode = command.RoleCode }; return(newUserCommand); }
/// <summary> /// Indicates whether the specified url matches this routing rule. /// </summary> /// <param name="url">The url to test</param> /// <param name="pageRoute">The page route already matched to this url.</param> public bool MatchesRule(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var routingPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(routingPart)) { return(false); } var isMatch = IntParser.ParseOrDefault(routingPart) > 0; return(isMatch); }
/// <summary> /// Verifies the security stamp claim in the specified <paramref name="principal"/>. If the validation /// if successful then a <see cref="IClaimsPrincipalBuilderContext"/> instance is returned which can be /// used to refresh the principal. If the stamp is invalid for any reason then <see langword="null"/> /// is returned. /// </summary> /// <param name="principal">The principal to verify.</param> protected virtual async Task <IClaimsPrincipalBuilderContext> VerifyClaimsPrincipalAsync(ClaimsPrincipal principal) { if (principal == null) { return(null); } var userId = IntParser.ParseOrDefault(principal.FindFirstValue(CofoundryClaimTypes.UserId)); var context = await _claimsPrincipalBuilderContextRepository.GetAsync(userId); if (context == null) { return(null); } var securityStampClaim = principal.FindFirstValue(CofoundryClaimTypes.SecurityStamp); if (string.IsNullOrEmpty(context.SecurityStamp) || securityStampClaim == context.SecurityStamp) { return(context); } _logger.LogDebug("Security stamp validation failed."); return(null); }
public async Task <IViewComponentResult> InvokeAsync() { // ModelBinder is not supported in view components so we have to bind // this manually. We have an issue open to try and improve the experience here // https://github.com/cofoundry-cms/cofoundry/issues/125 var webQuery = new SearchBlogPostsQuery(); webQuery.PageNumber = IntParser.ParseOrDefault(Request.Query[nameof(webQuery.PageNumber)]); webQuery.PageSize = IntParser.ParseOrDefault(Request.Query[nameof(webQuery.PageSize)]); webQuery.CategoryId = IntParser.ParseOrDefault(Request.Query[nameof(webQuery.CategoryId)]); var query = new SearchCustomEntityRenderSummariesQuery(); query.CustomEntityDefinitionCode = BlogPostCustomEntityDefinition.DefinitionCode; query.PageNumber = webQuery.PageNumber; query.PageSize = 30; query.PublishStatus = PublishStatusQuery.Published; // TODO: Filtering by Category (webQuery.CategoryId) // Searching/filtering custom entities is not implemented yet, but it // is possible to build your own search index using the message handling // framework or writing a custom query against the UnstructuredDataDependency table // See issue https://github.com/cofoundry-cms/cofoundry/issues/12 var entities = await _customEntityRepository.SearchCustomEntityRenderSummariesAsync(query); var viewModel = await MapBlogPostsAsync(entities); return(View(viewModel)); }
/// <summary> /// ModelBinder is not supported in view components so we have to bind /// this manually. We have an issue open to try and improve the experience here /// https://github.com/cofoundry-cms/cofoundry/issues/125 /// </summary> private SearchBlogPostsQuery ModelBind() { var webQuery = new SearchBlogPostsQuery(); webQuery.PageNumber = IntParser.ParseOrDefault(Request.Query[nameof(webQuery.PageNumber)]); webQuery.PageSize = IntParser.ParseOrDefault(Request.Query[nameof(webQuery.PageSize)]); webQuery.CategoryId = IntParser.ParseOrDefault(Request.Query[nameof(webQuery.CategoryId)]); return(webQuery); }
public static IImageResizeSettings ParseFromQueryString(IQueryCollection queryString) { var settings = new ImageResizeSettings(); settings.Width = IntParser.ParseOrDefault(GetQueryStringValue(queryString, QS_WIDTH)); settings.Height = IntParser.ParseOrDefault(GetQueryStringValue(queryString, QS_HEIGHT)); settings.Anchor = EnumParser.ParseOrDefault <ImageAnchorLocation>(GetQueryStringValue(queryString, QS_ANCHOR), settings.Anchor); settings.Mode = EnumParser.ParseOrDefault <ImageFitMode>(GetQueryStringValue(queryString, QS_MODE), settings.Mode); settings.Scale = EnumParser.ParseOrDefault <ImageScaleMode>(GetQueryStringValue(queryString, QS_SCALE), settings.Scale); settings.BackgroundColor = StringHelper.EmptyAsNull(GetQueryStringValue(queryString, QS_BACKGROUND_COLOR)); return(settings); }
public static IImageResizeSettings ParseFromQueryString(string queryString) { var qs = HttpUtility.ParseQueryString(queryString); var settings = new ImageResizeSettings(); settings.Width = IntParser.ParseOrDefault(qs[QS_WIDTH]); settings.Height = IntParser.ParseOrDefault(qs[QS_HEIGHT]); settings.Anchor = EnumParser.ParseOrDefault <ImageAnchorLocation>(qs[QS_ANCHOR], settings.Anchor); settings.Mode = EnumParser.ParseOrDefault <ImageFitMode>(qs[QS_MODE], settings.Mode); settings.Scale = EnumParser.ParseOrDefault <ImageScaleMode>(qs[QS_SCALE], settings.Scale); settings.BackgroundColor = StringHelper.EmptyAsNull(qs[QS_BACKGROUND_COLOR]); return(settings); }