Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
bbf6246a
IoTSharp
项目概览
IoTSharp
/
IoTSharp
9 个月 前同步成功
通知
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 搜索 >>
提交
bbf6246a
编写于
5月 19, 2019
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add user get list and create new user
上级
959a6c14
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
6 deletion
+40
-6
IoTSharp/Controllers/AccountController.cs
IoTSharp/Controllers/AccountController.cs
+27
-3
IoTSharp/Dtos/AccountDto.cs
IoTSharp/Dtos/AccountDto.cs
+13
-3
未找到文件。
IoTSharp/Controllers/AccountController.cs
浏览文件 @
bbf6246a
...
...
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.IdentityModel.Tokens
;
...
...
@@ -119,7 +120,9 @@ namespace IoTSharp.Controllers
{
var
user
=
new
IdentityUser
{
Email
=
model
.
Email
Email
=
model
.
Email
,
UserName
=
model
.
Email
,
PhoneNumber
=
model
.
PhoneNumber
};
var
result
=
await
_userManager
.
CreateAsync
(
user
,
model
.
Password
);
...
...
@@ -127,14 +130,14 @@ namespace IoTSharp.Controllers
{
await
_signInManager
.
SignInAsync
(
user
,
false
);
await
_signInManager
.
UserManager
.
AddClaimAsync
(
user
,
new
Claim
(
ClaimTypes
.
Email
,
model
.
Email
));
var
customer
=
_context
.
Customer
.
FirstOrDefault
(
c
=>
c
.
Name
==
model
.
CustomerName
);
var
customer
=
await
_context
.
Customer
.
Include
(
c
=>
c
.
Tenant
).
FirstOrDefaultAsync
(
c
=>
c
.
Id
==
model
.
CustomerId
);
if
(
customer
!=
null
)
{
await
_signInManager
.
UserManager
.
AddClaimAsync
(
user
,
new
Claim
(
ClaimTypes
.
Email
,
model
.
Email
));
await
_signInManager
.
UserManager
.
AddClaimAsync
(
user
,
new
Claim
(
IoTSharpClaimTypes
.
Customer
,
customer
.
Id
.
ToString
()));
await
_signInManager
.
UserManager
.
AddClaimAsync
(
user
,
new
Claim
(
IoTSharpClaimTypes
.
Tenant
,
customer
.
Tenant
.
Id
.
ToString
()));
await
_signInManager
.
UserManager
.
AddToRolesAsync
(
user
,
new
[]
{
nameof
(
UserRole
.
NormalUser
)
});
actionResult
=
CreatedAtAction
(
nameof
(
this
.
Login
),
new
LoginDto
()
{
UserName
=
model
.
Email
,
Password
=
model
.
Password
});
actionResult
=
CreatedAtAction
(
nameof
(
this
.
Login
),
new
LoginDto
()
{
UserName
=
model
.
Email
,
Password
=
model
.
Password
});
}
}
else
...
...
@@ -151,5 +154,26 @@ namespace IoTSharp.Controllers
return
actionResult
;
}
[
HttpGet
(
"{customerId}"
)]
public
async
Task
<
ActionResult
<
List
<
UserItemDto
>>>
All
(
Guid
customerId
)
{
List
<
UserItemDto
>
dtos
=
new
List
<
UserItemDto
>();
var
users
=
await
_userManager
.
GetUsersForClaimAsync
(
_signInManager
.
Context
.
User
.
FindFirst
(
m
=>
m
.
Type
==
IoTSharpClaimTypes
.
Customer
&&
m
.
Value
==
customerId
.
ToString
()));
users
.
ToList
().
ForEach
(
async
c
=>
{
var
uid
=
new
UserItemDto
()
{
Id
=
c
.
Id
,
Email
=
c
.
Email
,
Roles
=
new
List
<
string
>(
await
_userManager
.
GetRolesAsync
(
c
)),
PhoneNumber
=
c
.
PhoneNumber
,
AccessFailedCount
=
c
.
AccessFailedCount
};
dtos
.
Add
(
uid
);
});
return
dtos
;
}
}
}
\ No newline at end of file
IoTSharp/Dtos/AccountDto.cs
浏览文件 @
bbf6246a
...
...
@@ -18,7 +18,7 @@ namespace IoTSharp.Dtos
public
Microsoft
.
AspNetCore
.
Identity
.
SignInResult
SignIn
{
get
;
set
;
}
public
bool
Succeeded
{
get
;
set
;
}
public
TokenEntity
Token
{
get
;
set
;
}
public
IList
<
string
>
Roles
{
get
;
set
;
}
public
IList
<
string
>
Roles
{
get
;
set
;
}
}
public
class
LoginDto
...
...
@@ -34,12 +34,22 @@ namespace IoTSharp.Dtos
{
[
Required
]
public
string
Email
{
get
;
set
;
}
[
Required
]
public
string
CustomerName
{
get
;
set
;
}
public
string
PhoneNumber
{
get
;
set
;
}
[
Required
]
public
Guid
CustomerId
{
get
;
set
;
}
[
Required
]
[
StringLength
(
100
,
ErrorMessage
=
"PASSWORD_MIN_LENGTH"
,
MinimumLength
=
6
)]
public
string
Password
{
get
;
set
;
}
}
public
class
UserItemDto
{
public
string
Email
{
get
;
set
;
}
public
List
<
string
>
Roles
{
get
;
set
;
}
=
new
List
<
string
>();
public
string
PhoneNumber
{
get
;
set
;
}
public
int
AccessFailedCount
{
get
;
set
;
}
public
string
Id
{
get
;
set
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录