Archived
Private
Public Access
1
0

Login finished

This commit is contained in:
2023-04-15 17:54:37 +02:00
parent 7165ce1ae3
commit 72f08fc9cb
25 changed files with 412 additions and 62 deletions

2
BetterIServ.Backend/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
bin
obj

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,42 @@
using System.Net;
using Microsoft.AspNetCore.Mvc;
namespace BetterIServ.Backend.Controllers;
[ApiController]
public class HelperController : Controller {
[HttpPost("/login")]
public async Task<ActionResult<string>> Login([FromForm] string email, [FromForm] string password) {
try {
using var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AllowAutoRedirect = false }) { Timeout = TimeSpan.FromSeconds(5) };
var split = email.Split("@");
var username = split[0];
var domain = split[1];
var form = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("_username", username),
new KeyValuePair<string, string>("_password", password)
});
var request = new HttpRequestMessage {
RequestUri = new Uri($"https://{domain}/iserv/auth/login"),
Method = HttpMethod.Post,
Content = form
};
var response = await client.SendAsync(request);
var header = response.Headers.GetValues("Set-Cookie").First();
var part = header.Split(";")[0];
if (!part.Contains("IServAuthSession")) throw new Exception();
return Ok(part.Replace("IServAuthSession=", ""));
}
catch (Exception e) {
return Unauthorized();
}
}
}

View File

@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["BetterIServ.Backend/BetterIServ.Backend.csproj", "BetterIServ.Backend/"]
RUN dotnet restore "BetterIServ.Backend/BetterIServ.Backend.csproj"
COPY . .
WORKDIR "/src/BetterIServ.Backend"
RUN dotnet build "BetterIServ.Backend.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "BetterIServ.Backend.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BetterIServ.Backend.dll"]

View File

@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Cors.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors(options => {
options.WithOrigins("http://localhost:8100");
options.AllowCredentials();
});
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49668",
"sslPort": 44383
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5273",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7147;http://localhost:5273",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}