Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
5be81dba
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 搜索 >>
提交
5be81dba
编写于
6月 10, 2019
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify for vue admin
上级
5c75b9b0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
47 addition
and
6 deletion
+47
-6
.gitignore
.gitignore
+1
-0
.gitmodules
.gitmodules
+0
-3
IoTSharp/Controllers/AccountController.cs
IoTSharp/Controllers/AccountController.cs
+10
-2
IoTSharp/Data/Enums.cs
IoTSharp/Data/Enums.cs
+2
-0
IoTSharp/Dtos/AccountDto.cs
IoTSharp/Dtos/AccountDto.cs
+3
-1
IoTSharp/Dtos/UserInfoDto.cs
IoTSharp/Dtos/UserInfoDto.cs
+5
-0
IoTSharp/Extensions/TokenExtension.cs
IoTSharp/Extensions/TokenExtension.cs
+26
-0
未找到文件。
.gitignore
浏览文件 @
5be81dba
...
...
@@ -331,3 +331,4 @@ ASALocalRun/
/healthchecksdb
/.vscode
/Clients/MQTTClient/.vscode
/IoTSharp/ClientApp.rar
.gitmodules
已删除
100644 → 0
浏览文件 @
5c75b9b0
[submodule "IoTSharp/ClientApp"]
path = IoTSharp/ClientApp
url = https://github.com/IoTSharp/IoTSharp.ClientApp.git
IoTSharp/Controllers/AccountController.cs
浏览文件 @
5be81dba
...
...
@@ -44,14 +44,21 @@ namespace IoTSharp.Controllers
_logger
=
logger
;
_context
=
context
;
}
[
HttpGet
]
public
ActionResult
<
ApiResult
<
UserInfoDto
>>
MyInfo
()
public
async
Task
<
ActionResult
<
ApiResult
<
UserInfoDto
>
>>
MyInfo
()
{
string
custid
=
_signInManager
.
Context
.
User
.
FindFirstValue
(
IoTSharpClaimTypes
.
Customer
);
var
user
=
await
_userManager
.
GetUserAsync
(
_signInManager
.
Context
.
User
);
var
Customer
=
_context
.
Customer
.
FirstOrDefault
(
c
=>
c
.
Id
.
ToString
()
==
custid
);
var
rooles
=
await
_userManager
.
GetRolesAsync
(
user
);
var
uidto
=
new
UserInfoDto
()
{
Code
=
ApiCode
.
OK
,
Roles
=
string
.
Join
(
','
,
rooles
).
ToLower
().
Contains
(
"admin"
)?
"admin"
:
"editor"
,
//TODO: Permission control
Name
=
user
.
UserName
,
Avatar
=
user
.
Gravatar
(),
Introduction
=
user
.
NormalizedUserName
,
Customer
=
Customer
,
Tenant
=
Customer
.
Tenant
};
...
...
@@ -72,6 +79,7 @@ namespace IoTSharp.Controllers
var
roles
=
await
_userManager
.
GetRolesAsync
(
appUser
);
return
Ok
(
new
LoginResult
()
{
Code
=
ApiCode
.
OK
,
Succeeded
=
result
.
Succeeded
,
Token
=
token
,
UserName
=
appUser
.
UserName
,
...
...
IoTSharp/Data/Enums.cs
浏览文件 @
5be81dba
...
...
@@ -17,6 +17,8 @@ namespace IoTSharp.Data
public
enum
ApiCode
:
int
{
OK
=
2000
,
NotFound
=
404
,
Success
=
10000
,
LoginError
=
10001
,
Exception
=
10002
,
...
...
IoTSharp/Dtos/AccountDto.cs
浏览文件 @
5be81dba
using
System
;
using
IoTSharp.Data
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
...
...
@@ -14,6 +15,7 @@ namespace IoTSharp.Dtos
public
class
LoginResult
{
public
ApiCode
Code
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
Microsoft
.
AspNetCore
.
Identity
.
SignInResult
SignIn
{
get
;
set
;
}
public
bool
Succeeded
{
get
;
set
;
}
...
...
IoTSharp/Dtos/UserInfoDto.cs
浏览文件 @
5be81dba
...
...
@@ -8,6 +8,11 @@ namespace IoTSharp.Dtos
{
public
class
UserInfoDto
{
public
ApiCode
Code
{
get
;
set
;
}
public
string
Roles
{
get
;
set
;}
public
string
Name
{
get
;
set
;
}
public
string
Avatar
{
get
;
set
;
}
public
string
Introduction
{
get
;
set
;
}
public
Customer
Customer
{
get
;
set
;
}
public
Tenant
Tenant
{
get
;
set
;
}
}
...
...
IoTSharp/Extensions/TokenExtension.cs
浏览文件 @
5be81dba
...
...
@@ -12,6 +12,7 @@ using System.Diagnostics;
using
System.IdentityModel.Tokens.Jwt
;
using
System.Linq
;
using
System.Security.Claims
;
using
System.Security.Cryptography
;
using
System.Text
;
using
System.Threading.Tasks
;
...
...
@@ -155,5 +156,30 @@ namespace IoTSharp
{
return
jwtSecurityToken
.
Payload
[
Key
]
as
string
;
}
/// Hashes an email with MD5. Suitable for use with Gravatar profile
/// image urls
public
static
string
Gravatar
(
this
IdentityUser
user
)
{
string
email
=
user
.
Email
;
// Create a new instance of the MD5CryptoServiceProvider object.
MD5
md5Hasher
=
MD5
.
Create
();
// Convert the input string to a byte array and compute the hash.
byte
[]
data
=
md5Hasher
.
ComputeHash
(
Encoding
.
Default
.
GetBytes
(
email
));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder
sBuilder
=
new
StringBuilder
();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for
(
int
i
=
0
;
i
<
data
.
Length
;
i
++)
{
sBuilder
.
Append
(
data
[
i
].
ToString
(
"x2"
));
}
return
string
.
Format
(
"http://www.gravatar.com/avatar/{0}"
,
sBuilder
.
ToString
());
;
// Return the hexadecimal string.
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录