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.Title = task.Title;
|
||||||
existing.Status = task.Status;
|
existing.Status = task.Status;
|
||||||
existing.Priority = task.Priority;
|
existing.Priority = task.Priority;
|
||||||
|
existing.Description = task.Description;
|
||||||
|
existing.Tags = task.Tags;
|
||||||
|
existing.AssignedTo = task.AssignedTo;
|
||||||
|
existing.IsArchived = task.IsArchived;
|
||||||
|
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AdminUserViewModel
|
public class AdminUserViewModel
|
||||||
{
|
{
|
||||||
public string UserId { get; set; }
|
public string UserId { get; set; }
|
||||||
public string Email { 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.EntityFrameworkCore.Design;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Aberwyn.Data
|
namespace Aberwyn.Data
|
||||||
{
|
{
|
||||||
@@ -10,47 +12,59 @@ namespace Aberwyn.Data
|
|||||||
{
|
{
|
||||||
public ApplicationDbContext CreateDbContext(string[] args)
|
public ApplicationDbContext CreateDbContext(string[] args)
|
||||||
{
|
{
|
||||||
var basePath = Directory.GetCurrentDirectory();
|
var setup = LoadSetup();
|
||||||
var config = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(basePath)
|
|
||||||
.AddJsonFile("appsettings.json", optional: false)
|
|
||||||
.AddJsonFile("appsettings.Development.json", optional: true)
|
|
||||||
.AddEnvironmentVariables()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
var connectionString = config.GetConnectionString("DefaultConnection");
|
var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder
|
||||||
|
|
||||||
File.WriteAllText("connection-log.txt", $"Connection string: {connectionString}");
|
|
||||||
Console.WriteLine($"Anslutningssträng: {connectionString}");
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(connectionString))
|
|
||||||
{
|
{
|
||||||
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>();
|
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||||
optionsBuilder.UseMySql(
|
optionsBuilder.UseMySql(csBuilder.ConnectionString, new MySqlServerVersion(new Version(8, 0, 36)));
|
||||||
connectionString,
|
|
||||||
new MySqlServerVersion(new Version(8, 0, 36)));
|
|
||||||
|
|
||||||
return new ApplicationDbContext(optionsBuilder.Options);
|
return new ApplicationDbContext(optionsBuilder.Options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApplicationDbContext CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false)
|
public static ApplicationDbContext CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false)
|
||||||
{
|
{
|
||||||
var connectionString = useProdDb
|
var setup = LoadSetup();
|
||||||
? config.GetConnectionString("ProdConnection") // <--- FIX HÄR
|
|
||||||
: config.GetConnectionString("DefaultConnection");
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(connectionString))
|
var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder
|
||||||
throw new InvalidOperationException("Connection string saknas.");
|
{
|
||||||
|
Server = setup.DbHost,
|
||||||
|
Port = (uint)setup.DbPort,
|
||||||
|
Database = setup.DbName,
|
||||||
|
UserID = setup.DbUser,
|
||||||
|
Password = setup.DbPassword,
|
||||||
|
AllowUserVariables = true
|
||||||
|
};
|
||||||
|
|
||||||
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
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);
|
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;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detta är en alternativ konstruktör – används manuellt vid t.ex. import
|
// Detta är en alternativ konstruktör – används manuellt vid t.ex. import
|
||||||
public static MenuService CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false)
|
public static MenuService CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false)
|
||||||
{
|
{
|
||||||
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
var basePath = env.ContentRootPath ?? Directory.GetCurrentDirectory();
|
||||||
|
var setupPath = Path.Combine(basePath, "infrastructure", "setup.json");
|
||||||
|
|
||||||
var connStr = useProdDb
|
if (!File.Exists(setupPath))
|
||||||
? config.GetConnectionString("ProdConnection")
|
throw new FileNotFoundException("setup.json saknas i infrastructure/");
|
||||||
: config.GetConnectionString("DefaultConnection");
|
|
||||||
|
|
||||||
builder.UseMySql(connStr, ServerVersion.AutoDetect(connStr));
|
var setupJson = File.ReadAllText(setupPath);
|
||||||
var context = new ApplicationDbContext(builder.Options);
|
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)
|
public void UpdateWeeklyMenu(MenuViewModel model)
|
||||||
{
|
{
|
||||||
var existing = _context.WeeklyMenus
|
var existing = _context.WeeklyMenus
|
||||||
|
|||||||
@@ -80,8 +80,19 @@
|
|||||||
<div class="todo-task {{ PriorityClass(task.Priority) }}"
|
<div class="todo-task {{ PriorityClass(task.Priority) }}"
|
||||||
ng-repeat="task in FilteredTasks(col.Id) track by task.Id"
|
ng-repeat="task in FilteredTasks(col.Id) track by task.Id"
|
||||||
draggable-task
|
draggable-task
|
||||||
task="task">
|
task="task"
|
||||||
{{ task.Title }}
|
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>
|
<div>
|
||||||
<small>Prioritet:
|
<small>Prioritet:
|
||||||
<select ng-model="task.Priority" ng-change="UpdatePriority(task)">
|
<select ng-model="task.Priority" ng-change="UpdatePriority(task)">
|
||||||
@@ -93,8 +104,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div ng-if="col.Id === 'ideas'">
|
<div ng-if="col.Id === 'ideas'">
|
||||||
<input type="text" ng-model="NewTask.Title" placeholder="Ny idé..." />
|
<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">
|
<select ng-model="NewTask.Priority">
|
||||||
<option value="1">Låg</option>
|
<option value="1">Låg</option>
|
||||||
<option value="2">Medel</option>
|
<option value="2">Medel</option>
|
||||||
@@ -102,6 +117,7 @@
|
|||||||
</select>
|
</select>
|
||||||
<button type="button" ng-click="AddTask()">Lägg till</button>
|
<button type="button" ng-click="AddTask()">Lägg till</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user