Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LegalIdentityStateChanged.cs
1using System;
3using System.Threading.Tasks;
4using Waher.Content;
11
13{
15 {
17 : base("/LegalIdentityStateChanged")
18 {
19 }
20
21 public override bool HandlesSubPaths => false;
22 public override bool UserSessions => true;
23 public bool AllowsPOST => true;
24
25 public async Task POST(HttpRequest Request, HttpResponse Response)
26 {
27 Gateway.AssertUserAuthenticated(Request, "Admin.Notarius.Identities");
28 // TODO: OR Admin.Notarius.PendingIdentities
29
30 if (!Request.HasData)
31 {
32 await Response.SendResponse(new BadRequestException());
33 return;
34 }
35
36 ContentResponse Content = await Request.DecodeDataAsync();
37 if (Content.HasError || !(Content.Decoded is Dictionary<string, object> Obj))
38 {
39 await Response.SendResponse(new BadRequestException());
40 return;
41 }
42
43 if (!Obj.TryGetValue("id", out object Obj2) || !(Obj2 is string Id) ||
44 !Obj.TryGetValue("state", out Obj2) || !(Obj2 is string s) ||
45 !Enum.TryParse(s, out IdentityState State))
46 {
47 await Response.SendResponse(new BadRequestException());
48 return;
49 }
50
51 KeyValuePair<LegalIdentity, bool> P = await LegalComponent.GetLocalLegalIdentity(Id, true);
52 LegalIdentity Identity = P.Key;
53 bool Preview = P.Value;
54
55 if (Identity is null)
56 {
57 await Response.SendResponse(new NotFoundException());
58 return;
59 }
60
61 IAccount Account = await XmppServerModule.GetAccountAsync(Identity.Account);
62 if (Account is null)
63 {
64 await Response.SendResponse(new ForbiddenException(Request, "Account has been removed."));
65 return;
66 }
67
68 if (!Account.Enabled)
69 {
70 await Response.SendResponse(new ForbiddenException(Request, "Account has been disabled."));
71 return;
72 }
73
74 await XmppServerModule.Legal.UpdateState(Identity, State, Request.RemoteEndPoint,
75 Account as DataStorage.Account, Preview, true, null);
76
77 Response.StatusCode = 200;
78 Response.StatusMessage = "OK";
79 Response.ContentType = JsonCodec.DefaultContentType;
80 await Response.Write("true");
81 }
82 }
83}
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
const string DefaultContentType
application/json
Definition: JsonCodec.cs:20
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
Definition: Gateway.cs:3868
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:22
string RemoteEndPoint
Remote end-point.
Definition: HttpRequest.cs:243
bool HasData
If the request has data.
Definition: HttpRequest.cs:113
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:139
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Task Write(byte[] Data)
Returns binary data in the response.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Service Module hosting the XMPP broker and its components.
POST Interface for HTTP resources.
bool Enabled
If the account is enabled.
Definition: IAccount.cs:40
Interface for XMPP user accounts.
Definition: IAccount.cs:9