Skip to content

Instantly share code, notes, and snippets.

View jpd21122012's full-sized avatar
:octocat:

Ing. Jorge Perales Díaz jpd21122012

:octocat:
View GitHub Profile
// In your Maui app's login service
public async Task<bool> LoginAsync(string username)
{
// 1. Request a challenge from the server for this user
string challenge = await _apiService.GetLoginChallengeAsync(username);
// 2. Load the user's private key from secure storage
string privateKeyBase64 = await SecureStorage.GetAsync("user_privateKey");
byte[] privateKeyBytes = Convert.FromBase64String(privateKeyBase64);
// In your ASP.NET Core API Controller
[HttpPost("register")]
public async Task<IActionResult> Register([FromBody] UserRegistrationRequest request)
{
// In a real app, add validation, check for existing user, etc.
var newUser = new User
{
Username = request.Username,
// Store the user's public key for future verification
PublicKey = request.PublicKeyBase64,
public void OnRegisterButtonClicked(string username)
{
// Create a new key pair using the Ed25519 signature algorithm
var algorithm = SignatureAlgorithm.Ed25519;
var creationParameters = new KeyCreationParameters
{
ExportPolicy = KeyExportPolicies.AllowPlaintextArchiving
};
// This is the user's SECRET. Store this securely!
MyMauiAiApp/
├── Services/
│ ├── IAIService.cs
│ └── OpenAIService.cs
├── Utilities/
│ └── JsonToXamlConverter.cs
├── Models/
│ └── UISchema.cs
├── Views/
│ └── MainPage.xaml
private async void OnGenerateClicked(object sender, EventArgs e)
{
try
{
// 1. Get the user's prompt
string userDescription = PromptEditor.Text;
if (string.IsNullOrWhiteSpace(userDescription))
return;
<ScrollView>
<VerticalStackLayout Spacing="20" Padding="20">
<Label Text="AI UI Generator" FontSize="Title" HorizontalOptions="Center" />
<Editor x:Name="PromptEditor"
HeightRequest="150"
Placeholder="Describe your interface... E.g., 'A login page with a logo, two entries, and a blue button'" />
<Button Text="Generate XAML" Clicked="OnGenerateClicked" />
<Editor x:Name="XamlOutput"
HeightRequest="300"
IsReadOnly="True"
using Newtonsoft.Json;
using System.Text;
public static class JsonToXamlConverter
{
public static string Convert(string jsonInput)
{
try
{
// 1. Deserialize JSON into strongly-typed C# classes
public interface IAIService
{
Task<string> GenerateUIJsonAsync(string userPrompt);
}
public class OpenAIService : IAIService
{
private readonly OpenAIClient _client;
private const string _model = "gpt-4o"; // or "gpt-3.5-turbo"
// In MauiProgram.cs or a Service Factory
services.AddSingleton<IAIService>(new OpenAIService("your-openai-api-key"));
You are an assistant specialized in generating user interface schemas for .NET MAUI in JSON format.
The user will describe a screen, and you must generate a valid JSON object that represents it.
**Rules:**
1. **Respond only with the raw JSON object, no commentary, markdown, or extra text.**
2. **JSON Structure:**
- Use the schema provided below.
- Control types must be valid .NET MAUI types (e.g., 'VerticalStackLayout', 'Button', 'Label').
- All property values must be strings.