Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RequestAccount.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
9
11{
13 {
14 public RequestAccount()
15 : base("/RequestAccount")
16 {
17 }
18
19 public override bool HandlesSubPaths => false;
20 public override bool UserSessions => true;
21 public bool AllowsPOST => true;
22
23 public async Task POST(HttpRequest Request, HttpResponse Response)
24 {
25 if (!Request.HasData)
26 throw new BadRequestException();
27
28 object Obj = await Request.DecodeDataAsync();
29 if (!(Obj is Dictionary<string, string> Form))
30 throw new BadRequestException();
31
32 string Name;
34 string LinkedIn;
35 string Organization;
36 string Where;
37 string TimeLimit;
38 string Text;
39 string RecaptchaResponse;
40
41 if (!Form.ContainsKey("Name") || string.IsNullOrEmpty(Name = Form["Name"]))
42 throw new BadRequestException();
43
44 if (!Form.ContainsKey("EMail") || CaseInsensitiveString.IsNullOrEmpty(EMail = Form["EMail"]))
45 throw new BadRequestException();
46
47 if (!Form.ContainsKey("LinkedIn") || string.IsNullOrEmpty(LinkedIn = Form["LinkedIn"]))
48 throw new BadRequestException();
49
50 if (!Form.ContainsKey("Organization") || string.IsNullOrEmpty(Organization = Form["Organization"]))
51 throw new BadRequestException();
52
53 if (!Form.ContainsKey("Where") || string.IsNullOrEmpty(Where = Form["Where"]))
54 throw new BadRequestException();
55
56 if (!Form.ContainsKey("TimeLimit") || string.IsNullOrEmpty(TimeLimit = Form["TimeLimit"]))
57 TimeLimit = string.Empty;
58
59 if (!Form.ContainsKey("Text") || string.IsNullOrEmpty(Text = Form["Text"]))
60 throw new BadRequestException();
61
62 if (!Form.ContainsKey("g-recaptcha-response") || string.IsNullOrEmpty(RecaptchaResponse = Form["g-recaptcha-response"]))
63 throw new BadRequestException();
64
65 if (await Feedback.SiteVerify(RecaptchaResponse, Request.RemoteEndPoint))
66 {
67 KeyValuePair<string, object>[] Tags = await LoginAuditor.Annotate(Request.RemoteEndPoint,
68 new KeyValuePair<string, object>("Name", Name),
69 new KeyValuePair<string, object>("EMail", EMail.Value),
70 new KeyValuePair<string, object>("LinkedIn", LinkedIn),
71 new KeyValuePair<string, object>("Organization", Organization),
72 new KeyValuePair<string, object>("Where", Where),
73 new KeyValuePair<string, object>("TimeLimit", TimeLimit),
74 new KeyValuePair<string, object>("Text", Text),
75 new KeyValuePair<string, object>("RemoteEndPoint", Request.RemoteEndPoint));
76
77 Dictionary<string, object> Feedback = new Dictionary<string, object>();
78 foreach (KeyValuePair<string, object> P in Tags)
79 Feedback.Add(P.Key, P.Value);
80
81 Request.Session["Feedback"] = Feedback;
82
83 StringBuilder Markdown = new StringBuilder();
84 DateTime Now = DateTime.Now;
85
86 Markdown.AppendLine("Account requested.");
87 Markdown.AppendLine();
88
89 Markdown.AppendLine("| Account request ||");
90 Markdown.AppendLine("|:------|:-------|");
91
92 Markdown.Append("| Name: | ");
93 Markdown.Append(MarkdownDocument.Encode(Name));
94 Markdown.AppendLine(" |");
95
96 Markdown.Append("| e-Mail: | <a href=\"mailto:");
97 Markdown.Append(EMail.Replace("\"", "&quot;"));
98 Markdown.Append("\" target=\"_blank\">");
99 Markdown.Append(MarkdownDocument.Encode(EMail));
100 Markdown.AppendLine("</a> |");
101
102 Markdown.Append("| LinkedIn: | <a href=\"");
103 Markdown.Append(LinkedIn.Replace("\"", "&quot;"));
104 Markdown.Append("\" target=\"_blank\">");
105 Markdown.Append(MarkdownDocument.Encode(LinkedIn));
106 Markdown.AppendLine("</a> |");
107
108 Markdown.Append("| Organization: | ");
109 Markdown.Append(MarkdownDocument.Encode(Organization));
110 Markdown.AppendLine(" |");
111
112 Markdown.Append("| Where: | ");
113 Markdown.Append(MarkdownDocument.Encode(Where));
114 Markdown.AppendLine(" |");
115
116 Markdown.Append("| Time Limit: | ");
117 Markdown.Append(MarkdownDocument.Encode(TimeLimit));
118 Markdown.AppendLine(" |");
119
121
122 Markdown.Append("| Date | ");
123 Markdown.Append(MarkdownDocument.Encode(Now.ToShortDateString()));
124 Markdown.AppendLine(" |");
125 Markdown.Append("| Time | ");
126 Markdown.Append(MarkdownDocument.Encode(Now.ToLongTimeString()));
127 Markdown.AppendLine(" |");
128
129 Markdown.AppendLine();
130 Markdown.AppendLine();
131 Markdown.AppendLine("```");
132 Markdown.AppendLine(Text.Replace("```", " ` ` ` "));
133 Markdown.AppendLine("```");
134
135 await LoginAuditor.AppendWhoIsInfo(Markdown, Request.RemoteEndPoint);
136
137 await IoTGateway.Gateway.SendNotification(Markdown.ToString());
138
139 throw new SeeOtherException("/AccountRequested.md"); // PRG pattern.
140 }
141 else
142 throw new ForbiddenException("Request not verified. Bot?");
143 }
144 }
145}
Contains a markdown document. This markdown document class supports original markdown,...
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
Definition: HttpRequest.cs:18
string RemoteEndPoint
Remote end-point.
Definition: HttpRequest.cs:195
bool HasData
If the request has data.
Definition: HttpRequest.cs:74
Variables Session
Contains session states, if the resource requires sessions, or null otherwise.
Definition: HttpRequest.cs:164
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:95
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The response to the request can be found under a different URI and SHOULD be retrieved using a GET me...
Represents a case-insensitive string.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
CaseInsensitiveString Replace(CaseInsensitiveString oldValue, CaseInsensitiveString newValue)
Returns a new string in which all occurrences of a specified string in the current instance are repla...
Class that monitors login events, and help applications determine malicious intent....
Definition: LoginAuditor.cs:26
static async Task< string > AppendWhoIsInfo(StringBuilder Markdown, string RemoteEndpoint)
Appends WHOIS information to a Markdown document.
static async Task< KeyValuePair< string, object >[]> Annotate(string RemoteEndpoint, params KeyValuePair< string, object >[] Tags)
Annotates a remote endpoint.
bool AllowsPOST
If the POST method is allowed.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Service Module hosting the XMPP broker and its components.
static async Task AppendRemoteEndpointToTable(StringBuilder Markdown, string RemoteEndpoint)
Appends annotated information about a remote endpoint to a Markdown table.
POST Interface for HTTP resources.