0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd:Ⓜ️:login: Support identifier typed login.

This commit is contained in:
Jason Volk 2019-03-04 13:12:53 -08:00
parent 6d6fb8b0d3
commit 19e09b0ad5
4 changed files with 29 additions and 1 deletions

View file

@ -23,6 +23,9 @@ struct ircd::m::login
/// "m.login.token"]
json::property<name::type, json::string>,
/// Identification information for the user.
json::property<name::identifier, json::object>,
/// The fully qualified user ID or just local part of the user ID, to
/// log in.
json::property<name::user, json::string>,

View file

@ -115,6 +115,7 @@ struct ircd::m::name
static constexpr const char *const token {"token"};
static constexpr const char *const device_id {"device_id"};
static constexpr const char *const initial_device_display_name {"initial_device_display_name"};
static constexpr const char *const identifier {"identifier"};
static constexpr const char *const username {"username"};
static constexpr const char *const bind_email {"bind_email"};

View file

@ -94,6 +94,7 @@ constexpr const char *const ircd::m::name::password;
constexpr const char *const ircd::m::name::token;
constexpr const char *const ircd::m::name::device_id;
constexpr const char *const ircd::m::name::initial_device_display_name;
constexpr const char *const ircd::m::name::identifier;
constexpr const char *const ircd::m::name::username;
constexpr const char *const ircd::m::name::bind_email;

View file

@ -30,10 +30,33 @@ resource::response
post__login_password(client &client,
const resource::request::object<m::login> &request)
{
const json::object &identifier
{
json::get<"identifier"_>(request)
};
const json::string &identifier_type
{
identifier.get("type")
};
if(identifier_type && identifier_type != "m.id.user")
throw m::UNSUPPORTED
{
"Identifier type '%s' is not supported.", identifier_type
};
const json::string &username
{
identifier_type == "m.id.user"?
json::string(identifier.at("user")):
at<"user"_>(request)
};
// Build a canonical MXID from a the user field
const m::id::user::buf user_id
{
at<"user"_>(request), my_host()
username, my_host()
};
const string_view &supplied_password