33 #ifndef _IDENTT_QUERY_INVITE_SERVICE_HPP_ 34 #define _IDENTT_QUERY_INVITE_SERVICE_HPP_ 38 #include <store/InviteService.hpp> 44 template <
class HttpServerT>
68 identt::utils::SharedTable::pointer stptr,
69 typename std::shared_ptr<HttpServerT> server,
70 ::identt::query::HelpQuery::pointer helpquery,
72 :
identt::query::
ServiceBase<HttpServerT>(IDENTT_SERVICE_SCOPE_HTTP | IDENTT_SERVICE_SCOPE_HTTPS)
74 if (!(this->myscope & scope))
return;
77 helpquery->add({scope,
"POST _matrix/identity/api/v1/store-invite", {
78 "An identity service can store pending invitations to a user’s 3pid, which will",
79 "be retrieved and can be either notified on or look up when the 3pid is associated with a Matrix user ID.",
80 "following URL encoded POST parameters:",
81 " medium (string, required): The literal string email.",
82 " address (string, required): The email address or msisdn of the invited user.",
83 " room_id (string, required): The Matrix room ID to which the user is invited.",
84 " sender (string, required): The matrix user ID of the inviting user.",
85 " accesskey (string, required): if invite_requires_accesskey is set." 86 "An arbitrary number of other parameters may also be specified." 90 server->resource[
"/_matrix/identity/api/v1/store-invite$"][
"POST"]
91 =[
this,stptr](
typename HttpServerT::RespPtr response,
typename HttpServerT::ReqPtr request) {
92 IDENTT_PARALLEL_ONE([
this,stptr,response,request] {
94 LOG(INFO) << request->path;
98 identt::query::StoreInviteDataT inv;
101 int stat =
json2pb( request->content.string() , inv.mutable_invqry() , err);
111 if (stptr->invite_requires_key.Get()) {
112 bool is_server_query =
false;
113 auto it=request->header.find(
"Shared-Secret");
114 if (it!=request->header.end()) {
115 is_server_query = (it->second == stptr->shared_secret.Get());
117 if (!is_server_query ) {
123 if (stptr->is_master.Get())
129 hclient.
SendToMaster(stptr,::identt::hrpc::M_STOREINVITE,&inv);
134 pb2json(inv.mutable_invres() , output);
135 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
138 int ecode = (e.ecode()>=IDENTT_SYDENT_ERROR_MIN && e.ecode()<=IDENTT_SYDENT_ERROR_MAX) ? e.ecode() : M_UNKNOWN;
139 std::string output =
err2json(SydentErrors.at(ecode),e.what());
140 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
143 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
144 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
145 }
catch (std::exception& e)
147 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
148 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
163 #endif // _IDENTT_QUERY_INVITE_SERVICE_HPP_ void HttpOKAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ec, const char *em, const char *content_type, std::string &payload, bool add_cors)
HttpOKAction : OK Action template.
Definition: ServiceBase.hpp:154
Sydent Exceptions.
Definition: SydentQuery.hpp:91
void HttpErrorAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ec, const char *em)
HttpErrorAction : Error Action Template no payload maybe template.
Definition: ServiceBase.hpp:85
void StoreInviteAction(::identt::utils::SharedTable::pointer stptr, identt::query::StoreInviteDataT *inv)
StoreInviteAction : invite query internals.
Definition: InviteService.cc:52
Definition: BaseUtils.hpp:52
void pb2json(const google::protobuf::Message *msg, std::string &str)
pb2json : Convert protobuf to json
Definition: ProtoJson.cc:415
Definition: ServiceBase.hpp:55
Definition: CryptoBase.hpp:49
Definition: BaseUtils.hpp:89
Definition: InviteService.hpp:45
void VerifyAccessKeyAction(::identt::utils::SharedTable::pointer stptr, std::string akey)
VerifyAccessKeyAction : verify the access key.
Definition: AccessKeyService.cc:44
std::string err2json(const std::string errorcode, const std::string error)
err2json : Generate a Json for Error Message
Definition: ProtoJson.cc:511
bool JsonRequest(typename HttpServerT::ReqPtr request)
JsonRequest : Check if request is json from Content-Type and Accept fields.
Definition: ServiceBase.hpp:178
Definition: HrpcClient.hpp:46
int json2pb(const std::string &json, google::protobuf::Message *msg, std::string &err)
json2pb : Convert json to protobuf
Definition: ProtoJson.cc:446
InviteService(identt::utils::SharedTable::pointer stptr, typename std::shared_ptr< HttpServerT > server, ::identt::query::HelpQuery::pointer helpquery, unsigned int scope)
InviteService : constructor.
Definition: InviteService.hpp:67
Definition: InviteService.hpp:42
bool SendToMaster(::identt::utils::SharedTable::pointer stptr, ::identt::hrpc::MasterCmdTypeE service_id, google::protobuf::Message *msg, bool nothrow=false)
SendToMaster : send to master and get output.
Definition: AccessKeyService.hpp:42