Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
82aabaa
refactor: 增加 IAuthenticatorService 接口
ArgoZhang Apr 26, 2025
1d825b7
doc: 增加示例
ArgoZhang Apr 26, 2025
2250a78
refactor: 更改为 ITOTPService 服务
ArgoZhang Apr 26, 2025
c451e8b
refactor: 增加菜单
ArgoZhang Apr 26, 2025
b2c9c03
doc: 增加源码映射
ArgoZhang Apr 26, 2025
b92217c
feat: 增加 OtpInput 组件
ArgoZhang Apr 26, 2025
81b679d
doc: 更新示例
ArgoZhang Apr 26, 2025
861592b
refactor: 增加空检查
ArgoZhang Apr 26, 2025
5ef4ef0
chore: 增加工程引用
ArgoZhang Apr 26, 2025
efcd3fe
Merge branch 'main' into doc-authenticator
ArgoZhang Apr 26, 2025
908a7e7
refactor: 代码格式化
ArgoZhang Apr 26, 2025
c83b2de
refactor: 增加模板
ArgoZhang Apr 26, 2025
5046145
refactor: 更新脚本错误
ArgoZhang Apr 26, 2025
c75b2de
doc: 更新样式
ArgoZhang Apr 26, 2025
2994a85
Revert "refactor: 增加模板"
ArgoZhang Apr 26, 2025
94944fb
doc: 更新示例
ArgoZhang Apr 26, 2025
57db277
refactor: 增加样式文件扩展名
ArgoZhang Apr 26, 2025
06c01c0
feat: 增加 OtpInput 组件
ArgoZhang Apr 26, 2025
55fc6e4
refactor: 增加样式文件扩展名
ArgoZhang Apr 26, 2025
f618846
refactor: 增加 Readonly 功能
ArgoZhang Apr 26, 2025
d6b62af
Merge branch 'refactor-otp' into doc-authenticator
ArgoZhang Apr 26, 2025
f7c49ff
feat: 增加禁用只读功能
ArgoZhang Apr 26, 2025
5330d41
doc: 增加示例
ArgoZhang Apr 26, 2025
720d2a4
chore: 更新字典
ArgoZhang Apr 26, 2025
66c5176
feat: 增加 MaxLength 属性
ArgoZhang Apr 26, 2025
0cf0cd3
refactor: 增加脚本
ArgoZhang Apr 26, 2025
669ac78
doc: 增加示例
ArgoZhang Apr 26, 2025
ab8c23b
refactor: 更新示例
ArgoZhang Apr 27, 2025
d34bbd1
Merge branch 'main' into doc-authenticator
ArgoZhang Apr 27, 2025
9f027cb
refactor: 增加默认实现
ArgoZhang Apr 27, 2025
5e1cac0
refactor: 增加默认服务逻辑
ArgoZhang Apr 27, 2025
403ff5d
chore: 更新字典
ArgoZhang Apr 27, 2025
f796495
test: 增加单元测试
ArgoZhang Apr 27, 2025
53ba55f
test: 增加单元测试
ArgoZhang Apr 27, 2025
a130a33
chore: 更新字典
ArgoZhang Apr 27, 2025
e7db3cd
refactor: 更新接口
ArgoZhang Apr 27, 2025
ce27f07
chore: bump version 9.5.11-beta04
ArgoZhang Apr 27, 2025
9ce3f35
chore: bump version 9.5.11-beta02
ArgoZhang Apr 27, 2025
6c9fc9f
Merge branch 'chore-bump' into doc-authenticator
ArgoZhang Apr 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BootstrapBlazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{9BAF50BE
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest.Benchmarks", "tools\Benchmarks\UnitTest.Benchmarks.csproj", "{3E6D8D0E-5A36-4CFD-8612-7D64E3FFE7B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazor.Authenticator", "..\BootstrapBlazor.Extensions\src\components\BootstrapBlazor.Authenticator\BootstrapBlazor.Authenticator.csproj", "{51641ADB-69FA-6DDF-F83F-FEA0C5AFFD88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -112,6 +114,10 @@ Global
{3E6D8D0E-5A36-4CFD-8612-7D64E3FFE7B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E6D8D0E-5A36-4CFD-8612-7D64E3FFE7B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E6D8D0E-5A36-4CFD-8612-7D64E3FFE7B1}.Release|Any CPU.Build.0 = Release|Any CPU
{51641ADB-69FA-6DDF-F83F-FEA0C5AFFD88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{51641ADB-69FA-6DDF-F83F-FEA0C5AFFD88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51641ADB-69FA-6DDF-F83F-FEA0C5AFFD88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51641ADB-69FA-6DDF-F83F-FEA0C5AFFD88}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -128,6 +134,7 @@ Global
{D8AEAFE7-10AF-4A5B-BC67-FE740A2CA1DF} = {7C1D79F1-87BC-42C1-BD5A-CDE4044AC1BD}
{C075C6C8-B9CB-4AC0-9BDF-B2002B4AB99C} = {EA765165-0542-41C8-93F2-85787FEDEDFF}
{3E6D8D0E-5A36-4CFD-8612-7D64E3FFE7B1} = {9BAF50BE-141D-4429-93A9-942F373D1F68}
{51641ADB-69FA-6DDF-F83F-FEA0C5AFFD88} = {A2182155-43ED-44C1-BF6F-1B70EBD2DFFE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0DCB0756-34FA-4FD0-AE1D-D3F08B5B3A6B}
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\BootstrapBlazor.Extensions\src\components\BootstrapBlazor.Authenticator\BootstrapBlazor.Authenticator.csproj" />
<ProjectReference Include="..\BootstrapBlazor\BootstrapBlazor.csproj" />
</ItemGroup>

Expand Down
8 changes: 5 additions & 3 deletions src/BootstrapBlazor.Server/Components/Components/Pre.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export function dispose(id) {
EventHandler.off(el, 'click', '.btn-minus');

const { Pre } = window.BootstrapBlazor;
Pre.dispose(id, () => {
EventHandler.off(document, 'changed.bb.theme', updateTheme);
});
if (Pre) {
Pre.dispose(id, () => {
EventHandler.off(document, 'changed.bb.theme', updateTheme);
});
}
}
39 changes: 39 additions & 0 deletions src/BootstrapBlazor.Server/Components/Samples/Authenticators.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@page "/authenticator"

<HeadContent>
<style>
.qrcode {
display: flex;
justify-content: center;
}

.progress {
max-width: 500px;
margin: 0 auto;
}

.opt-progress-label {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 0.75rem;
color: var(--bs-body-color);
}
</style>
</HeadContent>

<h3>@Localizer["Title"]</h3>

<h4>@Localizer["SubTitle"]</h4>

<PackageTips Name="BootstrapBlazor.Authenticator"></PackageTips>

<DemoBlock Title="@Localizer["BaseUsageText"]" Introduction="@Localizer["IntroText1"]" Name="Normal">
<QRCode Content="@_content" Width="190" class="mb-3"></QRCode>
<OtpInput Value="@_code" class="text-center mb-3"></OtpInput>
<div class="position-relative">
<BootstrapBlazor.Components.Progress Value="@_progress" IsShowValue="false"></BootstrapBlazor.Components.Progress>
<span class="opt-progress-label">@_remain</span>
</div>
</DemoBlock>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone


namespace BootstrapBlazor.Server.Components.Samples;

/// <summary>
/// Authenticators sample
/// </summary>
public partial class Authenticators
{
[Inject]
[NotNull]
private IStringLocalizer<Anchors>? Localizer { get; set; }

[Inject]
[NotNull]
private ITotpService? TotpService { get; set; }

private string _content = "";

private string? _code;

private double _progress = 0;

private int _remain = 0;

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();

_content = TotpService.GenerateOtpUri();
_code = TotpService.Compute("OMM2LVLFX6QJHMYI");
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);

await Task.Delay(1000);
_code = TotpService.Compute("OMM2LVLFX6QJHMYI");
_remain = TotpService.Instance.GetRemainingSeconds();
_progress = (30d - _remain) * 100 / 30d;
StateHasChanged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public static IServiceCollection AddBootstrapBlazorServices(this IServiceCollect
services.AddSingleton<MenuService>();
services.AddScoped<FanControllerDataService>();

// 增加 Authenticator 服务
services.AddBootstrapBlazorAuthenticator();

// 增加示例网站配置
services.AddOptionsMonitor<WebsiteOptions>();

Expand Down
7 changes: 6 additions & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4918,7 +4918,8 @@
"UniverIcon": "Univer Icons",
"Typed": "Typed",
"UniverSheet": "UniverSheet",
"ShieldBadge": "ShieldBadge"
"ShieldBadge": "ShieldBadge",
"Authenticator": "Authenticator"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesHeader": {
"TablesHeaderTitle": "Header grouping function",
Expand Down Expand Up @@ -7091,5 +7092,9 @@
"BootstrapBlazor.Server.Components.Samples.Tutorials.OnlineSheet": {
"ToastOnReadyTitle": "Collaboration Notification",
"ToastOnReadyContent": "After 4 seconds the table is updated by other writers to change the content"
},
"BootstrapBlazor.Server.Components.Samples.Authenticators": {
"Title": "Authenticator",
"SubTitle": "An implementation TOTP RFC 6238 and HOTP RFC 4226 Authenticator service."
}
}
7 changes: 6 additions & 1 deletion src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4918,7 +4918,8 @@
"UniverIcon": "Univer Icons",
"Typed": "打字机效果 Typed",
"UniverSheet": "表格组件 UniverSheet",
"ShieldBadge": "徽章组件 ShieldBadge"
"ShieldBadge": "徽章组件 ShieldBadge",
"Authenticator": "密码验证服务 Authenticator"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesHeader": {
"TablesHeaderTitle": "表头分组功能",
Expand Down Expand Up @@ -7091,5 +7092,9 @@
"BootstrapBlazor.Server.Components.Samples.Tutorials.OnlineSheet": {
"ToastOnReadyTitle": "在线表格协作通知",
"ToastOnReadyContent": "4 秒后表格更新其他写作人员更改内容"
},
"BootstrapBlazor.Server.Components.Samples.Authenticators": {
"Title": "Authenticator 密码验证服务",
"SubTitle": "实现 TOTP RFC 6238 和 HOTP RFC 4226 认证器服务"
}
}
3 changes: 2 additions & 1 deletion src/BootstrapBlazor.Server/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@
"watermark": "Watermarks",
"typed": "Typeds",
"univer-sheet": "UniverSheets",
"shield-badge": "ShieldBadges"
"shield-badge": "ShieldBadges",
"authenticator": "Authenticators"
},
"video": {
"table": "BV1ap4y1x7Qn?p=1",
Expand Down
12 changes: 12 additions & 0 deletions src/BootstrapBlazor/Components/Input/OtpInput.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@namespace BootstrapBlazor.Components
@inherits ValidateBase<string>

<div @attributes="AdditionalAttributes" id="@Id" class="@ClassString">
@for (var index = 0; index < Digits; index++)
{
if (index < _values.Length)
{
<span class="@SpanClassString">@_values[index]</span>
}
}
</div>
44 changes: 44 additions & 0 deletions src/BootstrapBlazor/Components/Input/OtpInput.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

namespace BootstrapBlazor.Components;

/// <summary>
/// OTP input component
/// </summary>
public partial class OtpInput
{
/// <summary>
/// Gets or sets the length of the OTP input. Default is 6.
/// </summary>
[Parameter]
public int Digits { get; set; } = 6;

/// <summary>
///
/// </summary>
[Parameter]
public OtpInputType Type { get; set; }

private string? ClassString => CssBuilder.Default("bb-opt-input")
.AddClassFromAttributes(AdditionalAttributes)
.Build();

private string? SpanClassString => CssBuilder.Default("bb-opt-span")
.AddClass(ValidCss)
.Build();

private char[] _values = [];

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void OnParametersSet()
{
base.OnParametersSet();

_values = Value?.ToCharArray() ?? [];
}
}
11 changes: 11 additions & 0 deletions src/BootstrapBlazor/Components/Input/OtpInput.razor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.bb-opt-span {
display: inline-block;
border: 1px solid var(--bs-border-color);
font-size: 3em;
padding: 0 .5em;
border-radius: var(--bs-border-radius);

&:not(:last-child) {
margin-right: .5rem;
}
}
27 changes: 27 additions & 0 deletions src/BootstrapBlazor/Enums/OtpInputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

namespace BootstrapBlazor.Components;

/// <summary>
/// OTP input type
/// </summary>
public enum OtpInputType
{
/// <summary>
/// Number OTP Input
/// </summary>
Number,

/// <summary>
/// Text OTP Input
/// </summary>
Text,

/// <summary>
/// Password OTP Input
/// </summary>
Password
}
Loading
Loading