ircd:Ⓜ️:user::tokens: Add method to delete access tokens by device_id.

This commit is contained in:
Jason Volk 2023-03-03 12:10:52 -08:00
parent eb0a564d0b
commit 694b208829
2 changed files with 27 additions and 0 deletions

View File

@ -27,6 +27,7 @@ struct ircd::m::user::tokens
bool for_each(const closure_bool &) const;
bool check(const string_view &token) const;
bool del(const string_view &token, const string_view &reason) const;
size_t del_by_device(const string_view &device_id, 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;

View File

@ -59,6 +59,32 @@ const
return ret;
}
size_t
ircd::m::user::tokens::del_by_device(const string_view &device_id,
const string_view &reason)
const
{
size_t ret(0);
for_each([this, &ret, &device_id, &reason]
(const event::idx &event_idx, const string_view &token)
{
const auto match
{
[&device_id](const json::object &content)
{
return json::string{content["device_id"]} == device_id;
}
};
if(m::query(std::nothrow, event_idx, "content", false, match))
ret += del(token, reason);
return true;
});
return ret;
}
bool
ircd::m::user::tokens::del(const string_view &token,
const string_view &reason)