0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-30 10:42:47 +01:00
construct/modules/client/account/password.cc

82 lines
1.4 KiB
C++
Raw Normal View History

2018-02-14 21:54:21 +01:00
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#include "account.h"
using namespace ircd;
m::resource
2018-02-14 21:54:21 +01:00
account_password
{
"/_matrix/client/r0/account/password",
{
"Changes the password for an account on this homeserver. (3.3.4)"
}
};
m::resource::response
2018-02-14 21:54:21 +01:00
post__password(client &client,
const m::resource::request &request)
2018-02-14 21:54:21 +01:00
try
{
const json::string &new_password
2018-02-14 21:54:21 +01:00
{
request.at("new_password")
2018-02-14 21:54:21 +01:00
};
const json::object &auth
2018-02-14 21:54:21 +01:00
{
request["auth"]
};
const json::string &type
{
auth.at("type")
2018-02-14 21:54:21 +01:00
};
if(type != "m.login.password")
throw m::error
{
"M_UNSUPPORTED", "Login type is not supported."
};
const json::string &session
2018-02-14 21:54:21 +01:00
{
auth["session"]
2018-02-14 21:54:21 +01:00
};
m::user user
{
request.user_id
};
user.password(new_password);
return m::resource::response
2018-02-14 21:54:21 +01:00
{
client, http::OK
};
}
catch(const db::not_found &e)
{
throw m::error
{
http::FORBIDDEN, "M_FORBIDDEN", "Access denied."
};
}
m::resource::method
2018-02-14 21:54:21 +01:00
post_password
{
account_password, "POST", post__password,
{
post_password.REQUIRES_AUTH
}
};