empty backoffice: working!

This commit is contained in:
2020-03-22 14:47:59 +01:00
parent 676f218c3f
commit e70f9e9390
10 changed files with 235 additions and 34 deletions
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
namespace unjo.Core.Attributes
{
public class OperationCancelledExceptionFilterAttribute : ExceptionFilterAttribute
{
private readonly ILogger _logger;
public OperationCancelledExceptionFilterAttribute(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<OperationCancelledExceptionFilterAttribute>();
}
public override void OnException(ExceptionContext context)
{
if (context.Exception is OperationCanceledException)
{
_logger.LogInformation("Request was cancelled");
context.ExceptionHandled = true;
context.Result = new StatusCodeResult(400);
}
}
}
}
+49
View File
@@ -0,0 +1,49 @@
namespace unjo.Core
{
public class BackofficeConfiguration : IBackofficeConfiguration
{
public string SystemUserId { get; set; }
public FoldersConfig Folders { get; set; }
public RavenConfig Raven { get; set; }
public LoggingConfig Logging { get; set; }
}
public interface IBackofficeConfiguration
{
string SystemUserId { get; set; }
FoldersConfig Folders { get; set; }
RavenConfig Raven { get; set; }
LoggingConfig Logging { get; set; }
}
public class FoldersConfig
{
public string Temp { get; set; }
}
public class LoggingConfig
{
public bool IncludeScopes { get; set; }
public LogLevel LogLevel { get; set; }
}
public class LogLevel
{
public string Default { get; set; }
public string System { get; set; }
public string Microsoft { get; set; }
}
public class RavenConfig
{
public string Url { get; set; }
public string Database { get; set; }
public string License { get; set; }
}
}
+5
View File
@@ -5,4 +5,9 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.2" />
</ItemGroup>
</Project>
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace unjo.Web.Controllers
{
public abstract class BackofficeController : Controller
{
}
}
+14
View File
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace unjo.Web.Controllers
{
[AllowAnonymous]
public class IndexController : BackofficeController
{
public IActionResult Index()
{
return View("/Index.cshtml");
}
}
}
+5 -7
View File
@@ -1,11 +1,9 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
@{
string theme = HttpContextAccessor.HttpContext.Request.Cookies["theme"] ?? "dark";
Layout = null;
}
<!DOCTYPE html>
<html data-theme="@theme">
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow">
@@ -22,13 +20,13 @@
<meta name="msapplication-TileColor" content="#161e25">
<meta name="theme-color" content="#161e25">
<base href="~/">
<environment exclude="Development">
@*<environment exclude="Development">
<link href="~/Assets/app.css" rel="stylesheet" asp-append-version="true" />
</environment>
<title>fifty</title>
</environment>*@
<title>unjo</title>
</head>
<body>
<div id="app"></div>
<script src="~/Assets/app.js" asp-append-version="true"></script>
@*<script src="~/Assets/app.js" asp-append-version="true"></script>*@
</body>
</html>
+4 -6
View File
@@ -1,24 +1,22 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:51017",
"sslPort": 0
"applicationUrl": "http://localhost:2300",
"sslPort": 44308
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"unjo": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"applicationUrl": "http://localhost:2300",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
+110 -8
View File
@@ -1,35 +1,137 @@
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System;
using System.Threading.Tasks;
using unjo.Core;
namespace unjo.Web
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
private readonly IConfiguration config;
private IWebHostEnvironment env;
/// <summary>
/// Bootstrap the application
/// </summary>
public Startup(IConfiguration config, IWebHostEnvironment env)
{
this.config = config;
this.env = env;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
/// </summary>
public void ConfigureServices(IServiceCollection services)
{
//CultureInfo cultureInfo = new CultureInfo("en-US");
//cultureInfo.NumberFormat.CurrencySymbol = "€";
//CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
// build and register app configuration
services.Configure<IBackofficeConfiguration>(config);
BackofficeConfiguration appConfig = new BackofficeConfiguration();
ConfigurationBinder.Bind(config, appConfig);
services.AddSingleton<IBackofficeConfiguration>(appConfig);
// add unjo core
//services.AddCore(appConfig, env);
// add cookie-based authentication
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(opts => {
opts.Events.OnRedirectToLogin = (context) =>
{
context.Response.StatusCode = 401;
return Task.CompletedTask;
};
});
// add Core MVC
IMvcBuilder mvc = services.AddMvc(opts =>
{
opts.Filters.Add<Core.Attributes.OperationCancelledExceptionFilterAttribute>();
})
//.ExtendWithCore()
.AddNewtonsoftJson(opts =>
{
opts.SerializerSettings.Converters.Add(new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" });
opts.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()));
opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
if (Environment.GetEnvironmentVariable("DOTNET_WATCH") == "1")
{
mvc.AddRazorRuntimeCompilation();
}
services.Configure<IISOptions>(options =>
{
options.AutomaticAuthentication = false;
});
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// enable webpack middleware
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//app.UseDeveloperExceptionPage();
#pragma warning disable CS0618
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions()
{
HotModuleReplacement = true
});
#pragma warning restore CS0618
}
else
{
app.UseHsts();
}
app.UseStaticFiles();
app.UseRouting();
//app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
// routes for API
endpoints.MapControllerRoute(
name: "api",
pattern: "api/{controller=Index}/{action=Index}/{id?}"
);
// default routes
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Index}/{action=Index}/{id?}"
);
// fallbacks for SPA
endpoints.MapFallbackToController("Index", "Index");
});
}
}
+6 -5
View File
@@ -1,6 +1,7 @@
import Vue from 'vue'
import App from 'cmp/app.vue'
import 'filter/generic.js'
import 'directive/filedrop.js'
//import Vue from 'vue'
//import App from 'cmp/app.vue'
//import 'filter/generic.js'
//import 'directive/filedrop.js'
new Vue(App).$mount('#app');
//new Vue(App).$mount('#app');
console.info('hi');
+1 -8
View File
@@ -23,14 +23,7 @@ module.exports = {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': __dirname,
'api': path.join(__dirname, 'Api'),
'cmp': path.join(__dirname, 'Components'),
'store': path.join(__dirname, 'Utils'),
'utils': path.join(__dirname, 'Utils'),
'view': path.join(__dirname, 'Views'),
'filter': path.join(__dirname, 'Utils'),
'directive': path.join(__dirname, 'Utils')
'@': __dirname
}
},