Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AgeAuthenticator.cs
1using Paiwise;
2using System;
3using System.Threading.Tasks;
4using Waher.Content;
6
8{
13 {
18 {
19 }
20
24 public Task Start()
25 {
26 return Task.CompletedTask;
27 }
28
32 public Task Stop()
33 {
34 return Task.CompletedTask;
35 }
36
43 {
44 PersonalInformation PI = Application.PersonalInformation;
45
46 if (PI.BirthDate.HasValue && PI.AgeAbove.HasValue)
47 return Grade.Perfect;
48 else
49 return Grade.NotAtAll;
50 }
51
56 public Task Validate(IIdentityApplication Application)
57 {
58 try
59 {
60 PersonalInformation PI = Application.PersonalInformation;
61 DateTime Now = DateTime.Now;
62
63 if (!PI.BirthDate.HasValue || !PI.AgeAbove.HasValue)
64 return Task.CompletedTask;
65
66 if (PI.BirthDate.Value > Now)
67 {
68 Application.ClaimInvalid(PersonalInformation.BirthDayTag, "Birth date is in the future.", "en", "FutureBirthDate", this);
69 Application.ClaimInvalid(PersonalInformation.BirthMonthTag, "Birth date is in the future.", "en", "FutureBirthDate", this);
70 Application.ClaimInvalid(PersonalInformation.BirthYearTag, "Birth date is in the future.", "en", "FutureBirthDate", this);
71 return Task.CompletedTask;
72 }
73
75
76 if (D.Years < PI.AgeAbove.Value)
77 {
78 Application.ClaimInvalid(PersonalInformation.AgeAboveTag, "Age only above " + D.Years.ToString(), "en", "AgeNotReached", this);
79 return Task.CompletedTask;
80 }
81
82 Application.ClaimValid(PersonalInformation.AgeAboveTag, this);
83 }
84 catch (Exception ex)
85 {
86 Application.ReportError(ex.Message, string.Empty, string.Empty,
87 ValidationErrorType.Service, this);
88 }
89
90 return Task.CompletedTask;
91 }
92 }
93}
Contains personal information found in a legal identity.
const string AgeAboveTag
AGEABOVE
int? AgeAbove
Age above the stated number of years
const string BirthMonthTag
BMONTH
Interface for identity applications.
Interface for identity application authenticator services.
ValidationErrorType
Type of validation error.
Grade
Grade enumeration
Definition: Grade.cs:7
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:14
int Years
Number of years.
Definition: Duration.cs:131
static Duration GetDurationBetween(System.DateTime From, System.DateTime To)
Calculates the duration between two dates.
Definition: Duration.cs:694