mirror of
https://github.com/matrix-construct/construct
synced 2025-03-13 21:10:32 +01:00
modules/console: Add an mc register cmd.
This commit is contained in:
parent
7531c4b07c
commit
1babba0e98
1 changed files with 90 additions and 0 deletions
|
@ -10804,6 +10804,96 @@ console_cmd__vm__eval(opt &out, const string_view &line)
|
|||
// mc
|
||||
//
|
||||
|
||||
bool
|
||||
console_cmd__mc__register(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"user_id", "password", "[remote]"
|
||||
}};
|
||||
|
||||
const m::user::id &user_id
|
||||
{
|
||||
param.at("user_id")
|
||||
};
|
||||
|
||||
const string_view &password
|
||||
{
|
||||
param.at("password")
|
||||
};
|
||||
|
||||
const net::hostport remote
|
||||
{
|
||||
param.at("[remote]", user_id.host())
|
||||
};
|
||||
|
||||
static const string_view uri
|
||||
{
|
||||
"/_matrix/client/r0/register?kind=user"
|
||||
};
|
||||
|
||||
server::request::opts sopts;
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
16_KiB
|
||||
};
|
||||
|
||||
window_buffer wb{buf};
|
||||
wb([&](mutable_buffer buf)
|
||||
{
|
||||
return json::stringify(buf, json::members
|
||||
{
|
||||
{ "username", user_id.localname() },
|
||||
{ "password", password },
|
||||
{ "auth", json::members
|
||||
{
|
||||
{ "type", "m.login.dummy" }
|
||||
}}
|
||||
});
|
||||
});
|
||||
|
||||
const string_view &content
|
||||
{
|
||||
wb.completed()
|
||||
};
|
||||
|
||||
wb = mutable_buffer{wb};
|
||||
http::request
|
||||
{
|
||||
wb, host(remote), "POST", uri, size(content), "application/json"
|
||||
};
|
||||
|
||||
server::out sout
|
||||
{
|
||||
wb.completed(), content
|
||||
};
|
||||
|
||||
server::in sin
|
||||
{
|
||||
mutable_buffer{wb}
|
||||
};
|
||||
|
||||
server::request request
|
||||
{
|
||||
remote, std::move(sout), std::move(sin)
|
||||
};
|
||||
|
||||
request.wait(out.timeout);
|
||||
const auto code
|
||||
{
|
||||
request.get()
|
||||
};
|
||||
|
||||
const json::object response
|
||||
{
|
||||
request.in.content
|
||||
};
|
||||
|
||||
out << uint(code) << ": " << std::endl;
|
||||
out << string_view{response} << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__mc__register__available(opt &out, const string_view &line)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue