0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-01 08:18:20 +02:00

ircd:Ⓜ️ Move user::activate() out to modules/client/register.

This commit is contained in:
Jason Volk 2018-03-03 00:18:07 -08:00
parent fa3d92103c
commit 6333003aad
4 changed files with 52 additions and 33 deletions

View file

@ -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}

View file

@ -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<prototype> 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)

View file

@ -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)
{

View file

@ -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."
};
}