Setup.json password usage
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -305,18 +305,19 @@ namespace Aberwyn.Controllers
|
||||
existing.Title = task.Title;
|
||||
existing.Status = task.Status;
|
||||
existing.Priority = task.Priority;
|
||||
existing.Description = task.Description;
|
||||
existing.Tags = task.Tags;
|
||||
existing.AssignedTo = task.AssignedTo;
|
||||
existing.IsArchived = task.IsArchived;
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class AdminUserViewModel
|
||||
public class AdminUserViewModel
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Aberwyn.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Aberwyn.Data
|
||||
{
|
||||
@@ -10,47 +12,59 @@ namespace Aberwyn.Data
|
||||
{
|
||||
public ApplicationDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var basePath = Directory.GetCurrentDirectory();
|
||||
var config = new ConfigurationBuilder()
|
||||
.SetBasePath(basePath)
|
||||
.AddJsonFile("appsettings.json", optional: false)
|
||||
.AddJsonFile("appsettings.Development.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
var setup = LoadSetup();
|
||||
|
||||
var connectionString = config.GetConnectionString("DefaultConnection");
|
||||
|
||||
File.WriteAllText("connection-log.txt", $"Connection string: {connectionString}");
|
||||
Console.WriteLine($"Anslutningssträng: {connectionString}");
|
||||
|
||||
if (string.IsNullOrEmpty(connectionString))
|
||||
var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder
|
||||
{
|
||||
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
|
||||
}
|
||||
Server = setup.DbHost,
|
||||
Port = (uint)setup.DbPort,
|
||||
Database = setup.DbName,
|
||||
UserID = setup.DbUser,
|
||||
Password = setup.DbPassword,
|
||||
AllowUserVariables = true
|
||||
};
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||
optionsBuilder.UseMySql(
|
||||
connectionString,
|
||||
new MySqlServerVersion(new Version(8, 0, 36)));
|
||||
optionsBuilder.UseMySql(csBuilder.ConnectionString, new MySqlServerVersion(new Version(8, 0, 36)));
|
||||
|
||||
return new ApplicationDbContext(optionsBuilder.Options);
|
||||
}
|
||||
|
||||
public static ApplicationDbContext CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false)
|
||||
{
|
||||
var connectionString = useProdDb
|
||||
? config.GetConnectionString("ProdConnection") // <--- FIX HÄR
|
||||
: config.GetConnectionString("DefaultConnection");
|
||||
var setup = LoadSetup();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(connectionString))
|
||||
throw new InvalidOperationException("Connection string saknas.");
|
||||
var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder
|
||||
{
|
||||
Server = setup.DbHost,
|
||||
Port = (uint)setup.DbPort,
|
||||
Database = setup.DbName,
|
||||
UserID = setup.DbUser,
|
||||
Password = setup.DbPassword,
|
||||
AllowUserVariables = true
|
||||
};
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||
optionsBuilder.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 36)));
|
||||
optionsBuilder.UseMySql(csBuilder.ConnectionString, new MySqlServerVersion(new Version(8, 0, 36)));
|
||||
|
||||
return new ApplicationDbContext(optionsBuilder.Options);
|
||||
}
|
||||
|
||||
private static SetupSettings LoadSetup()
|
||||
{
|
||||
var basePath = Directory.GetCurrentDirectory();
|
||||
var setupPath = Path.Combine(basePath, "infrastructure", "setup.json");
|
||||
|
||||
if (!File.Exists(setupPath))
|
||||
throw new FileNotFoundException("setup.json saknas i infrastructure-mappen.");
|
||||
|
||||
var json = File.ReadAllText(setupPath);
|
||||
var setup = JsonSerializer.Deserialize<SetupSettings>(json);
|
||||
|
||||
if (setup == null || !setup.IsConfigured)
|
||||
throw new InvalidOperationException("setup.json är inte korrekt konfigurerad.");
|
||||
|
||||
return setup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,38 @@ public class MenuService
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// Detta är en alternativ konstruktör – används manuellt vid t.ex. import
|
||||
public static MenuService CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false)
|
||||
{
|
||||
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||
// Detta är en alternativ konstruktör – används manuellt vid t.ex. import
|
||||
public static MenuService CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false)
|
||||
{
|
||||
var basePath = env.ContentRootPath ?? Directory.GetCurrentDirectory();
|
||||
var setupPath = Path.Combine(basePath, "infrastructure", "setup.json");
|
||||
|
||||
var connStr = useProdDb
|
||||
? config.GetConnectionString("ProdConnection")
|
||||
: config.GetConnectionString("DefaultConnection");
|
||||
if (!File.Exists(setupPath))
|
||||
throw new FileNotFoundException("setup.json saknas i infrastructure/");
|
||||
|
||||
builder.UseMySql(connStr, ServerVersion.AutoDetect(connStr));
|
||||
var context = new ApplicationDbContext(builder.Options);
|
||||
var setupJson = File.ReadAllText(setupPath);
|
||||
var setup = System.Text.Json.JsonSerializer.Deserialize<SetupSettings>(setupJson)!;
|
||||
|
||||
if (!setup.IsConfigured || string.IsNullOrWhiteSpace(setup.DbPassword))
|
||||
throw new InvalidOperationException("setup.json är ofullständig.");
|
||||
|
||||
var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder
|
||||
{
|
||||
Server = setup.DbHost,
|
||||
Port = (uint)setup.DbPort,
|
||||
Database = setup.DbName,
|
||||
UserID = setup.DbUser,
|
||||
Password = setup.DbPassword,
|
||||
AllowUserVariables = true
|
||||
};
|
||||
|
||||
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||
builder.UseMySql(csBuilder.ConnectionString, ServerVersion.AutoDetect(csBuilder.ConnectionString));
|
||||
|
||||
var context = new ApplicationDbContext(builder.Options);
|
||||
return new MenuService(context);
|
||||
}
|
||||
|
||||
return new MenuService(context);
|
||||
}
|
||||
public void UpdateWeeklyMenu(MenuViewModel model)
|
||||
{
|
||||
var existing = _context.WeeklyMenus
|
||||
|
||||
@@ -80,8 +80,19 @@
|
||||
<div class="todo-task {{ PriorityClass(task.Priority) }}"
|
||||
ng-repeat="task in FilteredTasks(col.Id) track by task.Id"
|
||||
draggable-task
|
||||
task="task">
|
||||
{{ task.Title }}
|
||||
task="task"
|
||||
ng-if="!task.IsArchived">
|
||||
|
||||
<strong>{{ task.Title }}</strong>
|
||||
|
||||
<div>
|
||||
<small>👤 {{ task.AssignedTo || 'Ingen' }}</small><br />
|
||||
<small>🏷️ {{ task.Tags }}</small><br />
|
||||
<small>📅 {{ task.CreatedAt | date:'yyyy-MM-dd HH:mm' }}</small>
|
||||
</div>
|
||||
|
||||
<p ng-if="task.Description">{{ task.Description }}</p>
|
||||
|
||||
<div>
|
||||
<small>Prioritet:
|
||||
<select ng-model="task.Priority" ng-change="UpdatePriority(task)">
|
||||
@@ -93,8 +104,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-if="col.Id === 'ideas'">
|
||||
<input type="text" ng-model="NewTask.Title" placeholder="Ny idé..." />
|
||||
<input type="text" ng-model="NewTask.AssignedTo" placeholder="Tilldelad till..." />
|
||||
<input type="text" ng-model="NewTask.Tags" placeholder="Taggar (komma-separerat)" />
|
||||
<textarea ng-model="NewTask.Description" placeholder="Beskrivning"></textarea>
|
||||
<select ng-model="NewTask.Priority">
|
||||
<option value="1">Låg</option>
|
||||
<option value="2">Medel</option>
|
||||
@@ -102,6 +117,7 @@
|
||||
</select>
|
||||
<button type="button" ng-click="AddTask()">Lägg till</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user