chore: adjust line endings, show git info

This commit is contained in:
2025-07-22 10:59:12 +02:00
parent b292586764
commit 0ec7bdf2fe
3 changed files with 67 additions and 61 deletions

View File

@@ -1,58 +1,60 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using QuotifyBE.Data; using QuotifyBE.Data;
using QuotifyBE.DTOs; using QuotifyBE.DTOs;
using QuotifyBE.Entities; using QuotifyBE.Entities;
using QuotifyBE.Mapping; using QuotifyBE.Mapping;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace QuotifyBE.Controllers namespace QuotifyBE.Controllers
{ {
public class Seed : Controller public class Seed : Controller
{ {
private readonly ApplicationDbContext _db; private readonly ApplicationDbContext _db;
private readonly GeneralUseHelpers guhf; private readonly GeneralUseHelpers guhf;
public Seed(ApplicationDbContext db, GeneralUseHelpers GUHF) public Seed(ApplicationDbContext db, GeneralUseHelpers GUHF)
{ {
_db = db; _db = db;
guhf = GUHF; guhf = GUHF;
} }
public async Task SeedAsync() public async Task SeedAsync()
{ {
// Create a user account if no exist Console.WriteLine($"You're running QuotifyBE, commit {ThisAssembly.Git.Commit} of branch {ThisAssembly.Git.Branch} ({ThisAssembly.Git.CommitDate})\n");
var AccountNum = await _db.Users.CountAsync();
if (AccountNum == 0) // Create a user account if no exist
{ var AccountNum = await _db.Users.CountAsync();
var Admin = new User if (AccountNum == 0)
{ {
Name="admin", var Admin = new User
Email = "admin@mail.com", {
// hashed twice, once by frontend, and second time by backend Name="admin",
PasswordHash = guhf.HashWithSHA512(guhf.HashWithSHA512("admin")), Email = "admin@mail.com",
Role = 0 // role 0 - greatest power, admin, role 0 > role 1 // hashed twice, once by frontend, and second time by backend
}; PasswordHash = guhf.HashWithSHA512(guhf.HashWithSHA512("admin")),
_db.Users.Add(Admin); Role = 0 // role 0 - greatest power, admin, role 0 > role 1
await _db.SaveChangesAsync(); };
Console.WriteLine("[QuotifyBE] Administrator user account added!\nDefault credentials are: admin@mail.com, password: admin"); _db.Users.Add(Admin);
} await _db.SaveChangesAsync();
Console.WriteLine("[QuotifyBE] Administrator user account added!\nDefault credentials are: admin@mail.com, password: admin");
// Create sitewide statistic - number of draws }
Statistic? numOfDraws = await _db.Statistics
.FirstOrDefaultAsync(s => s.Label == "number_of_draws"); // Create sitewide statistic - number of draws
if (numOfDraws == null) Statistic? numOfDraws = await _db.Statistics
{ .FirstOrDefaultAsync(s => s.Label == "number_of_draws");
Statistic newRow = new Statistic if (numOfDraws == null)
{ {
Label = "number_of_draws", Statistic newRow = new Statistic
IValue = 0 {
}; Label = "number_of_draws",
_db.Statistics.Add(newRow); IValue = 0
await _db.SaveChangesAsync(); };
Console.WriteLine("[QuotifyBE] Sitewide statistic for number of draws added!"); _db.Statistics.Add(newRow);
} await _db.SaveChangesAsync();
Console.WriteLine("[QuotifyBE] Sitewide statistic for number of draws added!");
} }
}
} }
}
}

View File

@@ -1,4 +1,4 @@
namespace QuotifyBE.Entities namespace QuotifyBE.Entities
{ {
public class Image public class Image
{ {

View File

@@ -7,12 +7,16 @@
<UserSecretsId>b302b0ab-745f-4b53-b32a-12fbbc3e622d</UserSecretsId> <UserSecretsId>b302b0ab-745f-4b53-b32a-12fbbc3e622d</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext> <DockerfileContext>.</DockerfileContext>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn> <NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="EntityFramework" Version="6.5.1" /> <PackageReference Include="EntityFramework" Version="6.5.1" />
<PackageReference Include="GitInfo" Version="3.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.18" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.18" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.18" /> <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.18" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.7" />