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;
2using System.Collections.Generic;
3using System.Threading.Tasks;
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 // TODO: Remove on lab neuron, rights for QA testers to view all identities.
30
31 if (!Request.HasData)
32 throw new BadRequestException();
33
34 if (!(await Request.DecodeDataAsync() is Dictionary<string, object> Obj))
35 throw new BadRequestException();
36
37 if (!Obj.TryGetValue("id", out object Obj2) || !(Obj2 is string Id) ||
38 !Obj.TryGetValue("state", out Obj2) || !(Obj2 is string s) ||
39 !Enum.TryParse(s, out IdentityState State))
40 {
41 throw new BadRequestException();
42 }
43
44 LegalIdentity Identity = await Database.FindFirstDeleteRest<LegalIdentity>(new FilterFieldEqualTo("Id", Id))
45 ?? throw new NotFoundException();
46
47 IAccount Account = await XmppServerModule.GetAccountAsync(Identity.Account)
48 ?? throw new ForbiddenException("Account has been removed.");
49
50 if (!Account.Enabled)
51 throw new ForbiddenException("Account has been disabled.");
52
53 await XmppServerModule.Legal.UpdateState(Identity, State, Request.RemoteEndPoint, Account as DataStorage.Account);
54
55 Response.StatusCode = 200;
56 Response.ContentType = JsonCodec.DefaultContentType;
57 await Response.Write("true");
58 }
59 }
60}
const string DefaultContentType
application/json
Definition: JsonCodec.cs:19
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
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:3041
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
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
async 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...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
This filter selects objects that have a named field equal to a given value.
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