Beispiel #1
0
        public IActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var adminSettings = _conf.Get <AdminSettings>();

            if (model.Password == adminSettings.Password && model.Login == adminSettings.Login)
            {
                HttpContext.Session.Authorize();
                return(RedirectToAction("Index", "Home", new { Area = "Dashboard" }));
            }

            TempData["fail"] = "Ошибка авторизации";
            return(View(model));
        }
Beispiel #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!_conf.Get <MainSettings>().Installed&& filterContext.HttpContext.Request.Path == "/Dashboard/Home/Install")
            {
                return;
            }

            if (filterContext.HttpContext.Request.Path == "/Dashboard/Home/Login")
            {
                return;
            }

            if (!filterContext.HttpContext.Session.IsAuthorized())
            {
                filterContext.Result = new RedirectToActionResult("Login", "Home", new { Area = "Dashboard" });
            }

            base.OnActionExecuting(filterContext);
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IConfProvider conf)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseStatusCodePagesWithReExecute("/error/{0}");

            app.Use((httpContext, next) =>
            {
                const string url = "/Dashboard/Home/Install";
                if (!conf.Get <MainSettings>().Installed&& httpContext.Request.Path != url)
                {
                    Console.WriteLine("Redirected");
                    httpContext.Response.Redirect($"http://{httpContext.Request.Host}{url}");
                }
                return(next());
            });

            app.UseSession();

            // Session middleware
            app.Use((httpContext, nextMiddleware) =>
            {
                if (!httpContext.Session.Keys.Contains(SessionHelper.KeyCurrency))
                {
                    httpContext.Session.SetCurrency(Currency.RUR);
                }

                if (!httpContext.Session.Keys.Contains(SessionHelper.KeyCart))
                {
                    httpContext.Session.SetCartId(string.Empty);
                }

                return(nextMiddleware());
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "productListPager",
                    template: "Products/Page-{page:int}",
                    defaults: new { controller = "Product", action = "Index", category = 0 }
                    );

                routes.MapRoute(
                    name: "productListCategory",
                    template: "Products/Category-{category:int}",
                    defaults: new { controller = "Product", action = "Index", page = 1 }
                    );

                routes.MapRoute(
                    name: "productListCategoryPager",
                    template: "Products/Category-{category:int}/Page-{page:int}",
                    defaults: new { controller = "Product", action = "Index" }
                    );


                routes.MapRoute(
                    name: "productListSearch",
                    template: "Products/{search}",
                    defaults: new { controller = "Product", action = "Search", page = 1 }
                    );

                routes.MapRoute(
                    name: "productListSearchPager",
                    template: "Products/{search}/Page-{page:int}",
                    defaults: new { controller = "Product", action = "Search" }
                    );

                routes.MapRoute(
                    name: "productDetails",
                    template: "Product/{id:int}",
                    defaults: new { controller = "Product", action = "Details" }
                    );

                routes.MapRoute(
                    name: "productList",
                    template: "Products/",
                    defaults: new { controller = "Product", action = "Index", category = 0 }
                    );

                routes.MapRoute(
                    name: "cartView",
                    template: "Cart/",
                    defaults: new { controller = "Cart", action = "ViewCart" }
                    );

                routes.MapRoute("areaRoute", "{area:exists}/{controller=Home}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Product}/{action=Index}/{id?}");
            });
        }
Beispiel #4
0
 public IActionResult System()
 {
     return(View(_conf.Get <MainSettings>()));
 }
Beispiel #5
0
        public async Task <IActionResult> Index(int category = 0, int page = 1)
        {
            var result = await _client.GetCategoryGoods(categoryId : category, currency : HttpContext.Session.GetCurrency(), pageNumber : page, countGoods : (int)_conf.Get <MainSettings>().CountOfGoodsPerPage);

            return(View(result));
        }