EmailSendingHttpWebApp.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2017 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_NETWORK_HTTP_SERVER_HTTP_WEB_APPS__EMAIL_SENDING_HTTP_WEB_APP
18 #define COM_BORA_SOFTWARE__BALAU_NETWORK_HTTP_SERVER_HTTP_WEB_APPS__EMAIL_SENDING_HTTP_WEB_APP
19 
21 #include <Balau/Network/Http/Server/HttpWebApps/Impl/CurlEmailSender.hpp>
22 
23 // Avoid false positive (due to make_shared).
24 #pragma clang diagnostic push
25 #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
26 
27 namespace Balau{
28 
29 class BalauLogger;
30 class EnvironmentProperties;
31 
32 namespace Network::Http::HttpWebApps {
33 
56  public: using ParameterMap = std::unordered_map<std::string, std::string> ;
57 
61  public: using BodyGenerator = std::function<std::string (HttpSession & session,
62  const StringRequest & request,
63  std::map<std::string, std::string> & variables,
64  const ParameterMap &)>;
65 
75  public: EmailSendingHttpWebApp(BodyGenerator bodyGenerator_,
76  std::shared_ptr<HttpWebApp> successHandler_,
77  std::shared_ptr<HttpWebApp> failureHandler_,
78  std::string host,
79  unsigned short port,
80  std::string user,
81  std::string pw,
82  std::string userAgent,
83  std::string subject_,
84  std::string from_,
85  std::string to_,
86  std::vector<std::string> cc_ = {},
87  bool useTLS_ = true);
88 
98  public: EmailSendingHttpWebApp(BodyGenerator bodyGenerator_,
99  std::string successRedirectLocation_,
100  std::string failureRedirectLocation_,
101  std::string host,
102  unsigned short port,
103  std::string user,
104  std::string pw,
105  std::string userAgent,
106  std::string subject_,
107  std::string from_,
108  std::string to_,
109  std::vector<std::string> cc_ = {},
110  bool useTLS_ = true);
111 
117  public: EmailSendingHttpWebApp(const EnvironmentProperties & configuration, const BalauLogger & logger);
118 
119  public: void handleGetRequest(HttpSession & session,
120  const StringRequest & request,
121  std::map<std::string, std::string> & variables) override;
122 
123  public: void handleHeadRequest(HttpSession & session,
124  const StringRequest & request,
125  std::map<std::string, std::string> & variables) override;
126 
127  public: void handlePostRequest(HttpSession & session,
128  const StringRequest & request,
129  std::map<std::string, std::string> & variables) override;
130 
132 
133  private: static unsigned short verifyPort(int port);
134 
135  private: static BodyGenerator createBodyGenerator(const EnvironmentProperties & configuration);
136 
137  private: BodyGenerator bodyGenerator;
138  private: const std::shared_ptr<HttpWebApp> successHandler;
139  private: const std::shared_ptr<HttpWebApp> failureHandler;
140  private: const std::string successRedirectLocation;
141  private: const std::string failureRedirectLocation;
142  private: const std::string subject;
143  private: const std::string from;
144  private: const std::string to;
145  private: const std::vector<std::string> cc;
146  private: const bool useTLS;
147  private: Impl::CurlEmailSender emailSender;
148  private: std::unique_ptr<BalauLogger> log;
149 };
150 
151 } // namespace Network::Http::HttpWebApps
152 
153 } // namespace Balau
154 
155 #pragma clang diagnostic pop
156 
157 #endif // COM_BORA_SOFTWARE__BALAU_NETWORK_HTTP_SERVER_HTTP_WEB_APPS__EMAIL_SENDING_HTTP_WEB_APP
std::unordered_map< std::string, std::string > ParameterMap
The map type that holds request body parameters.
Definition: EmailSendingHttpWebApp.hpp:56
Manages the handling of HTTP messages and WebSocket upgrade requests in an HTTP connection.
Definition: HttpSession.hpp:46
An HTTP web application handler that sends an email when a post request is made.
Definition: EmailSendingHttpWebApp.hpp:48
void handleGetRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override
Handle a GET request.
void handleHeadRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override
Handle a HEAD request.
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
A hierarchical environment properties holder created from a composite property.
Definition: EnvironmentProperties.hpp:59
Abstract base class of HTTP web application handlers.
Definition: HttpWebApp.hpp:39
Abstract base class of HTTP web application handlers.
EmailSendingHttpWebApp(BodyGenerator bodyGenerator_, std::shared_ptr< HttpWebApp > successHandler_, std::shared_ptr< HttpWebApp > failureHandler_, std::string host, unsigned short port, std::string user, std::string pw, std::string userAgent, std::string subject_, std::string from_, std::string to_, std::vector< std::string > cc_={}, bool useTLS_=true)
Construct an email sender handler with success/failure handlers.
Request< StringBody > StringRequest
A request with a string body.
Definition: NetworkTypes.hpp:267
void handlePostRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override
Handle a POST request.
std::function< std::string(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables, const ParameterMap &)> BodyGenerator
The type of the body generator function.
Definition: EmailSendingHttpWebApp.hpp:64