2018-02-04 03:22:01 +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.
|
2017-08-23 23:10:28 +02:00
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
struct account
|
2017-12-12 21:26:39 +01:00
|
|
|
:ircd::resource
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
|
|
|
resource deactivate
|
|
|
|
{
|
2017-10-12 05:52:33 +02:00
|
|
|
"/_matrix/client/r0/account/deactivate",
|
2017-12-12 21:26:39 +01:00
|
|
|
{
|
|
|
|
"Deactivate the user's account, removing all ability for the user to login again. (3.3.3)"
|
|
|
|
}
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
resource password
|
|
|
|
{
|
2017-10-12 05:52:33 +02:00
|
|
|
"/_matrix/client/r0/account/password",
|
2017-12-12 21:26:39 +01:00
|
|
|
{
|
|
|
|
"Changes the password for an account on this homeserver. (3.3.4)"
|
|
|
|
}
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
using resource::resource;
|
|
|
|
}
|
|
|
|
account_resource
|
|
|
|
{
|
2017-10-12 05:52:33 +02:00
|
|
|
"/_matrix/client/r0/account",
|
2017-12-12 21:26:39 +01:00
|
|
|
{
|
|
|
|
"Account management (3.3)"
|
|
|
|
}
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
account_password(client &client, const resource::request &request)
|
|
|
|
try
|
|
|
|
{
|
2017-09-25 05:47:13 +02:00
|
|
|
const string_view &new_password
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2017-09-25 05:47:13 +02:00
|
|
|
unquote(request.at("new_password"))
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
|
2017-09-25 05:47:13 +02:00
|
|
|
const string_view &type
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2017-09-25 05:47:13 +02:00
|
|
|
unquote(request.at({"auth", "type"}))
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
|
2017-09-25 05:47:13 +02:00
|
|
|
if(type != "m.login.password")
|
2017-08-23 23:10:28 +02:00
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
"M_UNSUPPORTED", "Login type is not supported."
|
|
|
|
};
|
|
|
|
|
2017-09-25 05:47:13 +02:00
|
|
|
const string_view &session
|
|
|
|
{
|
|
|
|
request[{"auth", "session"}]
|
|
|
|
};
|
2017-08-23 23:10:28 +02:00
|
|
|
|
2017-09-25 05:47:13 +02:00
|
|
|
m::user user
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2017-09-25 05:47:13 +02:00
|
|
|
request.user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
user.password(new_password);
|
2017-08-23 23:10:28 +02:00
|
|
|
return resource::response
|
|
|
|
{
|
2017-09-25 05:47:13 +02:00
|
|
|
client, http::OK
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const db::not_found &e)
|
|
|
|
{
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::FORBIDDEN, "M_FORBIDDEN", "Access denied."
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-25 05:47:13 +02:00
|
|
|
resource::method post_password
|
2017-08-23 23:10:28 +02:00
|
|
|
{
|
2017-09-25 05:47:13 +02:00
|
|
|
account_resource.password, "POST", account_password,
|
|
|
|
{
|
|
|
|
post_password.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
account_deactivate(client &client, const resource::request &request)
|
|
|
|
{
|
|
|
|
const string_view &type
|
|
|
|
{
|
|
|
|
request.at({"auth", "type"})
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &session
|
|
|
|
{
|
|
|
|
request[{"auth", "session"}]
|
|
|
|
};
|
|
|
|
|
|
|
|
m::user user
|
|
|
|
{
|
|
|
|
request.user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
user.deactivate();
|
|
|
|
|
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, json::members
|
|
|
|
{
|
|
|
|
{ "goodbye", "Thanks for visiting. Come back soon!" }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
resource::method post_deactivate
|
|
|
|
{
|
|
|
|
account_resource.deactivate, "POST", account_deactivate,
|
|
|
|
{
|
|
|
|
post_deactivate.REQUIRES_AUTH
|
|
|
|
}
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
mapi::header IRCD_MODULE
|
|
|
|
{
|
2017-09-08 11:32:49 +02:00
|
|
|
"registers the resource 'client/account' to handle requests"
|
2017-08-23 23:10:28 +02:00
|
|
|
};
|