Compare commits

..

No commits in common. 'c431b740aa74101aca25b56100cc57a6b6c699c1' and '640147f94ec0f818f2f9dfe72fc8d140827e24fa' have entirely different histories.

  1. 10
      Backend/EVABackend/EVABackend/Areas/Identity/IdentityHostingStartup.cs
  2. 39
      Backend/EVABackend/EVABackend/Controllers/EVAController.cs
  3. 2
      Backend/EVABackend/EVABackend/Dockerfile
  4. 5
      Backend/EVABackend/EVABackend/Startup.cs
  5. BIN
      Backend/EVABackend/EVABackend/eva_users.db

10
Backend/EVABackend/EVABackend/Areas/Identity/IdentityHostingStartup.cs

@ -1,10 +1,12 @@
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
@ -16,9 +18,10 @@ namespace EVABackend.Areas.Identity
builder.ConfigureServices((context, services) =>
{
services.AddDbContext<EVABackendIdentityContext>(options =>
options.UseSqlite(context.Configuration.GetConnectionString("EVABackendIdentityContextConnection")));
options.UseSqlite(
context.Configuration.GetConnectionString("EVABackendIdentityContextConnection")));
services.AddIdentity<EVABackendUser, IdentityRole>()
services.AddDefaultIdentity<EVABackendUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<EVABackendIdentityContext>()
.AddDefaultTokenProviders();
@ -26,9 +29,6 @@ namespace EVABackend.Areas.Identity
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = "EVABackend_Token";
options.LoginPath = $"/unauthorized";
options.LogoutPath = $"/unauthorized";
options.AccessDeniedPath = $"/unauthorized";
});
});
}

39
Backend/EVABackend/EVABackend/Controllers/EVAController.cs

@ -1,5 +1,7 @@
using EVABackend.Areas.Identity.Data;
using EVABackend.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
@ -30,27 +32,7 @@ namespace EVABackend.Controllers
[AllowAnonymous]
public ActionResult Login()
{
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<ActionResult> LoginTest()
{
var user = await _userManager.FindByNameAsync("Test");
await _signInManager.SignInAsync(user, true);
return Ok(new { status = "Eingeloggt als Test" });
return Ok(new { status = "Nicht unterstützt" });
}
[HttpGet]
@ -60,6 +42,7 @@ namespace EVABackend.Controllers
{
if (_userManager.FindByNameAsync("Test") == null)
{
var user = new EVABackendUser
{
UserName = "Test",
@ -83,7 +66,6 @@ namespace EVABackend.Controllers
return Ok();
}
#endif
[HttpPost]
[Route("login")]
@ -96,18 +78,15 @@ namespace EVABackend.Controllers
return Ok();
}
return GetUnauthorized();
return Unauthorized();
}
[HttpPost]
#if DEBUG
[HttpGet]
#endif
[Route("logout")]
[Authorize]
public async Task<ActionResult> Logout()
{
await _signInManager.SignOutAsync();
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return Ok();
}
@ -167,7 +146,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();
@ -193,7 +172,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,
@ -209,7 +188,7 @@ namespace EVABackend.Controllers
[Authorize(Roles = "Verwaltung")]
public async Task<ActionResult> CreateRooms(CreateRooms model)
{
throw new System.NotImplementedException();
}
}
}

2
Backend/EVABackend/EVABackend/Dockerfile

@ -5,7 +5,7 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["EVABackend/EVABackend.csproj", "EVABackend/"]
COPY ["EVABackend.csproj", "EVABackend/"]
RUN dotnet restore "EVABackend/EVABackend.csproj"
COPY . .
WORKDIR "/src/EVABackend"

5
Backend/EVABackend/EVABackend/Startup.cs

@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Builder;
using EVABackend.Areas.Identity.Data;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -35,6 +37,7 @@ namespace EVABackend
app.UseStaticFiles();
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc();
}
}

BIN
Backend/EVABackend/EVABackend/eva_users.db

Binary file not shown.
Loading…
Cancel
Save