Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
5673d1e6
IoTSharp
项目概览
IoTSharp
/
IoTSharp
10 个月 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5673d1e6
编写于
1月 05, 2019
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add other api
上级
3d1e790e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
319 addition
and
73 deletion
+319
-73
IoTSharp.Hub/Controllers/AccountController.cs
IoTSharp.Hub/Controllers/AccountController.cs
+2
-70
IoTSharp.Hub/Controllers/CustomersController.cs
IoTSharp.Hub/Controllers/CustomersController.cs
+105
-0
IoTSharp.Hub/Controllers/DevicesController.cs
IoTSharp.Hub/Controllers/DevicesController.cs
+105
-0
IoTSharp.Hub/Controllers/InstallerController.cs
IoTSharp.Hub/Controllers/InstallerController.cs
+1
-3
IoTSharp.Hub/Controllers/TenantsController.cs
IoTSharp.Hub/Controllers/TenantsController.cs
+105
-0
IoTSharp.Hub/IoTSharp.Hub.csproj
IoTSharp.Hub/IoTSharp.Hub.csproj
+1
-0
未找到文件。
IoTSharp.Hub/Controllers/AccountController.cs
浏览文件 @
5673d1e6
...
...
@@ -64,58 +64,6 @@ namespace IoTSharp.Hub.Controllers
return
actionResult
;
}
[
AllowAnonymous
]
[
HttpPost
]
public
async
Task
<
IActionResult
>
Install
([
FromBody
]
InstallDto
model
)
{
IActionResult
actionResult
=
NoContent
();
try
{
var
tenant
=
new
Tenant
()
{
Id
=
Guid
.
NewGuid
(),
Name
=
model
.
TenantName
,
EMail
=
model
.
TenantEMail
};
var
customer
=
new
Customer
()
{
Id
=
Guid
.
NewGuid
(),
Name
=
model
.
CustomerName
,
Email
=
model
.
CustomerEMail
};
customer
.
Tenant
=
tenant
;
tenant
.
Customers
=
new
List
<
Customer
>();
tenant
.
Customers
.
Add
(
customer
);
tenant
.
Customers
.
Add
(
customer
);
var
user
=
new
IdentityUser
{
Email
=
model
.
AdminEmail
,
UserName
=
model
.
UserName
,
PhoneNumber
=
model
.
PhoneNumber
};
var
result
=
await
_userManager
.
CreateAsync
(
user
,
model
.
Password
);
if
(
result
.
Succeeded
)
{
_context
.
Tenant
.
Add
(
tenant
);
_context
.
Customer
.
Add
(
customer
);
await
_signInManager
.
SignInAsync
(
user
,
false
);
await
_signInManager
.
UserManager
.
AddClaimAsync
(
user
,
new
Claim
(
ClaimTypes
.
Email
,
model
.
AdminEmail
));
var
cust
=
_context
.
Customer
.
FirstOrDefault
(
c
=>
c
.
Name
==
model
.
CustomerName
);
if
(
cust
!=
null
)
{
await
_signInManager
.
UserManager
.
AddClaimAsync
(
user
,
new
Claim
(
ClaimTypes
.
GroupSid
,
cust
.
Id
.
ToString
()));
actionResult
=
Ok
(
new
{
code
=
0
,
msg
=
"OK"
,
data
=
GenerateJwtToken
(
model
.
AdminEmail
,
user
)
});
}
}
else
{
var
msg
=
from
e
in
result
.
Errors
select
$"
{
e
.
Code
}
:
{
e
.
Description
}
\r\n"
;
actionResult
=
BadRequest
(
new
{
code
=
-
3
,
msg
=
string
.
Join
(
';'
,
msg
.
ToArray
())
});
}
}
catch
(
Exception
ex
)
{
actionResult
=
BadRequest
(
new
{
code
=
-
2
,
msg
=
ex
.
Message
,
data
=
ex
});
_logger
.
LogError
(
ex
,
ex
.
Message
);
}
return
actionResult
;
}
/// <summary>
/// Register a user
/// </summary>
...
...
@@ -193,35 +141,19 @@ namespace IoTSharp.Hub.Controllers
[
Required
]
public
string
Email
{
get
;
set
;
}
}
public
class
RegisterDto
{
[
Required
]
public
string
Email
{
get
;
set
;
}
[
Required
]
public
string
CustomerName
{
get
;
set
;
}
[
Required
]
[
StringLength
(
100
,
ErrorMessage
=
"PASSWORD_MIN_LENGTH"
,
MinimumLength
=
6
)]
public
string
Password
{
get
;
set
;
}
}
public
class
InstallDto
{
[
Required
]
public
string
AdminEmail
{
get
;
set
;
}
[
Required
]
public
string
CustomerName
{
get
;
set
;
}
[
Required
]
[
StringLength
(
100
,
ErrorMessage
=
"PASSWORD_MIN_LENGTH"
,
MinimumLength
=
6
)]
public
string
Password
{
get
;
set
;
}
public
string
TenantName
{
get
;
set
;
}
public
string
TenantEMail
{
get
;
set
;
}
public
string
CustomerEMail
{
get
;
set
;
}
public
string
UserName
{
get
;
internal
set
;
}
public
string
PhoneNumber
{
get
;
internal
set
;
}
}
}
}
\ No newline at end of file
IoTSharp.Hub/Controllers/CustomersController.cs
0 → 100644
浏览文件 @
5673d1e6
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
IoTSharp.Hub.Data
;
namespace
IoTSharp.Hub.Controllers
{
[
Route
(
"api/[controller]"
)]
[
ApiController
]
public
class
CustomersController
:
ControllerBase
{
private
readonly
ApplicationDbContext
_context
;
public
CustomersController
(
ApplicationDbContext
context
)
{
_context
=
context
;
}
// GET: api/Customers
[
HttpGet
]
public
async
Task
<
ActionResult
<
IEnumerable
<
Customer
>>>
GetCustomer
()
{
return
await
_context
.
Customer
.
ToListAsync
();
}
// GET: api/Customers/5
[
HttpGet
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Customer
>>
GetCustomer
(
Guid
id
)
{
var
customer
=
await
_context
.
Customer
.
FindAsync
(
id
);
if
(
customer
==
null
)
{
return
NotFound
();
}
return
customer
;
}
// PUT: api/Customers/5
[
HttpPut
(
"{id}"
)]
public
async
Task
<
IActionResult
>
PutCustomer
(
Guid
id
,
Customer
customer
)
{
if
(
id
!=
customer
.
Id
)
{
return
BadRequest
();
}
_context
.
Entry
(
customer
).
State
=
EntityState
.
Modified
;
try
{
await
_context
.
SaveChangesAsync
();
}
catch
(
DbUpdateConcurrencyException
)
{
if
(!
CustomerExists
(
id
))
{
return
NotFound
();
}
else
{
throw
;
}
}
return
NoContent
();
}
// POST: api/Customers
[
HttpPost
]
public
async
Task
<
ActionResult
<
Customer
>>
PostCustomer
(
Customer
customer
)
{
_context
.
Customer
.
Add
(
customer
);
await
_context
.
SaveChangesAsync
();
return
CreatedAtAction
(
"GetCustomer"
,
new
{
id
=
customer
.
Id
},
customer
);
}
// DELETE: api/Customers/5
[
HttpDelete
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Customer
>>
DeleteCustomer
(
Guid
id
)
{
var
customer
=
await
_context
.
Customer
.
FindAsync
(
id
);
if
(
customer
==
null
)
{
return
NotFound
();
}
_context
.
Customer
.
Remove
(
customer
);
await
_context
.
SaveChangesAsync
();
return
customer
;
}
private
bool
CustomerExists
(
Guid
id
)
{
return
_context
.
Customer
.
Any
(
e
=>
e
.
Id
==
id
);
}
}
}
IoTSharp.Hub/Controllers/DevicesController.cs
0 → 100644
浏览文件 @
5673d1e6
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
IoTSharp.Hub.Data
;
namespace
IoTSharp.Hub.Controllers
{
[
Route
(
"api/[controller]"
)]
[
ApiController
]
public
class
DevicesController
:
ControllerBase
{
private
readonly
ApplicationDbContext
_context
;
public
DevicesController
(
ApplicationDbContext
context
)
{
_context
=
context
;
}
// GET: api/Devices
[
HttpGet
]
public
async
Task
<
ActionResult
<
IEnumerable
<
Device
>>>
GetDevice
()
{
return
await
_context
.
Device
.
ToListAsync
();
}
// GET: api/Devices/5
[
HttpGet
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Device
>>
GetDevice
(
Guid
id
)
{
var
device
=
await
_context
.
Device
.
FindAsync
(
id
);
if
(
device
==
null
)
{
return
NotFound
();
}
return
device
;
}
// PUT: api/Devices/5
[
HttpPut
(
"{id}"
)]
public
async
Task
<
IActionResult
>
PutDevice
(
Guid
id
,
Device
device
)
{
if
(
id
!=
device
.
Id
)
{
return
BadRequest
();
}
_context
.
Entry
(
device
).
State
=
EntityState
.
Modified
;
try
{
await
_context
.
SaveChangesAsync
();
}
catch
(
DbUpdateConcurrencyException
)
{
if
(!
DeviceExists
(
id
))
{
return
NotFound
();
}
else
{
throw
;
}
}
return
NoContent
();
}
// POST: api/Devices
[
HttpPost
]
public
async
Task
<
ActionResult
<
Device
>>
PostDevice
(
Device
device
)
{
_context
.
Device
.
Add
(
device
);
await
_context
.
SaveChangesAsync
();
return
CreatedAtAction
(
"GetDevice"
,
new
{
id
=
device
.
Id
},
device
);
}
// DELETE: api/Devices/5
[
HttpDelete
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Device
>>
DeleteDevice
(
Guid
id
)
{
var
device
=
await
_context
.
Device
.
FindAsync
(
id
);
if
(
device
==
null
)
{
return
NotFound
();
}
_context
.
Device
.
Remove
(
device
);
await
_context
.
SaveChangesAsync
();
return
device
;
}
private
bool
DeviceExists
(
Guid
id
)
{
return
_context
.
Device
.
Any
(
e
=>
e
.
Id
==
id
);
}
}
}
IoTSharp.Hub/Controllers/InstallerController.cs
浏览文件 @
5673d1e6
...
...
@@ -79,7 +79,7 @@ namespace IoTSharp.Hub.Controllers
var
user
=
new
IdentityUser
{
Email
=
model
.
Email
,
UserName
=
model
.
UserName
,
UserName
=
model
.
Email
,
PhoneNumber
=
model
.
PhoneNumber
};
...
...
@@ -144,8 +144,6 @@ namespace IoTSharp.Hub.Controllers
[
EmailAddress
]
public
string
CustomerEMail
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
[
Phone
]
public
string
PhoneNumber
{
get
;
set
;
}
}
...
...
IoTSharp.Hub/Controllers/TenantsController.cs
0 → 100644
浏览文件 @
5673d1e6
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
IoTSharp.Hub.Data
;
namespace
IoTSharp.Hub.Controllers
{
[
Route
(
"api/[controller]"
)]
[
ApiController
]
public
class
TenantsController
:
ControllerBase
{
private
readonly
ApplicationDbContext
_context
;
public
TenantsController
(
ApplicationDbContext
context
)
{
_context
=
context
;
}
// GET: api/Tenants
[
HttpGet
]
public
async
Task
<
ActionResult
<
IEnumerable
<
Tenant
>>>
GetTenant
()
{
return
await
_context
.
Tenant
.
ToListAsync
();
}
// GET: api/Tenants/5
[
HttpGet
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Tenant
>>
GetTenant
(
Guid
id
)
{
var
tenant
=
await
_context
.
Tenant
.
FindAsync
(
id
);
if
(
tenant
==
null
)
{
return
NotFound
();
}
return
tenant
;
}
// PUT: api/Tenants/5
[
HttpPut
(
"{id}"
)]
public
async
Task
<
IActionResult
>
PutTenant
(
Guid
id
,
Tenant
tenant
)
{
if
(
id
!=
tenant
.
Id
)
{
return
BadRequest
();
}
_context
.
Entry
(
tenant
).
State
=
EntityState
.
Modified
;
try
{
await
_context
.
SaveChangesAsync
();
}
catch
(
DbUpdateConcurrencyException
)
{
if
(!
TenantExists
(
id
))
{
return
NotFound
();
}
else
{
throw
;
}
}
return
NoContent
();
}
// POST: api/Tenants
[
HttpPost
]
public
async
Task
<
ActionResult
<
Tenant
>>
PostTenant
(
Tenant
tenant
)
{
_context
.
Tenant
.
Add
(
tenant
);
await
_context
.
SaveChangesAsync
();
return
CreatedAtAction
(
"GetTenant"
,
new
{
id
=
tenant
.
Id
},
tenant
);
}
// DELETE: api/Tenants/5
[
HttpDelete
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Tenant
>>
DeleteTenant
(
Guid
id
)
{
var
tenant
=
await
_context
.
Tenant
.
FindAsync
(
id
);
if
(
tenant
==
null
)
{
return
NotFound
();
}
_context
.
Tenant
.
Remove
(
tenant
);
await
_context
.
SaveChangesAsync
();
return
tenant
;
}
private
bool
TenantExists
(
Guid
id
)
{
return
_context
.
Tenant
.
Any
(
e
=>
e
.
Id
==
id
);
}
}
}
IoTSharp.Hub/IoTSharp.Hub.csproj
浏览文件 @
5673d1e6
...
...
@@ -43,6 +43,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="MQTTnet" Version="2.8.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
<PackageReference Include="NSwag.AspNetCore" Version="12.0.7" />
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录