mirror of
https://github.com/matrix-construct/construct
synced 2024-06-11 06:28:55 +02:00
ircd:Ⓜ️ Tweak specifics of user/account creation/activation related.
This commit is contained in:
parent
30532b47ff
commit
08fc944021
|
@ -16,8 +16,9 @@ namespace ircd::m
|
|||
struct user;
|
||||
|
||||
bool my(const user &);
|
||||
|
||||
bool exists(const user &);
|
||||
bool exists(const id::user &);
|
||||
user create(const id::user &, const json::members &args = {});
|
||||
}
|
||||
|
||||
struct ircd::m::user
|
||||
|
@ -41,8 +42,8 @@ struct ircd::m::user
|
|||
event::id::buf password(const string_view &password);
|
||||
|
||||
bool is_active() const;
|
||||
event::id::buf deactivate(const json::members &contents = {});
|
||||
event::id::buf activate(const json::members &contents = {});
|
||||
event::id::buf deactivate();
|
||||
event::id::buf activate();
|
||||
|
||||
user(const id &user_id)
|
||||
:user_id{user_id}
|
||||
|
|
51
ircd/m/m.cc
51
ircd/m/m.cc
|
@ -227,10 +227,8 @@ ircd::m::init::bootstrap()
|
|||
);
|
||||
|
||||
create(user::users, me.user_id);
|
||||
me.activate(
|
||||
{
|
||||
{ "active", true }
|
||||
});
|
||||
create(me.user_id);
|
||||
me.activate();
|
||||
|
||||
create(my_room, me.user_id);
|
||||
send(my_room, me.user_id, "m.room.name", "",
|
||||
|
@ -742,12 +740,45 @@ ircd::m::user::tokens
|
|||
tokens_room_id
|
||||
};
|
||||
|
||||
ircd::m::user
|
||||
ircd::m::create(const id::user &user_id,
|
||||
const json::members &contents)
|
||||
{
|
||||
const m::user user
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
const m::room::id::buf user_room_id
|
||||
{
|
||||
user.room_id()
|
||||
};
|
||||
|
||||
//TODO: ABA
|
||||
//TODO: TXN
|
||||
m::room user_room
|
||||
{
|
||||
create(user_room_id, m::me.user_id, "user")
|
||||
};
|
||||
|
||||
//TODO: ABA
|
||||
//TODO: TXN
|
||||
send(user.users, m::me.user_id, "ircd.user", user.user_id, contents);
|
||||
return user;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::exists(const user::id &user_id)
|
||||
{
|
||||
return user::users.has("ircd.user", user_id);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::exists(const user &user)
|
||||
{
|
||||
return exists(user.user_id);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::my(const user &user)
|
||||
{
|
||||
|
@ -803,29 +834,29 @@ ircd::m::user::gen_access_token(const mutable_buffer &buf)
|
|||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::user::activate(const json::members &contents)
|
||||
ircd::m::user::activate()
|
||||
{
|
||||
using prototype = event::id::buf (const m::user &, const json::members &);
|
||||
using prototype = event::id::buf (const m::user &);
|
||||
|
||||
static import<prototype> function
|
||||
{
|
||||
"client_account", "activate__user"
|
||||
};
|
||||
|
||||
return function(*this, contents);
|
||||
return function(*this);
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::user::deactivate(const json::members &contents)
|
||||
ircd::m::user::deactivate()
|
||||
{
|
||||
using prototype = event::id::buf (const m::user &, const json::members &);
|
||||
using prototype = event::id::buf (const m::user &);
|
||||
|
||||
static import<prototype> function
|
||||
{
|
||||
"client_account", "deactivate__user"
|
||||
};
|
||||
|
||||
return function(*this, contents);
|
||||
return function(*this);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
using namespace ircd;
|
||||
|
||||
extern "C" bool is_active__user(const m::user &user);
|
||||
extern "C" m::event::id::buf activate__user(const m::user &user, const json::members &contents);
|
||||
extern "C" m::event::id::buf activate__user(const m::user &user);
|
||||
extern "C" m::event::id::buf deactivate__user(const m::user &user);
|
||||
|
||||
mapi::header
|
||||
IRCD_MODULE
|
||||
|
@ -31,38 +32,29 @@ account_resource
|
|||
};
|
||||
|
||||
m::event::id::buf
|
||||
activate__user(const m::user &user,
|
||||
const json::members &contents)
|
||||
activate__user(const m::user &user)
|
||||
{
|
||||
//TODO: ABA
|
||||
if(is_active__user(user))
|
||||
throw m::error
|
||||
{
|
||||
http::CONFLICT, "M_USER_IN_USE",
|
||||
"The desired user ID is already in use."
|
||||
};
|
||||
|
||||
const m::room::id::buf user_room_id
|
||||
const m::user::room user_room
|
||||
{
|
||||
user.room_id()
|
||||
user
|
||||
};
|
||||
|
||||
//TODO: ABA
|
||||
m::room user_room
|
||||
return send(user_room, m::me.user_id, "ircd.account", "active",
|
||||
{
|
||||
create(user_room_id, m::me.user_id, "user")
|
||||
};
|
||||
|
||||
//TODO: ABA
|
||||
return send(user.users, m::me.user_id, "ircd.user", user.user_id, contents);
|
||||
{ "value", true }
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
is_active__user(const m::user &user)
|
||||
{
|
||||
const m::user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
bool ret{false};
|
||||
const m::room &users{m::user::users};
|
||||
users.get(std::nothrow, "ircd.user", user.user_id, [&ret]
|
||||
user_room.get(std::nothrow, "ircd.account", "active", [&ret]
|
||||
(const m::event &event)
|
||||
{
|
||||
const json::object &content
|
||||
|
@ -70,7 +62,7 @@ is_active__user(const m::user &user)
|
|||
at<"content"_>(event)
|
||||
};
|
||||
|
||||
ret = content.get<bool>("active") == true;
|
||||
ret = content.get<bool>("value") == true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -64,6 +64,13 @@ extern "C" m::event::id::buf
|
|||
deactivate__user(const m::user &user,
|
||||
const json::members &)
|
||||
{
|
||||
//TODO: XXX
|
||||
return {};
|
||||
const m::user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
return send(user_room, m::me.user_id, "ircd.account", "active",
|
||||
{
|
||||
{ "value", false }
|
||||
});
|
||||
}
|
||||
|
|
|
@ -92,20 +92,27 @@ try
|
|||
// Check if the password is acceptable for this server or throws
|
||||
validate_password(password);
|
||||
|
||||
//TODO: ABA
|
||||
if(exists(user_id))
|
||||
throw m::error
|
||||
{
|
||||
http::CONFLICT, "M_USER_IN_USE",
|
||||
"The desired user ID is already in use."
|
||||
};
|
||||
|
||||
//TODO: ABA / TXN
|
||||
// Represent the user
|
||||
m::user user
|
||||
{
|
||||
user_id
|
||||
m::create(user_id)
|
||||
};
|
||||
|
||||
// Activate the account. Underneath this will create a special room
|
||||
// for this user in the form of !@user:host and set a key in !users:host
|
||||
// If the user_id is taken this throws 409 Conflict because those assets
|
||||
// will already exist; otherwise the user is registered after this call.
|
||||
user.activate(
|
||||
{
|
||||
{ "active", true }
|
||||
});
|
||||
//TODO: ABA / TXN
|
||||
user.activate();
|
||||
|
||||
// Set the password for the account. This issues an ircd.password state
|
||||
// event to the user's room. User will be able to login with
|
||||
|
|
|
@ -40,11 +40,16 @@ presence_set(const m::presence &content)
|
|||
at<"user_id"_>(content)
|
||||
};
|
||||
|
||||
//TODO: ABA
|
||||
if(!exists(user))
|
||||
create(user.user_id);
|
||||
|
||||
const m::user::room user_room
|
||||
{
|
||||
user
|
||||
};
|
||||
|
||||
//TODO: ABA
|
||||
return send(user_room, user.user_id, "m.presence", json::strung{content});
|
||||
}
|
||||
|
||||
|
@ -129,9 +134,6 @@ handle_edu_m_presence_(const m::event &event,
|
|||
at<"presence"_>(object)
|
||||
};
|
||||
|
||||
if(!exists(user_id))
|
||||
m::user{user_id}.activate();
|
||||
|
||||
const auto evid
|
||||
{
|
||||
m::presence::set(object)
|
||||
|
|
Loading…
Reference in a new issue