generated from karsten.jeppesen/KAJE-Template
Added RBAC and Insert
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
@if (Model.theScene.role == "error")
|
@if (Model.theScene.role == "error")
|
||||||
{
|
{
|
||||||
<h2>Vælg project</h2>
|
<h2 style="color: white">Choose Project Type</h2>
|
||||||
<form class="form-horizontal" method="post">
|
<form class="form-horizontal" method="post">
|
||||||
<select id="role" name="role" onchange="javascript:this.form.submit()">
|
<select id="role" name="role" onchange="javascript:this.form.submit()">
|
||||||
<option value="error">---</option>
|
<option value="error">---</option>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace Agent86.Pages
|
namespace Agent86.Pages
|
||||||
{
|
{
|
||||||
[Authorize(Roles = "user,teacher")]
|
[Authorize(Roles = "user,owner,teacher")]
|
||||||
public class IndexModel : PageModel
|
public class IndexModel : PageModel
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -22,11 +22,12 @@ namespace Agent86.Pages
|
|||||||
|
|
||||||
[BindProperty]
|
[BindProperty]
|
||||||
public string UserInput { get; set; }
|
public string UserInput { get; set; }
|
||||||
|
|
||||||
[BindProperty]
|
[BindProperty]
|
||||||
public Scene theScene { get; set; } = new();
|
public Scene theScene { get; set; } = new();
|
||||||
[BindProperty]
|
[BindProperty]
|
||||||
public List<Scene> Scenes { get; set; } = new();
|
public List<Scene> Scenes { get; set; } = new();
|
||||||
|
[BindProperty]
|
||||||
|
public string myRole { get; set; }
|
||||||
|
|
||||||
public List<ChatMessage> ChatHistory { get; set; } = new();
|
public List<ChatMessage> ChatHistory { get; set; } = new();
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ namespace Agent86.Pages
|
|||||||
public void OnGet()
|
public void OnGet()
|
||||||
{
|
{
|
||||||
LoadHistory();
|
LoadHistory();
|
||||||
|
myRole= User.Claims.FirstOrDefault(c => c.Type == "roles")?.Value;
|
||||||
if (theScene.role == "error")
|
if (theScene.role == "error")
|
||||||
{
|
{
|
||||||
// Handle the case where the scene role is not set
|
// Handle the case where the scene role is not set
|
||||||
|
|||||||
43
Agent86/Agent86/Pages/Insert.cshtml
Normal file
43
Agent86/Agent86/Pages/Insert.cshtml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
@page
|
||||||
|
@model Agent86.Pages.InsertModel
|
||||||
|
|
||||||
|
@if (Model.myRole == "teacher" || Model.myRole == "developer" || Model.myRole == "owner")
|
||||||
|
{
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h2 style="color:white">Insert New Project</h2>
|
||||||
|
<form class="form-horizontal" method="post">
|
||||||
|
<input type="hidden" name="action" value="insert" />
|
||||||
|
<label for="projectName" style="background-color: white">Project Name:</label><br />
|
||||||
|
<input type="text" id="projectName" name="projectName" required /><br /><br />
|
||||||
|
<label for="quest" style="background-color: white">Quest:</label><br />
|
||||||
|
<input type="text" id="quest" name="quest" required /><br /><br />
|
||||||
|
<label for="member" style="background-color: white">Your role:</label><br />
|
||||||
|
<input type="text" id="member" name="member" value="Team Member" /><br /><br />
|
||||||
|
<label for="customer" style="background-color: white">Customer:</label><br />
|
||||||
|
<input type="text" id="customer" name="customer" required /><br /><br />
|
||||||
|
<label for="instruction" style="background-color: white">Instruction:</label><br />
|
||||||
|
<textarea id="instruction" name="instruction" rows="10" cols="80" required></textarea><br /><br />
|
||||||
|
<button type="submit">Insert Project</button>
|
||||||
|
</form>
|
||||||
|
<br /> <br /> <br />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3 style="color:white">Suggested AI template</h3>
|
||||||
|
<p style="background-color: white">
|
||||||
|
I made a roleplay AI agent to allow my compter science students to have a simulated customer to converse with for a code project.<br/>
|
||||||
|
I need examples of the system prompt to guide the AI in behaving like a customer who wants an online sales site.<br />
|
||||||
|
The customer, named Anita Bath, is a head hunter selling human heads to savages.<br />
|
||||||
|
Quality criterias like shrunk, skin color, missing eye(s) or ear(s), mounted on poles or not, you may be creative even funny<br />
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<h2 style="color: red;">Access Denied</h2>
|
||||||
|
<p>You do not have permission to access this page.</p>
|
||||||
|
}
|
||||||
42
Agent86/Agent86/Pages/Insert.cshtml.cs
Normal file
42
Agent86/Agent86/Pages/Insert.cshtml.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using Agent86.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace Agent86.Pages
|
||||||
|
{
|
||||||
|
public class InsertModel : PageModel
|
||||||
|
{
|
||||||
|
[BindProperty]
|
||||||
|
public string myRole { get; set; }
|
||||||
|
[BindProperty]
|
||||||
|
public List<Scene> Scenes { get; set; } = new();
|
||||||
|
[BindProperty]
|
||||||
|
public Scene theScene { get; set; } = new();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
myRole = User.Claims.FirstOrDefault(c => c.Type == "roles")?.Value;
|
||||||
|
if (theScene.role == "error")
|
||||||
|
{
|
||||||
|
// Handle the case where the scene role is not set
|
||||||
|
Scenes = [.. new Persistence.DbOps().GetScenes().OrderBy(s => s.role)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult OnPost(string action = "error", string projectName = "error", string quest = "error", string member = "error", string customer = "error", string instruction = "error")
|
||||||
|
{
|
||||||
|
myRole = User.Claims.FirstOrDefault(c => c.Type == "roles")?.Value;
|
||||||
|
if (myRole == "teacher" || myRole == "owner")
|
||||||
|
{
|
||||||
|
if (action == "insert")
|
||||||
|
{
|
||||||
|
new Persistence.DbOps().InsertScene(projectName, quest, member, customer, instruction);
|
||||||
|
}
|
||||||
|
return RedirectToPage("/Index");
|
||||||
|
}
|
||||||
|
return RedirectToPage("/Index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,9 +20,12 @@
|
|||||||
</button>
|
</button>
|
||||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||||
<ul class="navbar-nav flex-grow-1">
|
<ul class="navbar-nav flex-grow-1">
|
||||||
<li class="nav-item">
|
@if (Model.myRole == "teacher" || Model.myRole == "developer" || Model.myRole == "owner")
|
||||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
{
|
||||||
</li>
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-page="/Insert">Insert</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -57,6 +57,15 @@ namespace Agent86.Persistence
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InsertScene(string projectName, string quest, string member, string customer, string instruction)
|
||||||
|
{
|
||||||
|
using (var myDbConnection = new MySqlConnection(GetConnectionString()))
|
||||||
|
{
|
||||||
|
CreateIfNotExist(myDbConnection);
|
||||||
|
myDbConnection.Execute("INSERT INTO Scene (role, quest, me, customer, instruction) VALUES (@projectName, @quest, @member, @customer, @instruction)", new { projectName, quest, member, customer, instruction });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Operations
|
#endregion Operations
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user