-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
96 lines (68 loc) · 2.83 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Kisa_Kuikka.Data;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers;
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.StaticFiles;
using Kisa_Kuikka.Auth;
using Kisa_Kuikka.Services;
using Kisa_Kuikka.Models.DynamicAuth;
using Kisa_Kuikka.Filters;
using Kisa_Kuikka.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Kisa_Kuikka.Controllers;
using System.Reflection;
//using static NPOI.XSSF.UserModel.Charts.XSSFLineChartData<Tx, Ty>;
var builder = WebApplication.CreateBuilder(args);
ConfigurationManager configuration = builder.Configuration;
// Add services to the container.
var DBHOST = Environment.GetEnvironmentVariable("DB_HOST");
var DBPORT = Environment.GetEnvironmentVariable("DB_PORT");
var DBNAME = Environment.GetEnvironmentVariable("DB_NAME");
var DBUSER = Environment.GetEnvironmentVariable("DB_USER");
var DBUSERPASSWD = Environment.GetEnvironmentVariable("DB_USER_PASSWORD");
var connectionString = $"Server={DBHOST},{DBPORT};Database={DBNAME};User ID={DBUSER};Password={DBUSERPASSWD};TrustServerCertificate=True;MultipleActiveResultSets=true;";
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddIdentity<IdentityUser, IdentityRole>(options => {
//aseta salasana ja kirjautumis säännöt
options.SignIn.RequireConfirmedAccount = false;
options.Password.RequireNonAlphanumeric = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddErrorDescriber<CustomIdentityErrorDescriber>()
.AddDefaultTokenProviders()
.AddDefaultUI();
var mvcbuilder = builder.Services.AddControllersWithViews();
builder.Services.AddDynamicAuthorization<ApplicationDbContext>(options => options.DefaultAdminUser = Environment.GetEnvironmentVariable("DefaultAdminUser"))
.AddSqlServerStore(options => options.ConnectionString = connectionString)
.AddUi(mvcbuilder);
builder.Services.AddRazorPages();
builder.Services.AddScoped<IilmoitusService, IlmoitusService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/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.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
app.MapControllers();
app.Run();