public override async ValueTask <RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values) { var displayUrl = httpContext.Request.GetDisplayUrl(); var uri = ConvertStringToUri(displayUrl); if (uri != null) { CmsTreeNode?cmsTreeNode = await cmsTreeService.GetCmsTreeNode(CmsTreeType, uri.AbsolutePath, null).ConfigureAwait(false); if (cmsTreeNode != null && cmsTreeNode.CmsItemId.HasValue) { var cmsItem = await readCmsItemService.Read <CmsItem>(CmsTreeType, cmsTreeNode.CmsItemId.Value, null).ConfigureAwait(false); if (cmsItem != null) { return(new RouteValueDictionary() { { "controller", cmsTreeNode.CmsItemType }, { "action", "Index" }, { "area", null }, { "cmsItemId", cmsTreeNode.CmsItemId.Value }, }); } } } return(new RouteValueDictionary()); }
public async Task <IActionResult> Login(string email, string password) { var(users, total) = await readCmsItemService.List(CmsUser.DefaultCmsType, null, null, searchQuery : email); if (users.Any()) { var user = (await readCmsItemService.Read <CmsItem>(CmsUser.DefaultCmsType, users.First().Id, null))?.ToObject <CmsUser>(); if (user != null && BCrypt.Net.BCrypt.Verify(password, user.PasswordEncrypted)) { var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme); identity.AddClaim(new Claim(ClaimTypes.Name, user.Email)); identity.AddClaim(new Claim(ClaimTypes.Email, user.Email)); identity.AddClaim(new Claim(ClaimTypes.Role, "cms")); var principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTimeOffset.UtcNow.AddMonths(3) }); return(RedirectToAction("Index", "Home", new { Area = "cms" })); } } ModelState.AddModelError("email", "User not found"); return(View()); }
public Task <T?> Read <T>(CmsType cmsType, Guid id, string?lang) where T : CmsItem { IReadCmsItem firstReadProdiver = GetReadProvider(cmsType); return(firstReadProdiver.Read <T>(cmsType, id, lang)); }
public async Task <CmsItem?> Load([FromRoute] string cmsType, [FromRoute] Guid id, [FromRoute] string?lang) { var cmsItem = await readCmsItemService.Read <CmsItem>(cmsType, id, lang).ConfigureAwait(false); return(cmsItem); }
public async Task <IActionResult> Delete([FromRoute] string cmsType, [FromRoute] Guid id, [FromRoute] string?lang, [FromQuery] string?treeItemSchemaKey, [FromQuery] Guid?treeNodeId) { if (id == Guid.Empty) { return(new NotFoundResult()); } var cmsMenuItem = schemaService.GetCmsType(cmsType); if (cmsMenuItem == null) { return(new NotFoundResult()); } var schemaKey = cmsMenuItem.SchemaKey; List <CmsTreeNode> nodes = new List <CmsTreeNode>(); if (cmsMenuItem.IsTree) { nodes = await cmsTreeService.GetCmsTreeNodesForCmsItemId(cmsType, id, lang); if (nodes.Any()) { schemaKey = nodes.First().CmsItemType; } else { schemaKey = treeItemSchemaKey; if (treeNodeId.HasValue) { nodes = await cmsTreeService.GetCmsTreeNodesForNodeId(cmsType, treeNodeId.Value, lang); } } if (schemaKey == null) { //TODO: Forward to pick a schema } } if (schemaKey == null) { return(new NotFoundResult()); } var schema = schemaService.GetSchema(schemaKey); if (schema == null) { return(new NotFoundResult()); } var data = await readCmsItemService.Read <CmsItem>(cmsType, id, lang).ConfigureAwait(false); var model = new EditViewModel { CmsType = cmsType, Id = id, SchemaLocation = schema, MenuCmsItem = cmsMenuItem, CmsConfiguration = schemaService.GetCmsConfiguration(), Language = lang, Data = data, Nodes = nodes, TreeItemSchemaKey = treeItemSchemaKey, TreeNodeId = treeNodeId }; return(View("Delete", model)); }
public async Task <IActionResult> Index(Guid cmsItemId) { var item = await dataProviderService.Read <CmsItem>(PageTreeRoutes.PageTreeType, cmsItemId, null); return(View(item)); }