116 lines
4.0 KiB
C#
116 lines
4.0 KiB
C#
/*
|
|
* OCPP.Core - https://github.com/dallmann-consulting/OCPP.Core
|
|
* Copyright (C) 2020-2021 dallmann consulting GmbH.
|
|
* All Rights Reserved.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using OCPP.Core.Database;
|
|
|
|
namespace OCPP.Core.Management
|
|
{
|
|
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.AddOCPPDbContext(Configuration);
|
|
|
|
services.AddControllersWithViews();
|
|
|
|
services.AddAuthentication(
|
|
CookieAuthenticationDefaults.AuthenticationScheme)
|
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
|
|
options =>
|
|
{
|
|
options.LoginPath = "/Account/Login";
|
|
options.LogoutPath = "/Account/Logout";
|
|
});
|
|
|
|
services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
|
|
services.AddMvc()
|
|
.AddViewLocalization(
|
|
LanguageViewLocationExpanderFormat.Suffix,
|
|
opts => { opts.ResourcesPath = "Resources"; })
|
|
.AddDataAnnotationsLocalization();
|
|
|
|
// authentication
|
|
services.AddAuthentication(options =>
|
|
{
|
|
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
|
});
|
|
|
|
services.AddTransient(
|
|
m => new UserManager(Configuration)
|
|
);
|
|
services.AddDistributedMemoryCache();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseAuthentication();
|
|
app.UseRouting();
|
|
app.UseAuthorization();
|
|
|
|
var supportedCultures = new[] { "en", "de" };
|
|
var localizationOptions = new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[0])
|
|
.AddSupportedCultures(supportedCultures)
|
|
.AddSupportedUICultures(supportedCultures);
|
|
app.UseRequestLocalization(localizationOptions);
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}/{connectorId?}/");
|
|
});
|
|
}
|
|
}
|
|
}
|