Profil-Seite: Anzeigename, Passwort ändern, Persona (ersetzt USER.md)
- Neuer Menüpunkt 'Mein Profil' statt 'Logout' - Profil-Page: Anzeigename, Persona (Freitext), Passwort ändern, Logout - ProfileEndpoint: GET/PUT /api/profile, PUT /api/profile/password - User-Persona im System-Prompt statt USER.md (Fallback: Anzeigename/Username) - SystemPromptBuilder: dataDir-Parameter entfernt, userPersona-Parameter hinzugefügt - DB-Migration: persona-Spalte in users-Tabelle
This commit is contained in:
1 parent
f49c526384
commit
7149904ae4
12 files changed
+341
-26
No files matched your search
@@ -82,9 +82,9 @@ public static class ChatEndpoint
|
||||
|
||||
var markedMessages = await db.GetMarkedMessages(sessionId);
|
||||
var agentMemoryDir = memoryService.GetAgentMemoryDir(agent.AgentId);
|
||||
var dataDir = memoryService.DataDir;
|
||||
var agentSkills = await db.GetAgentSkills(agent.AgentId);
|
||||
var systemPromptText = SystemPromptBuilder.Build(agent, session, markedMessages, memoryService, agentMemoryDir, dataDir, agentSkills, skillService);
|
||||
var user = await db.GetUser(userId);
|
||||
var systemPromptText = SystemPromptBuilder.Build(agent, session, markedMessages, memoryService, agentMemoryDir, agentSkills, skillService, userPersona: user?.GetEffectivePersona());
|
||||
|
||||
var chainId = Guid.NewGuid().ToString("N");
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
using System.Text.Json;
|
||||
using Gott.Extensions;
|
||||
using Gott.Services;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Gott.Endpoints;
|
||||
|
||||
public static class ProfileEndpoint
|
||||
{
|
||||
public static void MapProfileEndpoints(this WebApplication app)
|
||||
{
|
||||
app.MapGet("/api/profile", HandleGet);
|
||||
app.MapPut("/api/profile", HandleUpdate);
|
||||
app.MapPut("/api/profile/password", HandlePasswordChange);
|
||||
}
|
||||
|
||||
private static async System.Threading.Tasks.Task HandleGet(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var userId = ctx.GetUserId();
|
||||
var user = await db.GetUser(userId);
|
||||
if (user == null)
|
||||
{
|
||||
ctx.Response.StatusCode = 404;
|
||||
await ctx.Response.WriteAsJsonAsync(new { error = "User not found" });
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.Response.WriteAsJsonAsync(new
|
||||
{
|
||||
userId = user.UserId,
|
||||
username = user.Username,
|
||||
displayName = user.DisplayName,
|
||||
persona = user.Persona,
|
||||
isAdmin = user.IsAdmin
|
||||
});
|
||||
}
|
||||
|
||||
private static async System.Threading.Tasks.Task HandleUpdate(HttpContext ctx, DatabaseService db)
|
||||
{
|
||||
var userId = ctx.GetUserId();
|
||||
var body = await JsonSerializer.DeserializeAsync<JsonElement>(ctx.Request.Body);
|
||||
|
||||
var displayName = body.TryGetProperty("displayName", out var dn) ? dn.GetString() : null;
|
||||
var persona = body.TryGetProperty("persona", out var p) ? p.GetString() : null;
|
||||
|
||||
await db.UpdateUserProfile(userId, displayName, persona);
|
||||
|
||||
var user = await db.GetUser(userId);
|
||||
await ctx.Response.WriteAsJsonAsync(new
|
||||
{
|
||||
userId = user.UserId,
|
||||
username = user.Username,
|
||||
displayName = user.DisplayName,
|
||||
persona = user.Persona,
|
||||
isAdmin = user.IsAdmin
|
||||
});
|
||||
}
|
||||
|
||||
private static async System.Threading.Tasks.Task HandlePasswordChange(HttpContext ctx, DatabaseService db, AuthService auth)
|
||||
{
|
||||
var userId = ctx.GetUserId();
|
||||
var body = await JsonSerializer.DeserializeAsync<JsonElement>(ctx.Request.Body);
|
||||
|
||||
var currentPassword = body.TryGetProperty("currentPassword", out var cp) ? cp.GetString() : null;
|
||||
var newPassword = body.TryGetProperty("newPassword", out var np) ? np.GetString() : null;
|
||||
|
||||
if (string.IsNullOrEmpty(currentPassword) || string.IsNullOrEmpty(newPassword))
|
||||
{
|
||||
ctx.Response.StatusCode = 400;
|
||||
await ctx.Response.WriteAsJsonAsync(new { error = "Aktuelles und neues Passwort erforderlich" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword.Length < 4)
|
||||
{
|
||||
ctx.Response.StatusCode = 400;
|
||||
await ctx.Response.WriteAsJsonAsync(new { error = "Passwort muss mindestens 4 Zeichen lang sein" });
|
||||
return;
|
||||
}
|
||||
|
||||
var user = await db.GetUser(userId);
|
||||
if (user == null || !auth.VerifyPassword(currentPassword, user.PasswordHash))
|
||||
{
|
||||
ctx.Response.StatusCode = 401;
|
||||
await ctx.Response.WriteAsJsonAsync(new { error = "Aktuelles Passwort ist falsch" });
|
||||
return;
|
||||
}
|
||||
|
||||
var newHash = auth.HashPassword(newPassword);
|
||||
await db.UpdateUserPassword(userId, newHash);
|
||||
|
||||
await ctx.Response.WriteAsJsonAsync(new { ok = true });
|
||||
}
|
||||
}
|
||||
@@ -139,9 +139,9 @@ public static class SessionEndpoint
|
||||
|
||||
var markedMessages = await db.GetMarkedMessages(sessionId);
|
||||
var agentMemoryDir = memoryService.GetAgentMemoryDir(agent.AgentId);
|
||||
var dataDir = memoryService.DataDir;
|
||||
var agentSkills = await db.GetAgentSkills(agent.AgentId);
|
||||
var systemPrompt = SystemPromptBuilder.Build(agent, session, markedMessages, memoryService, agentMemoryDir, dataDir, agentSkills, skillService);
|
||||
var user = await db.GetUser(userId);
|
||||
var systemPrompt = SystemPromptBuilder.Build(agent, session, markedMessages, memoryService, agentMemoryDir, agentSkills, skillService, userPersona: user?.GetEffectivePersona());
|
||||
|
||||
ctx.Response.ContentType = "text/plain; charset=utf-8";
|
||||
await ctx.Response.WriteAsync(systemPrompt);
|
||||
@@ -173,9 +173,9 @@ public static class SessionEndpoint
|
||||
|
||||
var markedMessages = await db.GetMarkedMessages(sessionId);
|
||||
var agentMemoryDir = memoryService.GetAgentMemoryDir(agent.AgentId);
|
||||
var dataDir = memoryService.DataDir;
|
||||
var agentSkills = await db.GetAgentSkills(agent.AgentId);
|
||||
var blocks = SystemPromptBuilder.BuildBlocks(agent, session, markedMessages, memoryService, agentMemoryDir, dataDir, agentSkills, skillService);
|
||||
var user = await db.GetUser(userId);
|
||||
var blocks = SystemPromptBuilder.BuildBlocks(agent, session, markedMessages, memoryService, agentMemoryDir, agentSkills, skillService, userPersona: user?.GetEffectivePersona());
|
||||
|
||||
await ctx.Response.WriteAsJsonAsync(blocks.Select(b => new { b.Icon, b.Label, b.Content }));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user