mirror of
https://github.com/matrix-construct/construct
synced 2024-05-29 00:03:45 +02:00
ircd:Ⓜ️:user: Move definitions from modules/client to m_user.
This commit is contained in:
parent
7fa72e8f39
commit
2115bf7cf4
38
ircd/m.cc
38
ircd/m.cc
|
@ -2461,44 +2461,6 @@ const
|
|||
return function(*this);
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::user::password(const string_view &password)
|
||||
{
|
||||
using prototype = event::id::buf (const m::user::id &, const string_view &) noexcept;
|
||||
|
||||
static mods::import<prototype> function
|
||||
{
|
||||
"client_account", "set_password"
|
||||
};
|
||||
|
||||
return function(user_id, password);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::user::is_password(const string_view &password)
|
||||
const noexcept try
|
||||
{
|
||||
using prototype = bool (const m::user::id &, const string_view &) noexcept;
|
||||
|
||||
static mods::import<prototype> function
|
||||
{
|
||||
"client_account", "is_password"
|
||||
};
|
||||
|
||||
return function(user_id, password);
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::critical
|
||||
{
|
||||
"user::is_password(): %s %s",
|
||||
string_view{user_id},
|
||||
e.what()
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// user::room
|
||||
//
|
||||
|
|
|
@ -79,84 +79,3 @@ post_password
|
|||
post_password.REQUIRES_AUTH
|
||||
}
|
||||
};
|
||||
|
||||
static string_view
|
||||
gen_password_hash(const mutable_buffer &out,
|
||||
const string_view &supplied_password);
|
||||
|
||||
extern "C" m::event::id::buf
|
||||
set_password(const m::user::id &user_id,
|
||||
const string_view &password)
|
||||
{
|
||||
char buf[64];
|
||||
const auto supplied
|
||||
{
|
||||
gen_password_hash(buf, password)
|
||||
};
|
||||
|
||||
const m::user::room user_room{user_id};
|
||||
return send(user_room, user_id, "ircd.password", user_id,
|
||||
{
|
||||
{ "sha256", supplied }
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
is_password(const m::user::id &user_id,
|
||||
const string_view &password)
|
||||
noexcept try
|
||||
{
|
||||
char buf[64];
|
||||
const auto supplied
|
||||
{
|
||||
gen_password_hash(buf, password)
|
||||
};
|
||||
|
||||
bool ret{false};
|
||||
const m::user::room user_room{user_id};
|
||||
user_room.get("ircd.password", user_id, [&supplied, &ret]
|
||||
(const m::event &event)
|
||||
{
|
||||
const json::object &content
|
||||
{
|
||||
json::at<"content"_>(event)
|
||||
};
|
||||
|
||||
const auto &correct
|
||||
{
|
||||
unquote(content.at("sha256"))
|
||||
};
|
||||
|
||||
ret = supplied == correct;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch(const m::NOT_FOUND &e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::critical
|
||||
{
|
||||
"is_password__user(): %s %s",
|
||||
string_view{user_id},
|
||||
e.what()
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
string_view
|
||||
gen_password_hash(const mutable_buffer &out,
|
||||
const string_view &supplied_password)
|
||||
{
|
||||
//TODO: ADD SALT
|
||||
const sha256::buf hash
|
||||
{
|
||||
sha256{supplied_password}
|
||||
};
|
||||
|
||||
return b64encode_unpadded(out, hash);
|
||||
}
|
||||
|
|
|
@ -65,3 +65,98 @@ catch(const std::exception &e)
|
|||
|
||||
throw;
|
||||
}
|
||||
|
||||
//
|
||||
// user::user
|
||||
//
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
static string_view gen_password_hash(const mutable_buffer &, const string_view &);
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::user::password(const string_view &password)
|
||||
{
|
||||
char buf[64];
|
||||
const auto supplied
|
||||
{
|
||||
gen_password_hash(buf, password)
|
||||
};
|
||||
|
||||
const m::user::room user_room
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
return send(user_room, user_id, "ircd.password", user_id,
|
||||
{
|
||||
{ "sha256", supplied }
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::user::is_password(const string_view &password)
|
||||
const noexcept try
|
||||
{
|
||||
char buf[64];
|
||||
const auto supplied
|
||||
{
|
||||
gen_password_hash(buf, password)
|
||||
};
|
||||
|
||||
bool ret{false};
|
||||
const m::user::room user_room
|
||||
{
|
||||
user_id
|
||||
};
|
||||
|
||||
const ctx::uninterruptible::nothrow ui;
|
||||
user_room.get("ircd.password", user_id, [&supplied, &ret]
|
||||
(const m::event &event)
|
||||
{
|
||||
const json::object &content
|
||||
{
|
||||
json::at<"content"_>(event)
|
||||
};
|
||||
|
||||
const auto &correct
|
||||
{
|
||||
unquote(content.at("sha256"))
|
||||
};
|
||||
|
||||
ret = supplied == correct;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch(const m::NOT_FOUND &e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::critical
|
||||
{
|
||||
"is_password__user(): %s %s",
|
||||
string_view{user_id},
|
||||
e.what()
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::gen_password_hash(const mutable_buffer &out,
|
||||
const string_view &supplied_password)
|
||||
{
|
||||
//TODO: ADD SALT
|
||||
const sha256::buf hash
|
||||
{
|
||||
sha256{supplied_password}
|
||||
};
|
||||
|
||||
return b64encode_unpadded(out, hash);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue