示例#1
0
        public string GenerateActivationKey(DbT10Software db)
        {
            Random       r     = new Random();
            const string chars = "abcdefghiijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

            List <string> keys = db.OrderDetails.Select(od => od.Id).ToList();

            StringBuilder sb = null;

            while (sb == null || keys.Contains(sb.ToString()))
            {
                sb = new StringBuilder();
                for (int i = 0; i < 14; i++)
                {
                    if (i == 4 || i == 9)
                    {
                        sb.Append("-");
                    }
                    else
                    {
                        sb.Append(chars[r.Next(chars.Length)]);
                    }
                }
            }

            return(sb.ToString());
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DbT10Software db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseMiddleware <SessionKeeper>();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Gallery}/{action=Index}/{id?}");
            });

            // Comment next line away if you don't want to restart the database every time
            db.Database.EnsureDeleted();

            db.Database.EnsureCreated();
            // Comment next line away to not reseed database
            new DbSeeder(db).Seed();
        }
示例#3
0
        public List <Cart> LoadProducts(DbT10Software db)
        {
            List <Cart> loadedCart = new List <Cart>();

            foreach (var item in Products)
            {
                loadedCart.Add(new Cart
                {
                    Id        = 0,
                    ProductId = item.ProductId,
                    Product   = db.Products.FirstOrDefault(product => product.Id == item.ProductId),
                    Quantity  = item.Quantity,
                    UserId    = 0
                });
            }
            return(loadedCart);
        }
示例#4
0
 public CartController(DbT10Software _db, Verify v)
 {
     this._db = _db;
     _v       = v;
 }
 public LogoutController(DbT10Software db)
 {
     _db = db;
 }
示例#6
0
        public async Task Invoke(HttpContext context, ITempDataProvider tdp, DbT10Software db)
        {
            // check and get exisiting user lastaccesstime
            string lastAccess = context.Request.Cookies["lastAccessTime"];

            // Check if lastAccessTime session object is available
            if (lastAccess == null)
            {
                // When lastAccessTime is null, it is a new session
                context.Response.Cookies.Append("lastAccessTime", DateTime.Now.ToString(), new CookieOptions
                {
                    HttpOnly = true,
                    SameSite = SameSiteMode.Lax
                });
            }
            else
            {
                // When lastAccessTime is present, check if it has passed 20 minutes
                DateTime lastAccessDateTime = Convert.ToDateTime(lastAccess);

                // If now is more than 20 mins from lastAccessTime
                if (DateTime.Now.CompareTo(lastAccessDateTime.AddMinutes(20)) == 1)
                {
                    //if user not active, remove the last accesstime and redirect to session timeout controller
                    //controller will clean up session and redirect to gallery page with session timeout message
                    context.Response.Cookies.Delete("lastAccessTime");

                    string sessionId = context.Request.Cookies["sessionId"];

                    if (sessionId != null)
                    {
                        var session = db.Sessions.FirstOrDefault(session => session.Id == sessionId);

                        if (session != null)
                        {
                            db.Sessions.Remove(session);
                            db.SaveChanges();
                        }
                    }

                    context.Response.Cookies.Delete("sessionId");

                    // Uses injected TempDataProvider to add TempData into context without controller
                    tdp.SaveTempData(context, new Dictionary <string, object> {
                        ["Alert"] = "warning|Your session has timed-out!"
                    });

                    context.Response.Redirect("/Gallery/Index");

                    return;
                }
                else
                {
                    // if user still active, keep Update last access time stamp
                    context.Response.Cookies.Append("lastAccessTime", DateTime.Now.ToString(), new CookieOptions
                    {
                        HttpOnly = true,
                        SameSite = SameSiteMode.Lax
                    });
                }
            }

            await next(context);
        }
 public GalleryController(DbT10Software db, Verify v)
 {
     _db = db;
     _v  = v;
 }
示例#8
0
 public PurchaseController(DbT10Software db)
 {
     _db = db;
 }