You can register custom http handlers;
C#:
WebAPI.Register("/create_account", context =>
{
    // never reveal the secret key, this is used to prevent spoofing
    string secret = context.Request.Queries["secret"];

    if (secret != "A1B2C3D4E5F6") // this should really be stored in a config file and loaded, not distributed in source code...
    {
        context.Response.Status = HttpStatusCode.Unauthorized;
        return;
    }

    string username = context.Request.Queries["username"];
    string password = context.Request.Queries["password"];
    string email = context.Request.Queries["email"];

    IAccount account = Accounts.GetAccount(username);

    if (account != null)
    {
        context.Response.Status = HttpStatusCode.Conflict;
        return;
    }

    account = new Account(username, password);

    context.Response.Data = "SUCCESS";

    context.Response.Status = HttpStatusCode.OK;
});
Testing said:

The Wordpress account registration should be done with a form that targets a local php script to append the secret key and then forward the request to your shard's create_account endpoint (via cURL).
The secret key cannot be displayed anywhere to the end user, so you have to process things server-side.
 
Works fine!

Thanks!
private static void CSInvoke()
{
_ActivityTimer.Start();

// Mantém o registro original da rota "/"
Register("/", HandleRoot);

// Adiciona o registro da nova rota "/create_account"
Register("/create_account", context =>
{
// Nunca revele a chave secreta, isso é usado para prevenir falsificação
string secret = context.Request.Queries["secret"];

if (secret != "A1B2C3D4E5F6")
{
context.Response.Status = HttpStatusCode.Unauthorized;
return;
}

string username = context.Request.Queries["username"];
string password = context.Request.Queries["password"];
string email = context.Request.Queries["email"];

IAccount account = Accounts.GetAccount(username);

if (account != null)
{
context.Response.Status = HttpStatusCode.Conflict;
return;
}

account = new Account(username, password);

context.Response.Data = "SUCCESS";
context.Response.Status = HttpStatusCode.OK;
});
}
 
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back