diff --git a/Backend/EVABackend/EVABackend/Areas/Identity/IdentityHostingStartup.cs b/Backend/EVABackend/EVABackend/Areas/Identity/IdentityHostingStartup.cs index 4610acd..1b74950 100644 --- a/Backend/EVABackend/EVABackend/Areas/Identity/IdentityHostingStartup.cs +++ b/Backend/EVABackend/EVABackend/Areas/Identity/IdentityHostingStartup.cs @@ -1,12 +1,10 @@ using EVABackend.Areas.Identity.Data; using EVABackend.Models; -using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using System; [assembly: HostingStartup(typeof(EVABackend.Areas.Identity.IdentityHostingStartup))] namespace EVABackend.Areas.Identity @@ -18,10 +16,9 @@ namespace EVABackend.Areas.Identity builder.ConfigureServices((context, services) => { services.AddDbContext(options => - options.UseSqlite( - context.Configuration.GetConnectionString("EVABackendIdentityContextConnection"))); + options.UseSqlite(context.Configuration.GetConnectionString("EVABackendIdentityContextConnection"))); - services.AddDefaultIdentity() + services.AddIdentity() .AddRoles() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); @@ -29,6 +26,9 @@ namespace EVABackend.Areas.Identity services.ConfigureApplicationCookie(options => { options.Cookie.Name = "EVABackend_Token"; + options.LoginPath = $"/unauthorized"; + options.LogoutPath = $"/unauthorized"; + options.AccessDeniedPath = $"/unauthorized"; }); }); } diff --git a/Backend/EVABackend/EVABackend/Controllers/EVAController.cs b/Backend/EVABackend/EVABackend/Controllers/EVAController.cs index 8f2be76..b44185e 100644 --- a/Backend/EVABackend/EVABackend/Controllers/EVAController.cs +++ b/Backend/EVABackend/EVABackend/Controllers/EVAController.cs @@ -32,7 +32,27 @@ namespace EVABackend.Controllers [AllowAnonymous] public ActionResult Login() { - return Ok(new { status = "Nicht unterstützt" }); + return StatusCode(404, new { status = "Nicht unerstützt" }); + } + + [HttpGet] + [Route("unauthorized")] + [AllowAnonymous] + public ActionResult GetUnauthorized() + { + return StatusCode(401, new { status = "401 - Unauthorized" }); + } + +#if DEBUG + [HttpGet] + [Route("login_test")] + [AllowAnonymous] + public async Task LoginTest() + { + var user = await _userManager.FindByNameAsync("Test"); + await _signInManager.SignInAsync(user, true); + + return Ok(new { status = "Eingeloggt als Test" }); } [HttpGet] @@ -42,7 +62,6 @@ namespace EVABackend.Controllers { if (_userManager.FindByNameAsync("Test") == null) { - var user = new EVABackendUser { UserName = "Test", @@ -66,6 +85,7 @@ namespace EVABackend.Controllers return Ok(); } +#endif [HttpPost] [Route("login")] @@ -78,15 +98,18 @@ namespace EVABackend.Controllers return Ok(); } - return Unauthorized(); + return GetUnauthorized(); } [HttpPost] +#if DEBUG + [HttpGet] +#endif [Route("logout")] [Authorize] public async Task Logout() { - await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); + await _signInManager.SignOutAsync(); return Ok(); } @@ -146,7 +169,7 @@ namespace EVABackend.Controllers await _context.SaveChangesAsync(); antrag.Instrumente = instrumente.Select(i => new AntragInstrument { AntragId = antrag.Id, InstrumentId = i.Id }).ToList(); - + await _context.SaveChangesAsync(); return Ok(); @@ -172,7 +195,7 @@ namespace EVABackend.Controllers var model = rooms.Select(r => new { RaumID = r.Id, - RaumName= r.Name, + RaumName = r.Name, Instrumente = r.Instrumente.Select(i => new { InstrumentID = i.InstrumentId, @@ -188,7 +211,7 @@ namespace EVABackend.Controllers [Authorize(Roles = "Verwaltung")] public async Task CreateRooms(CreateRooms model) { - + throw new System.NotImplementedException(); } } } diff --git a/Backend/EVABackend/EVABackend/Startup.cs b/Backend/EVABackend/EVABackend/Startup.cs index f68d70a..5472cc9 100644 --- a/Backend/EVABackend/EVABackend/Startup.cs +++ b/Backend/EVABackend/EVABackend/Startup.cs @@ -1,7 +1,5 @@ -using EVABackend.Areas.Identity.Data; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -33,11 +31,11 @@ namespace EVABackend else { app.UseHsts(); + app.UseHttpsRedirection(); } app.UseStaticFiles(); app.UseAuthentication(); - app.UseHttpsRedirection(); app.UseMvc(); } } diff --git a/Backend/EVABackend/EVABackend/eva_users.db b/Backend/EVABackend/EVABackend/eva_users.db index 0609774..32663f9 100644 Binary files a/Backend/EVABackend/EVABackend/eva_users.db and b/Backend/EVABackend/EVABackend/eva_users.db differ