From 6333003aadcd3d9a839d3268ecaed0af569accb7 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 3 Mar 2018 00:18:07 -0800 Subject: [PATCH] ircd::m: Move user::activate() out to modules/client/register. --- include/ircd/m/user.h | 2 +- ircd/m/m.cc | 13 +++++++++++++ ircd/m/user.cc | 32 -------------------------------- modules/client/register.cc | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 33 deletions(-) diff --git a/include/ircd/m/user.h b/include/ircd/m/user.h index 71701acc5..c51bb97d6 100644 --- a/include/ircd/m/user.h +++ b/include/ircd/m/user.h @@ -42,8 +42,8 @@ struct ircd::m::user event::id::buf presence(const string_view &, const string_view &status = {}); void password(const string_view &password); - void activate(const json::members &contents = {}); void deactivate(const json::members &contents = {}); + event::id::buf activate(const json::members &contents = {}); user(const id &user_id) :user_id{user_id} diff --git a/ircd/m/m.cc b/ircd/m/m.cc index e07e3065b..4712bf6f0 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -285,6 +285,19 @@ ircd::m::leave_ircd_room() // m/user.h // +ircd::m::event::id::buf +ircd::m::user::activate(const json::members &contents) +{ + using prototype = event::id::buf (const m::user &, const json::members &); + + static import function + { + "client_register", "register__user" + }; + + return function(*this, contents); +} + ircd::m::event::id::buf ircd::m::user::presence(const string_view &presence, const string_view &status_msg) diff --git a/ircd/m/user.cc b/ircd/m/user.cc index 133c9c068..9ab0b9c10 100644 --- a/ircd/m/user.cc +++ b/ircd/m/user.cc @@ -60,38 +60,6 @@ ircd::m::my(const user &user) return my(user.user_id); } -/// Register the user by creating a room !@user:myhost and then setting a -/// an `ircd.account` state event in the `users` room. -/// -/// Each of the registration options becomes a key'ed state event in the -/// user's room. -/// -/// Once this call completes the registration was successful; otherwise -/// throws. -void -ircd::m::user::activate(const json::members &contents) -try -{ - const auto room_id{this->room_id()}; - m::room room - { - create(room_id, me.user_id, "user") - }; - - send(room, user_id, "ircd.account.options", "registration", contents); - send(users, me.user_id, "ircd.user", user_id, - { - { "active", true } - }); -} -catch(const m::ALREADY_MEMBER &e) -{ - throw m::error - { - http::CONFLICT, "M_USER_IN_USE", "The desired user ID is already in use." - }; -} - void ircd::m::user::deactivate(const json::members &contents) { diff --git a/modules/client/register.cc b/modules/client/register.cc index 8af441617..30e3189fe 100644 --- a/modules/client/register.cc +++ b/modules/client/register.cc @@ -38,6 +38,7 @@ struct body using super_type::tuple; }; +extern "C" m::event::id::buf register__user(const m::user &user, const json::members &contents); static void validate_user_id(const m::id::user &user_id); static void validate_password(const string_view &password); @@ -262,3 +263,40 @@ validate_password(const string_view &password) "The desired password is too long" }; } + +/// Register the user by creating a room !@user:myhost and then setting a +/// an `ircd.account` state event in the `users` room. +/// +/// Each of the registration options becomes a key'ed state event in the +/// user's room. +/// +/// Once this call completes the registration was successful; otherwise +/// throws. +m::event::id::buf +register__user(const m::user &user, + const json::members &contents) +try +{ + const m::room::id user_room_id + { + user.room_id() + }; + + m::room user_room + { + create(user_room_id, m::me.user_id, "user") + }; + + send(user_room, user.user_id, "ircd.account.options", "registration", contents); + return send(user.users, m::me.user_id, "ircd.user", user.user_id, + { + { "active", true } + }); +} +catch(const m::ALREADY_MEMBER &e) +{ + throw m::error + { + http::CONFLICT, "M_USER_IN_USE", "The desired user ID is already in use." + }; +}