Exemple #1
0
        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());
        }
Exemple #2
0
        public async Task <IActionResult> List([FromRoute] string cmsType, [FromQuery] string?sortField, [FromQuery] string?sortOrder, [FromQuery] int pageIndex, [FromQuery] string?q)
        {
            ViewBag.SortField   = sortField;
            ViewBag.SortOrder   = sortOrder;
            ViewBag.SearchQuery = q;

            var cmsMenuItem = schemaService.GetCmsType(cmsType);

            if (cmsMenuItem == null)
            {
                return(new NotFoundResult());
            }

            if (cmsMenuItem.IsTree)
            {
                return(await ListTree(cmsType, null, q));
            }

            if (cmsMenuItem.SchemaKey == null)
            {
                return(new NotFoundResult());
            }

            var schema = schemaService.GetSchema(cmsMenuItem.SchemaKey);

            if (schema == null)
            {
                throw new Exception($"schema not found for key: {cmsMenuItem.SchemaKey}");
            }

            int pageSize = cmsMenuItem.PageSize;

            if (pageSize <= 0)
            {
                pageSize = 20;
            }

            var(results, total) = await readCmsItemService.List(cmsType, sortField, sortOrder, pageSize : pageSize, pageIndex, q).ConfigureAwait(false);

            if (cmsMenuItem.IsSingleton)
            {
                if (results.Any())
                {
                    return(RedirectToAction("Edit", "Edit", new { cmsType = cmsType, id = results.First().Id }));
                }
                else
                {
                    return(RedirectToAction("Create", "Edit", new { cmsType = cmsType }));
                }
            }

            var model = new ListViewModel
            {
                CmsType     = cmsType,
                Schema      = schema,
                MenuCmsItem = cmsMenuItem,
                Items       = results,
                TotalPages  = total,
                CurrentPage = pageIndex + 1,
                PageSize    = pageSize
            };

            return(View(model));
        }
Exemple #3
0
        public Task <(IReadOnlyList <CmsItem> results, int total)> List(CmsType cmsType, string?sortField, string?sortOrder, int pageSize = 20, int pageIndex = 0, string?searchQuery = null)
        {
            IReadCmsItem firstReadProdiver = GetReadProvider(cmsType);

            return(firstReadProdiver.List(cmsType, sortField, sortOrder, pageSize, pageIndex, searchQuery));
        }
Exemple #4
0
        public async Task <IReadOnlyList <CmsItem> > List([FromRoute] string cmsType, [FromQuery] string?sortField, [FromQuery] string?sortOrder)
        {
            var(results, _) = await readCmsItemService.List(cmsType, sortField, sortOrder).ConfigureAwait(false);

            return(results);
        }