2018-02-14 21:42:25 +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 "user.h"
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
2018-02-15 22:06:49 +01:00
|
|
|
"Client X.X :User endpoints"
|
2018-02-14 21:42:25 +01:00
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource
|
2018-02-14 21:42:25 +01:00
|
|
|
user_resource
|
|
|
|
{
|
|
|
|
"/_matrix/client/r0/user/",
|
|
|
|
{
|
|
|
|
"User resource",
|
|
|
|
resource::DIRECTORY,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2020-04-10 10:04:30 +02:00
|
|
|
get_user(client &client,
|
|
|
|
const m::resource::request &request)
|
2018-02-14 21:42:25 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 2)
|
2018-02-15 06:52:19 +01:00
|
|
|
throw m::NEED_MORE_PARAMS
|
2018-02-14 21:42:25 +01:00
|
|
|
{
|
2018-02-15 06:52:19 +01:00
|
|
|
"user_id required"
|
2018-02-14 21:42:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(user_id, request.parv[0])
|
2018-02-14 21:42:25 +01:00
|
|
|
};
|
|
|
|
|
2018-04-09 04:34:20 +02:00
|
|
|
if(request.user_id != user_id)
|
|
|
|
throw m::UNSUPPORTED
|
|
|
|
{
|
|
|
|
"Getting user data as someone else is not yet supported"
|
|
|
|
};
|
|
|
|
|
2018-02-14 21:42:25 +01:00
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cmd == "filter")
|
|
|
|
return get__filter(client, request, user_id);
|
|
|
|
|
2018-04-09 04:12:22 +02:00
|
|
|
if(cmd == "account_data")
|
|
|
|
return get__account_data(client, request, user_id);
|
|
|
|
|
2018-06-20 05:32:29 +02:00
|
|
|
if(cmd == "rooms")
|
|
|
|
return get__rooms(client, request, user_id);
|
|
|
|
|
2018-02-14 21:42:25 +01:00
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"/user command not found"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2018-02-14 21:42:25 +01:00
|
|
|
get_method
|
|
|
|
{
|
|
|
|
user_resource, "GET", get_user,
|
|
|
|
{
|
|
|
|
get_method.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2020-04-10 10:04:30 +02:00
|
|
|
post_user(client &client,
|
|
|
|
m::resource::request &request)
|
2018-02-14 21:42:25 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 2)
|
2018-02-15 06:52:19 +01:00
|
|
|
throw m::NEED_MORE_PARAMS
|
2018-02-14 21:42:25 +01:00
|
|
|
{
|
2018-02-15 06:52:19 +01:00
|
|
|
"user_id required"
|
2018-02-14 21:42:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(user_id, request.parv[0])
|
2018-02-14 21:42:25 +01:00
|
|
|
};
|
|
|
|
|
2018-04-09 04:34:20 +02:00
|
|
|
if(request.user_id != user_id)
|
|
|
|
throw m::UNSUPPORTED
|
|
|
|
{
|
|
|
|
"Posting user data as someone else is not yet supported"
|
|
|
|
};
|
|
|
|
|
2018-02-14 21:42:25 +01:00
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cmd == "filter")
|
|
|
|
return post__filter(client, request, user_id);
|
|
|
|
|
2018-02-20 23:45:22 +01:00
|
|
|
if(cmd == "openid")
|
|
|
|
return post__openid(client, request, user_id);
|
|
|
|
|
2018-02-14 21:42:25 +01:00
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"/user command not found"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2018-02-14 21:42:25 +01:00
|
|
|
post_method
|
|
|
|
{
|
|
|
|
user_resource, "POST", post_user,
|
|
|
|
{
|
|
|
|
post_method.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2020-04-10 10:04:30 +02:00
|
|
|
put_user(client &client,
|
|
|
|
const m::resource::request &request)
|
2018-02-14 21:42:25 +01:00
|
|
|
{
|
2018-02-22 01:53:07 +01:00
|
|
|
if(request.parv.size() < 1)
|
2018-02-15 06:52:19 +01:00
|
|
|
throw m::NEED_MORE_PARAMS
|
2018-02-14 21:42:25 +01:00
|
|
|
{
|
2018-02-15 06:52:19 +01:00
|
|
|
"user_id required"
|
2018-02-14 21:42:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(user_id, request.parv[0])
|
2018-02-14 21:42:25 +01:00
|
|
|
};
|
|
|
|
|
2018-04-09 04:34:20 +02:00
|
|
|
if(request.user_id != user_id)
|
|
|
|
throw m::UNSUPPORTED
|
|
|
|
{
|
|
|
|
"Putting user data as someone else is not yet supported"
|
|
|
|
};
|
|
|
|
|
2018-02-22 01:53:07 +01:00
|
|
|
if(request.parv.size() < 2)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"user command required"
|
|
|
|
};
|
|
|
|
|
2018-02-14 21:42:25 +01:00
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cmd == "account_data")
|
|
|
|
return put__account_data(client, request, user_id);
|
|
|
|
|
2018-02-22 01:53:07 +01:00
|
|
|
if(cmd == "rooms")
|
|
|
|
return put__rooms(client, request, user_id);
|
|
|
|
|
2018-02-14 21:42:25 +01:00
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"/user command not found"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2018-02-14 21:42:25 +01:00
|
|
|
put_method
|
|
|
|
{
|
|
|
|
user_resource, "PUT", put_user,
|
|
|
|
{
|
|
|
|
put_method.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
2019-03-06 02:10:22 +01:00
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2020-04-10 10:04:30 +02:00
|
|
|
delete_user(client &client,
|
|
|
|
const m::resource::request &request)
|
2019-03-06 02:10:22 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 1)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"user_id required"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
|
|
|
url::decode(user_id, request.parv[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
if(request.user_id != user_id)
|
|
|
|
throw m::UNSUPPORTED
|
|
|
|
{
|
|
|
|
"Deleting user data as someone else is not yet supported"
|
|
|
|
};
|
|
|
|
|
|
|
|
if(request.parv.size() < 2)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"user command required"
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &cmd
|
|
|
|
{
|
|
|
|
request.parv[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
if(cmd == "rooms")
|
|
|
|
return delete__rooms(client, request, user_id);
|
|
|
|
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"/user command not found"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2019-03-06 02:10:22 +01:00
|
|
|
delete_method
|
|
|
|
{
|
|
|
|
user_resource, "DELETE", delete_user,
|
|
|
|
{
|
|
|
|
delete_method.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|