Hello, I'm looking for how to connect my website made in WordPress so that players can create accounts from the website. And I don't know if I'm doing well here.Working in what way?
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:
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;
});
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.