123 lines
4.5 KiB
C#
123 lines
4.5 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using UTB.Eshop.Web.Models.ApplicationServices.Abstraction;
|
|
using UTB.Eshop.Web.Models.ApplicationServices.Implementation;
|
|
using UTB.Eshop.Web.Models.Database;
|
|
using UTB.Eshop.Web.Models.Identity;
|
|
|
|
namespace UTB.Eshop.Web
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddDbContext<EshopDbContext>(options => options.UseMySql(Configuration.GetConnectionString("MySqlConnectionString"), new MySqlServerVersion("8.0.26")));
|
|
|
|
services.AddIdentity<User, Role>()
|
|
.AddEntityFrameworkStores<EshopDbContext>()
|
|
.AddDefaultTokenProviders();
|
|
|
|
services.Configure<IdentityOptions>(options =>
|
|
{
|
|
options.Password.RequireDigit = false;
|
|
options.Password.RequiredLength = 3;
|
|
options.Password.RequireNonAlphanumeric = false;
|
|
options.Password.RequireUppercase = false;
|
|
options.Password.RequireLowercase = false;
|
|
options.Password.RequiredUniqueChars = 2;
|
|
|
|
options.Lockout.AllowedForNewUsers = true;
|
|
options.Lockout.MaxFailedAccessAttempts = 10;
|
|
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
|
|
|
|
options.User.RequireUniqueEmail = true;
|
|
});
|
|
|
|
services.ConfigureApplicationCookie(options =>
|
|
{
|
|
options.Cookie.HttpOnly = true;
|
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
|
|
options.LoginPath = "/Security/Account/Login";
|
|
options.LogoutPath = "/Security/Account/Logout";
|
|
options.SlidingExpiration = true;
|
|
});
|
|
|
|
|
|
services.AddScoped<ISecurityApplicationService, SecurityIdentityApplicationService>();
|
|
|
|
services.AddDistributedMemoryCache(); // Adds a default in-memory implementation of IDistributedCache
|
|
services.AddSession(options =>
|
|
{
|
|
// Set a short timeout for easy testing.
|
|
options.IdleTimeout = TimeSpan.FromMinutes(30);
|
|
options.Cookie.HttpOnly = true;
|
|
// Make the session cookie essential
|
|
options.Cookie.IsEssential = true;
|
|
});
|
|
|
|
services.AddControllersWithViews();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
//nastaveni CultureInfo tak, aby se mena zobrazovala v dolarech ;-)
|
|
var cultInfo = new CultureInfo(CultureInfo.CurrentCulture.Name);
|
|
cultInfo.NumberFormat.CurrencySymbol = "$";
|
|
CultureInfo.DefaultThreadCurrentCulture = cultInfo;
|
|
CultureInfo.DefaultThreadCurrentUICulture = cultInfo;
|
|
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseSession();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllerRoute(
|
|
name: "areas",
|
|
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
|
|
);
|
|
endpoints.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
});
|
|
}
|
|
}
|
|
}
|