mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 22:41:12 +01:00
ircd:Ⓜ️:user::tokens: Add methods to create and add tokens via interface.
This commit is contained in:
parent
f39e25f972
commit
990482308e
2 changed files with 38 additions and 0 deletions
|
@ -28,6 +28,8 @@ struct ircd::m::user::tokens
|
|||
bool check(const string_view &token) const;
|
||||
bool del(const string_view &token, const string_view &reason) const;
|
||||
size_t del(const string_view &reason) const;
|
||||
m::event::id::buf add(const string_view &, const json::object & = {}) const;
|
||||
string_view create(const mutable_buffer &, const json::object & = {}) const;
|
||||
|
||||
tokens(const m::user &user)
|
||||
:user{user}
|
||||
|
|
|
@ -8,6 +8,42 @@
|
|||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::user::tokens::create(const mutable_buffer &buf,
|
||||
const json::object &content)
|
||||
const
|
||||
{
|
||||
const auto token
|
||||
{
|
||||
generate(buf)
|
||||
};
|
||||
|
||||
const auto event_id
|
||||
{
|
||||
add(token, content)
|
||||
};
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::user::tokens::add(const string_view &token,
|
||||
const json::object &content)
|
||||
const
|
||||
{
|
||||
const m::room::id::buf tokens_room
|
||||
{
|
||||
"tokens", user.user_id.host()
|
||||
};
|
||||
|
||||
const m::event::id::buf event_id
|
||||
{
|
||||
m::send(tokens_room, user, "ircd.access_token", token, content)
|
||||
};
|
||||
|
||||
return event_id;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::user::tokens::del(const string_view &reason)
|
||||
const
|
||||
|
|
Loading…
Reference in a new issue