0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

modules/client: Implement the register/available endpoint.

This commit is contained in:
Jason Volk 2019-01-12 11:51:57 -08:00
parent f6e1311e21
commit 3a3dfe40d1
3 changed files with 68 additions and 1 deletions

View file

@ -162,6 +162,7 @@ client_client_publicised_groups_la_SOURCES = client/publicised_groups.cc
client_client_initialsync_la_SOURCES = client/initialsync.cc
client_client_search_la_SOURCES = client/search.cc
client_client_joined_groups_la_SOURCES = client/joined_groups.cc
client_client_register_available_la_SOURCES = client/register_available.cc
client_module_LTLIBRARIES = \
client/client_versions.la \
@ -183,6 +184,7 @@ client_module_LTLIBRARIES = \
client/client_initialsync.la \
client/client_search.la \
client/client_joined_groups.la \
client/client_register_available.la \
###
#

View file

@ -16,8 +16,8 @@ IRCD_MODULE
"Client 3.4.1 :Register"
};
static void validate_user_id(const m::id::user &user_id);
static void validate_password(const string_view &password);
extern "C" void validate_user_id(const m::id::user &user_id);
extern "C" std::string
register_user(const m::registar &,

View file

@ -0,0 +1,65 @@
// 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"
};
resource::response
get__register_available(client &client,
const resource::request &request)
{
// 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) }
}
};
}