mirror of
https://github.com/matrix-construct/construct
synced 2024-11-18 16:00:57 +01:00
84 lines
2 KiB
C++
84 lines
2 KiB
C++
// Matrix Construct
|
|
//
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
using namespace ircd;
|
|
|
|
mapi::header
|
|
IRCD_MODULE
|
|
{
|
|
"Client 3.4.1 :Register Available"
|
|
};
|
|
|
|
static resource::response
|
|
get__register_available(client &client, const resource::request &request);
|
|
|
|
resource
|
|
register_available_resource
|
|
{
|
|
"/_matrix/client/r0/register/available",
|
|
{
|
|
"(5.5.8) Checks to see if a username is available and valid for the server."
|
|
}
|
|
};
|
|
|
|
resource::method
|
|
method_get
|
|
{
|
|
register_available_resource, "GET", get__register_available
|
|
};
|
|
|
|
mods::import<void (const m::id::user &)>
|
|
validate_user_id
|
|
{
|
|
"client_register", "validate_user_id"
|
|
};
|
|
|
|
mods::import<ircd::conf::item<bool>>
|
|
register_enable
|
|
{
|
|
"client_register", "register_enable"
|
|
};
|
|
|
|
mods::import<ircd::conf::item<bool>>
|
|
register_user_enable
|
|
{
|
|
"client_register", "register_user_enable"
|
|
};
|
|
|
|
resource::response
|
|
get__register_available(client &client,
|
|
const resource::request &request)
|
|
{
|
|
if(!bool(register_enable) || !bool(register_user_enable))
|
|
throw m::error
|
|
{
|
|
http::FORBIDDEN, "M_REGISTRATION_DISABLED",
|
|
"Registration is disabled. No username is available."
|
|
};
|
|
|
|
// The successful construction of this m::user::id implies valid
|
|
// formatting otherwise an m::INVALID_MXID (400) is thrown.
|
|
m::user::id::buf user_id
|
|
{
|
|
url::decode(user_id, request.query.at("username")), my_host()
|
|
};
|
|
|
|
// Performs additional custom checks on the user_id else throws.
|
|
validate_user_id(user_id);
|
|
|
|
// We indicate availability of a valid mxid in the cacheable 200 OK
|
|
return resource::response
|
|
{
|
|
client, json::members
|
|
{
|
|
{ "available", !m::exists(user_id) }
|
|
}
|
|
};
|
|
}
|