public static Task Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] Message message, [SignalR(HubName = "Messages")] IAsyncCollector <SignalRMessage> signalRMessages) { var table = TableUtilities.GetCloudTable("Applications"); var operation = TableOperation.Retrieve <ApplicationEntity>(message.GroupId, message.ApplicationId); var result = table.Execute(operation); var application = result.Result as ApplicationEntity; if (application == null) { return(Task.CompletedTask); } if (application.Password.Equals(message.Password) == false) { return(Task.CompletedTask); } // Will return completed even if the password was incorrect, however, it will not do // What it was asked to do if that's the case. return(signalRMessages.AddAsync( new SignalRMessage { Target = message.GroupId, Arguments = new[] { message.Content } })); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post")] ApplicationInfo info, ILogger log) { var table = TableUtilities.GetCloudTable("Applications"); var operation = TableOperation.Retrieve <ApplicationEntity>(info.GroupId, info.ApplicationId); var result = await table.ExecuteAsync(operation); var application = result.Result as ApplicationEntity; if (application == null) { return(new NotFoundResult()); } if (application.Password.Equals(info.Password) == false) { return(new UnauthorizedResult()); } operation = TableOperation.Delete(application); await table.ExecuteAsync(operation); return(new NoContentResult()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post")] ApplicationInfo info, ILogger log) { var table = TableUtilities.GetCloudTable("Applications"); var operation = TableOperation.Retrieve <ApplicationEntity>(info.GroupId, info.ApplicationId); var result = await table.ExecuteAsync(operation); var application = result.Result as ApplicationEntity; if (application != null) { return(new ConflictResult()); } var query = table.CreateQuery <ApplicationEntity>() .Where(p => p.PartitionKey.Equals(info.GroupId)) .AsTableQuery(); var entities = await table.ExecuteQueryAsync(query); if (entities.Count > 0 && entities.First().Password.Equals(info.Password) == false) { return(new UnauthorizedResult()); } operation = TableOperation.Insert(new ApplicationEntity { PartitionKey = info.GroupId, RowKey = info.ApplicationId, MachineName = info.MachineName, Password = info.Password }); await table.ExecuteAsync(operation); return(new NoContentResult()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] ChangePasswordInfo info, ILogger log) { var table = TableUtilities.GetCloudTable("Applications"); var operation = TableOperation.Retrieve <ApplicationEntity>(info.GroupId, info.ApplicationId); var result = await table.ExecuteAsync(operation); var application = result.Result as ApplicationEntity; if (application == null) { return(new NotFoundResult()); } if (application.Password.Equals(info.Password) == false) { return(new UnauthorizedResult()); } var query = table.CreateQuery <ApplicationEntity>() .Where(p => p.PartitionKey.Equals(info.GroupId)) .AsTableQuery(); var entities = await table.ExecuteQueryAsync(query); var batch = new TableBatchOperation(); foreach (var entity in entities) { entity.Password = info.NewPassword; batch.Replace(entity); } await table.ExecuteBatchAsync(batch); return(new NoContentResult()); }