Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
VerifyEMail.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
9using Waher.Script;
13
15{
20 {
24 public VerifyEMail()
25 : base("Account/VerifyEMail",
26 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
27 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
28 {
29 }
30
31 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(VerifyEMail).Namespace + ".JSON.VerifyEMail.req");
32 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(VerifyEMail).Namespace + ".XML.VerifyEMail.req");
33
42 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
43 {
44 AccountUser User = AssertUserAuthenticated(Request, false);
45 string EMail = (string)Parameters["PEMail"].AssociatedObjectValue;
46 double Code = (double)Parameters["PCode"].AssociatedObjectValue;
47
48 if (User.Account.EMail != EMail)
49 throw new BadRequestException("E-mail mismatch.");
50
51 if (User.Account.EMailVerified.HasValue)
52 throw new BadRequestException("E-mail already verified.");
53
54 string OnboardingDomainName = await LegalComponent.GetOnboardingNeuronDomainName();
55
56 if (!(await InternetContent.PostAsync(
57 new Uri("https://" + OnboardingDomainName + "/ID/VerifyNumber.ws"),
58 new Dictionary<string, object>()
59 {
60 { "EMail", EMail },
61 { "Code", (int)Code }
62 },
63 new KeyValuePair<string, string>("Accept", JsonCodec.DefaultContentType))
64 is Dictionary<string, object> Result))
65 {
66 throw new ServiceUnavailableException("Unable to verify mail. Unexpected result");
67 }
68
69 if (!Result.TryGetValue("Status", out object Obj) || !(Obj is bool Status) || !Status)
70 {
71 if (Result.TryGetValue("Message", out Obj) && Obj is string Message)
72 throw new BadRequestException("Unable to verify mail. Error reported: " + Message);
73 else
74 throw new ServiceUnavailableException("Unable to verify mail.");
75 }
76
77 User.Account.EMailVerified = DateTime.UtcNow;
79 User.Account.PhoneNrVerified.HasValue)
80 {
81 User.Account.Enabled = true;
82 }
83
84 await Database.Update(User.Account);
85
86 await Response.Return(new NamedDictionary<string, object>("EMailVerified", AgentNamespace)
87 {
88 { "eMail", EMail },
89 { "userName", User.UserName }
90 });
91 }
92 }
93}
Static class managing encoding and decoding of internet content.
static Task< object > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
const string DefaultContentType
application/json
Definition: JsonCodec.cs:19
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:96
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
Definition: HttpRequest.cs:18
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Represents a case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:626
Class managing a script expression.
Definition: Expression.cs:39
DateTime? PhoneNrVerified
When Phone Number was verified.
Definition: Account.cs:277
CaseInsensitiveString EMail
E-mail address associated with account.
Definition: Account.cs:129
DateTime? EMailVerified
When e-Mail was verified.
Definition: Account.cs:268
CaseInsensitiveString PhoneNr
Phone number associated with account.
Definition: Account.cs:138
Verifies an e-mail address corresponding to an account.
Definition: VerifyEMail.cs:20
VerifyEMail()
Verifies an e-mail address corresponding to an account.
Definition: VerifyEMail.cs:24
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
Definition: VerifyEMail.cs:42
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd