Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
17a5f485
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 搜索 >>
提交
17a5f485
编写于
11月 23, 2020
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
实现基本的登录界面和右上角的个人信息显示
上级
e8382c81
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
122 addition
and
25 deletion
+122
-25
IoTSharp.ClientApp/Layouts/BasicLayout.razor
IoTSharp.ClientApp/Layouts/BasicLayout.razor
+11
-4
IoTSharp.ClientApp/Pages/User/Login/Login.razor
IoTSharp.ClientApp/Pages/User/Login/Login.razor
+1
-1
IoTSharp.ClientApp/Pages/User/Login/Login.razor.cs
IoTSharp.ClientApp/Pages/User/Login/Login.razor.cs
+7
-5
IoTSharp.ClientApp/Program.cs
IoTSharp.ClientApp/Program.cs
+9
-2
IoTSharp.ClientApp/Services/AccountService.cs
IoTSharp.ClientApp/Services/AccountService.cs
+9
-4
IoTSharp.ClientApp/Services/UserService.cs
IoTSharp.ClientApp/Services/UserService.cs
+13
-2
IoTSharp.ClientApp/wwwroot/appsettings.json
IoTSharp.ClientApp/wwwroot/appsettings.json
+1
-0
IoTSharp.ClientApp/wwwroot/css/site.css
IoTSharp.ClientApp/wwwroot/css/site.css
+1
-1
IoTSharp.SDKs/IoTSharp.Sdk.CSharp/IoTSharp.Sdk.Http.csproj
IoTSharp.SDKs/IoTSharp.Sdk.CSharp/IoTSharp.Sdk.Http.csproj
+3
-6
IoTSharp.SDKs/IoTSharp.Sdk.CSharp/IoTSharpClient.cs
IoTSharp.SDKs/IoTSharp.Sdk.CSharp/IoTSharpClient.cs
+67
-0
未找到文件。
IoTSharp.ClientApp/Layouts/BasicLayout.razor
浏览文件 @
17a5f485
@namespace IoTSharp.ClientApp
@namespace IoTSharp.ClientApp
@inherits LayoutComponentBase
<AntDesign.Pro.Layout.BasicLayout
...
...
@@ -12,15 +13,21 @@
</ChildContent>
</AntDesign.Pro.Layout.BasicLayout>
<SettingDrawer />
@using IoTSharp.Sdk.Http;
@inject HttpClient HttpClient
@inject IoTSharpClient client
@inject NavigationManager NavigationManager
@code
{
private MenuDataItem[] MenuData { get; set; } = {};
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
MenuData = await HttpClient.GetFromJsonAsync<MenuDataItem[]>("data/menu.json");
await base.OnInitializedAsync();
MenuData = await HttpClient.GetFromJsonAsync<MenuDataItem[]>("data/menu.json");
if (!client.IsLogin)
{
NavigationManager.NavigateTo("/user/login");
}
}
}
\ No newline at end of file
IoTSharp.ClientApp/Pages/User/Login/Login.razor
浏览文件 @
17a5f485
...
...
@@ -4,7 +4,7 @@
<div class="main__b__0">
<div class="login">
<Form Model="@_model" OnFinish="HandleSubmit">
<Form Model="@_model" OnFinish="HandleSubmit
Async
">
<Tabs ActiveKey="@context.LoginType">
<TabPane Key="1">
<Tab>账户密码登录</Tab>
...
...
IoTSharp.ClientApp/Pages/User/Login/Login.razor.cs
浏览文件 @
17a5f485
...
...
@@ -16,15 +16,17 @@ namespace IoTSharp.ClientApp.Pages.User
[
Inject
]
public
MessageService
Message
{
get
;
set
;
}
public
void
HandleSubmit
()
public
async
Task
HandleSubmitAsync
()
{
if
(
_model
.
UserName
==
"admin"
&&
_model
.
Password
==
"ant.design"
)
var
ok
=
await
AccountService
.
LoginAsync
(
_model
);
if
(
ok
)
{
NavigationManager
.
NavigateTo
(
"/"
);
return
;
}
if
(
_model
.
UserName
==
"user"
&&
_model
.
Password
==
"ant.design"
)
NavigationManager
.
NavigateTo
(
"/"
);
else
{
await
Message
.
Error
(
$"登录失败"
);
}
}
public
async
Task
GetCaptcha
()
...
...
IoTSharp.ClientApp/Program.cs
浏览文件 @
17a5f485
...
...
@@ -3,6 +3,7 @@ using System.Net.Http;
using
System.Threading.Tasks
;
using
AntDesign.Pro.Layout
;
using
IoTSharp.ClientApp.Services
;
using
IoTSharp.Sdk.Http
;
using
Microsoft.AspNetCore.Components.WebAssembly.Hosting
;
using
Microsoft.Extensions.DependencyInjection
;
...
...
@@ -16,15 +17,21 @@ namespace IoTSharp.ClientApp
builder
.
RootComponents
.
Add
<
App
>(
"app"
);
builder
.
Services
.
AddScoped
(
sp
=>
new
HttpClient
{
BaseAddress
=
new
Uri
(
builder
.
HostEnvironment
.
BaseAddress
)});
sp
=>
new
HttpClient
{
BaseAddress
=
new
Uri
(
builder
.
HostEnvironment
.
BaseAddress
)
});
builder
.
Services
.
AddScoped
(
fc
=>
{
return
new
IoTSharpClient
(
new
Uri
(
builder
.
Configuration
[
"BaseURL"
]));
});
builder
.
Services
.
AddAntDesign
();
builder
.
Services
.
Configure
<
ProSettings
>(
builder
.
Configuration
.
GetSection
(
"ProSettings"
));
builder
.
Services
.
AddScoped
<
IChartService
,
ChartService
>();
builder
.
Services
.
AddScoped
<
IProjectService
,
ProjectService
>();
builder
.
Services
.
AddScoped
<
IUserService
,
UserService
>();
builder
.
Services
.
AddScoped
<
IAccountService
,
AccountService
>();
builder
.
Services
.
AddScoped
<
IProfileService
,
ProfileService
>();
await
builder
.
Build
().
RunAsync
();
}
}
...
...
IoTSharp.ClientApp/Services/AccountService.cs
浏览文件 @
17a5f485
using
System
;
using
System.Threading.Tasks
;
using
IoTSharp.ClientApp.Models
;
using
IoTSharp.Sdk.Http
;
namespace
IoTSharp.ClientApp.Services
{
public
interface
IAccountService
{
Task
LoginAsync
(
LoginParamsType
model
);
Task
<
bool
>
LoginAsync
(
LoginParamsType
model
);
Task
<
string
>
GetCaptchaAsync
(
string
modile
);
}
public
class
AccountService
:
IAccountService
{
private
readonly
Random
_random
=
new
Random
();
private
readonly
IoTSharpClient
_client
;
public
Task
LoginAsync
(
LoginParamsType
model
)
public
AccountService
(
IoTSharpClient
client
)
{
// todo: login logic
return
Task
.
CompletedTask
;
_client
=
client
;
}
public
async
Task
<
bool
>
LoginAsync
(
LoginParamsType
model
)
{
return
await
_client
.
LoginAsync
(
model
.
UserName
,
model
.
Password
);
}
public
Task
<
string
>
GetCaptchaAsync
(
string
modile
)
...
...
IoTSharp.ClientApp/Services/UserService.cs
浏览文件 @
17a5f485
...
...
@@ -2,6 +2,7 @@
using
System.Net.Http.Json
;
using
System.Threading.Tasks
;
using
IoTSharp.ClientApp.Models
;
using
IoTSharp.Sdk.Http
;
namespace
IoTSharp.ClientApp.Services
{
...
...
@@ -13,15 +14,25 @@ namespace IoTSharp.ClientApp.Services
public
class
UserService
:
IUserService
{
private
readonly
HttpClient
_httpClient
;
private
readonly
IoTSharpClient
_client
;
public
UserService
(
HttpClient
httpClient
)
public
UserService
(
HttpClient
httpClient
,
IoTSharpClient
client
)
{
_httpClient
=
httpClient
;
_client
=
client
;
}
public
async
Task
<
CurrentUser
>
GetCurrentUserAsync
()
{
return
await
_httpClient
.
GetFromJsonAsync
<
CurrentUser
>(
"data/current_user.json"
);
var
cu
=
await
_httpClient
.
GetFromJsonAsync
<
CurrentUser
>(
"data/current_user.json"
);
var
my
=
_client
.
MyInfo
;
cu
.
Name
=
my
.
Name
;
cu
.
Email
=
my
.
Email
;
cu
.
Avatar
=
my
.
Avatar
;
cu
.
Title
=
my
.
Introduction
;
cu
.
Group
=
$"
{
my
.
Tenant
?.
Name
}
-
{
my
.
Customer
?.
Name
}
"
;
cu
.
Userid
=
_client
.
MyInfo
.
Name
;
return
cu
;
}
}
}
\ No newline at end of file
IoTSharp.ClientApp/wwwroot/appsettings.json
浏览文件 @
17a5f485
{
"BaseURL"
:
"http://10.165.83.194:2927/"
,
"ProSettings"
:
{
"NavTheme"
:
"dark"
,
"Layout"
:
"side"
,
...
...
IoTSharp.ClientApp/wwwroot/css/site.css
浏览文件 @
17a5f485
此差异已折叠。
点击以展开。
IoTSharp.SDKs/IoTSharp.Sdk.CSharp/IoTSharp.Sdk.Http.csproj
浏览文件 @
17a5f485
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;net
standard2.0;netstandard2.1;net
5.0</TargetFrameworks>
<TargetFrameworks>net452;net5.0</TargetFrameworks>
<RootNamespace>IoTSharp.Sdk.Http</RootNamespace>
<Product>IoTSharp</Product>
<Company>IoTSharp</Company>
...
...
@@ -25,13 +25,10 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net
standard2
.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net
5
.0'">
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Include="..\docs\200x200.png">
<Pack>True</Pack>
...
...
IoTSharp.SDKs/IoTSharp.Sdk.CSharp/IoTSharpClient.cs
0 → 100644
浏览文件 @
17a5f485
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net.Http
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Sdk.Http
{
public
class
IoTSharpClient
{
public
IoTSharpClient
()
{
}
public
IoTSharpClient
(
Uri
uri
)
{
BaseURL
=
uri
.
ToString
();
}
public
bool
Anonymous
=>
(
_result
?.
Roles
?.
Contains
(
nameof
(
UserRole
.
Anonymous
))).
GetValueOrDefault
();
public
bool
CustomerAdmin
=>
(
_result
?.
Roles
?.
Contains
(
nameof
(
UserRole
.
CustomerAdmin
))).
GetValueOrDefault
();
public
bool
NormalUser
=>
(
_result
?.
Roles
?.
Contains
(
nameof
(
UserRole
.
NormalUser
))).
GetValueOrDefault
();
public
bool
SystemAdmin
=>
(
_result
?.
Roles
?.
Contains
(
nameof
(
UserRole
.
SystemAdmin
))).
GetValueOrDefault
();
public
bool
TenantAdmin
=>
(
_result
?.
Roles
?.
Contains
(
nameof
(
UserRole
.
TenantAdmin
))).
GetValueOrDefault
();
public
TokenEntity
Token
=>
_result
.
Token
;
public
bool
IsLogin
=>
(
_result
?.
Succeeded
).
GetValueOrDefault
();
public
bool
CanLogout
=>
IsLogin
;
public
bool
CanLogin
=>
!
IsLogin
;
public
UserInfoDto
MyInfo
{
get
;
set
;
}
public
string
BaseURL
{
get
;
set
;
}
=
"http://localhost:51498"
;
public
HttpClient
HttpClient
{
get
;
set
;
}
=
new
HttpClient
();
public
T
Create
<
T
>()
where
T
:
class
{
T
t
=
Activator
.
CreateInstance
(
typeof
(
T
),
HttpClient
)
as
T
;
typeof
(
T
).
GetProperty
(
"BaseUrl"
).
SetValue
(
t
,
BaseURL
);
return
t
;
}
AccountClient
_act_client
;
private
LoginResult
_result
;
public
async
Task
<
bool
>
LoginAsync
(
string
username
,
string
password
)
{
try
{
_act_client
=
new
AccountClient
(
HttpClient
);
_result
=
await
_act_client
.
LoginAsync
(
new
LoginDto
()
{
UserName
=
username
,
Password
=
password
});
HttpClient
.
DefaultRequestHeaders
.
Add
(
"Authorization"
,
$"Bearer
{
Token
.
Access_token
}
"
);
ApiResultOfUserInfoDto
userInfoDto
=
await
_act_client
.
MyInfoAsync
();
MyInfo
=
userInfoDto
.
Data
;
}
catch
(
Exception
ex
)
{
throw
new
Exception
(
"Login error "
,
ex
);
}
return
(
bool
)(
_result
?.
SignIn
.
Succeeded
);
}
public
async
void
LogoutAsync
()
{
await
_act_client
.
LogoutAsync
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录