|
|
|
@ -67,7 +67,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult GetProducts(string token)
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var model = new
|
|
|
|
|
{
|
|
|
|
|
Products = this._productRepo.ReadOnlyTable().Select(o => new
|
|
|
|
@ -85,7 +89,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult GetNodes(string token)
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var model = this._nodeRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Scenes)
|
|
|
|
|
.OrderBy(o => o.DisplayOrder)
|
|
|
|
@ -106,7 +114,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult GetNode(string token, string number)
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var model = this._nodeRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Scenes)
|
|
|
|
|
.Include(o => o.Devices)
|
|
|
|
@ -119,7 +131,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult GetProduct(string token, string number)
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var model = this._productRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Devices)
|
|
|
|
|
.ThenInclude(o => o.Data)
|
|
|
|
@ -131,7 +147,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult GetDevice(string token, string number)
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var model = this._deviceRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Data)
|
|
|
|
|
.Include(o => o.Product)
|
|
|
|
@ -144,7 +164,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult GetTemplate(string token, string number)
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var node = _nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == number);
|
|
|
|
|
var template = string.IsNullOrEmpty(token) ? node.Template : node.MobileTemplate;
|
|
|
|
|
if (!string.IsNullOrEmpty(template))
|
|
|
|
@ -162,7 +186,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
CallApi(connectionId, number, method);
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
@ -178,7 +206,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
foreach (var number in numbers)
|
|
|
|
|
{
|
|
|
|
|
this.CallApi(connectionId, number, method);
|
|
|
|
@ -197,7 +229,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var command = this._commandRepo.ReadOnlyTable().Include(o => o.Device).ThenInclude(o => o.Node).FirstOrDefault(o => o.Id == id);
|
|
|
|
|
this._hub.ServerToClient(Methods.ExecCommand, command.Id, command.Device.Node.Number, connectionId);
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
@ -214,7 +250,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var scene = this._sceneRepo.ReadOnlyTable().Include(o => o.Node).FirstOrDefault(o => o.Id == id);
|
|
|
|
|
if (scene.NodeId != null)
|
|
|
|
|
{
|
|
|
|
@ -234,6 +274,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var commands = this._sceneCommandRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Command).ThenInclude(o => o.Device).ThenInclude(o => o.Node)
|
|
|
|
|
.Where(o => o.SceneId == id)
|
|
|
|
@ -261,7 +306,11 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult GetChartData(string token, string number, string time)
|
|
|
|
|
{
|
|
|
|
|
var userName = User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var userName = this.GetUserName(token);
|
|
|
|
|
if (string.IsNullOrEmpty(userName))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Data).FirstOrDefault(o => o.Number == number);
|
|
|
|
|
var url = this._configuration["influxdb:url"];
|
|
|
|
|
var usr = this._configuration["influxdb:usr"];
|
|
|
|
@ -349,7 +398,20 @@ namespace IoTCenter.Controllers
|
|
|
|
|
{
|
|
|
|
|
return Color.FromKnownColor(KnownColor.Orange).Name;
|
|
|
|
|
}
|
|
|
|
|
return Color.FromKnownColor(KnownColor.Blue).Name;
|
|
|
|
|
return Color.FromKnownColor(KnownColor.DarkBlue).Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetUserName(string token)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return User.Identity.IsAuthenticated ? User.Identity.Name : this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************************************************/
|
|
|
|
|