Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DeleteAccount.cs
1using System.Threading.Tasks;
2using Waher.Content;
6
8{
10 {
11 public DeleteAccount()
12 : base("/DeleteAccount")
13 {
14 }
15
16 public override bool HandlesSubPaths => false;
17 public override bool UserSessions => true;
18 public bool AllowsPOST => true;
19
20 public async Task POST(HttpRequest Request, HttpResponse Response)
21 {
22 Gateway.AssertUserAuthenticated(Request, "Admin.Broker.Accounts");
23
24 if (!Request.HasData)
25 {
26 await Response.SendResponse(new BadRequestException());
27 return;
28 }
29
30 ContentResponse Content = await Request.DecodeDataAsync();
31 if (Content.HasError || !(Content.Decoded is string UserName))
32 {
33 await Response.SendResponse(new BadRequestException());
34 return;
35 }
36
37 DataStorage.PersistenceLayer PersistenceLayer = XmppServerModule.PersistenceLayer ?? new DataStorage.PersistenceLayer();
38 await PersistenceLayer.DeleteAccount(UserName, Request.RemoteEndPoint);
39
40 Response.StatusCode = 200;
41 Response.StatusMessage = "OK";
42 Response.ContentType = PlainTextCodec.DefaultContentType;
43 await Response.Write("1");
44 }
45 }
46}
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Plain text encoder/decoder.
const string DefaultContentType
text/plain
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...
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...
async Task< bool > DeleteAccount(CaseInsensitiveString UserName, string RemoteEndPoint)
Deletes an account.
bool AllowsPOST
If the POST method is allowed.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
POST Interface for HTTP resources.