第36章 GoogleAuthenticator插件项与启动项的相互组合

 

109 MultiFactorAuthenticationMethodSearchModel、MultiFactorAuthenticationMethodListModel、MultiFactorAuthenticationMethodModel、MultiFactorAuthenticationMethodModelFactory、IMultiFactorAuthenticationMethodModelFactory

    MultiFactorAuthenticationMethodSearchModel纪录,可以通过该纪录,为在执行搜索操作后,对多个多因素身份认证方式模型实例,进行分页操作提供数据支撑。

    MultiFactorAuthenticationMethodListModel纪录,通列表实例中所存储的多个多因素身份认证方式模型实例进行分页操作,主要用于通过浏览器中的页面向服务器端提交数据。

    MultiFactorAuthenticationMethodModel纪录,可以通过该模型记录中的属性成员获取(GoogleAuthenticator)多因素身份认证方式插件的本地化基本数据信息,从而为(GoogleAuthenticator)多因素身份认证插件界面的本地化显示提供数据支撑。

    MultiFactorAuthenticationMethodModelFactory类,继承于IMultiFactorAuthenticationMethodModelFactory接口,通过该类中的方法成员,为管理区域多因素身份认证方式页面中的分页显示操作提供数据支撑;同时也为把页面中的数据转换后提交到服务器端提供支撑。

IMultiFactorAuthenticationMethodModelFactory接口,

继承该接口的类中的方法成员,为管理区域多因素身份认证方式页面中的分页显示操作提供数据支撑;同时也为把页面中的数据转换后提交到服务器端提供支撑。

通过MSBuild定义Nop.Plugin.MultiFactorAuth.GoogleAuthenticator

1、通过MSBuild定义Nop.Plugin.MultiFactorAuth.GoogleAuthenticator,双击Nop.Plugin.MultiFactorAuth.GoogleAuthenticator项目打开Nop.Plugin.MultiFactorAuth.GoogleAuthenticator.csproj文件,定义该文件为:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>

    <TargetFramework>net5.0</TargetFramework>

      <!--设置预生成目录的相对路径字符串-->

      <OutputPath>..\..\Presentation\Nop.Web\Plugins\MultiFactorAuth.GoogleAuthenticator</OutputPath>

      <!--定义预生成目录的属性变量-->

      <OutDir>$(OutputPath)</OutDir>

      <!--该属性的参数值为:true时,如果当前项目(这里特指:Nop.Plugin.MultiFactorAuth.GoogleAuthenticator)中存在NuGet引用,则保证在执行了预生成操作后把NuGet所引用的dll文件复制到目标项目(这里特指:Nop.Web)的指定目录中。-->

      <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

      <BaseOutputPath>..\..\Presentation\Nop.Web\Plugins\MultiFactorAuth.GoogleAuthenticator</BaseOutputPath>

  </PropertyGroup>

    <!--通过“ClearPluginAssemblies”删除复制到目标项目(这里特指:Nop.Web)的指定目录中的文件时,排除对下面所定义文件的删除操作。-->

    <ItemGroup>

        <None Remove="logo.png" />

        <None Remove="plugin.json" />

        <None Remove="Views\Configure.cshtml" />

        <None Remove="Views\Customer\GAAuthentication.cshtml" />

        <None Remove="Views\Customer\GAVefification.cshtml" />

        <None Remove="Views\_ViewImports.cshtml" />

    </ItemGroup>

    <!--通过“ClearPluginAssemblies”和下载的定义,把当前项目(这里特指:Nop.Plugin.MultiFactorAuth.GoogleAuthenticator)中指定文件,复制到目标项目(这里特指:Nop.Web)的指定目录中。-->

    <!--CopyToPublishDirectory 的值,Never:从不复制;PreserveNewest:复制最新的-->

    <ItemGroup>

        <Content Include="logo.png">

            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

        </Content>

        <Content Include="plugin.json">

            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

        </Content>

        <Content Include="Views\Customer\GAVefification.cshtml">

            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

        </Content>

        <Content Include="Views\Customer\GAAuthentication.cshtml">

            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

        </Content>

        <Content Include="Views\Configure.cshtml">

            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

        </Content>

        <Content Include="Views\_ViewImports.cshtml">

            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

        </Content>

    </ItemGroup>

  <ItemGroup>

    <PackageReference Include="GoogleAuthenticator" Version="2.4.0" />

  </ItemGroup>

  <ItemGroup>

    <ProjectReference Include="..\..\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj" />

      <!-- 引用“ClearPluginAssemblies”程序-->

      <ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />

  </ItemGroup>

    <!-- 在执行预生成操作后,通过“ClearPluginAssemblies”程序,用于在执行预生成操作后,自动把指定的文件复制到目标项目(这里特指:Nop.Web)的指定目录中,同时删除一些语言包和公有dll文件,只保留当前插件项一些特有的dll文件。-->

    <Target Name="NopTarget" AfterTargets="Build">

        <!--删除目标项目(这里特指:Nop.Web)的指定目录中,一些语言包和公有dll文件,只保留当前插件项一些特有的dll文件-->

        <MSBuild Projects="@(ClearPluginAssemblies)" Properties="PluginPath=$(MSBuildProjectDirectory)\$(OutDir)" Targets="NopClear" />

    </Target>

</Project>

2、通过MSBuild重构Nop.Web,双击Nop.Webk项目打开Nop.Web.csproj文件,在该文件中添加定义:

<PropertyGroup>

        <!--配置应用程序是使用工作站垃圾回收还是服务器垃圾回收(默认值:false=启用工作站垃圾回收,防止内存无限制增长): https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals-->

        <ServerGarbageCollection>false</ServerGarbageCollection>

        <!--配置是否启用后台(并发)垃圾回收。(默认值:true=启用后台垃圾回收): https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals#concurrent-garbage-collection-->

        <ConcurrentGarbageCollection>false</ConcurrentGarbageCollection>

    </PropertyGroup>

  1. 重构Nop.Web.Framework.Infrastructure.DependencyRegistrar.Register方法,取消下列语句前的注释:

       services.AddScoped<IMultiFactorAuthenticationPluginManager, MultiFactorAuthenticationPluginManager>();

2、重构Nop.Web.Infrastructure.DependencyRegistrar.Register方法,取消下列语句前的注释:

services.AddScoped<IMultiFactorAuthenticationMethodModelFactory, MultiFactorAuthenticationMethodModelFactory>();

3、重构Nop.Web.Areas.Admin.Infrastructure.Mapper.AdminMapperConfiguration类,取消下列语句前的注释:

CreateMultiFactorAuthenticationMaps();

  /// <summary>

        /// 【多因素身份认证映射】

        /// <remarks>

        /// 摘要:

        ///     通过“AutoMapper”中间件,把多因素身份认证模型纪录的接口及其类注入到.NetCore的依赖注入容器中。

        /// </remarks>

        /// </summary>

        protected virtual void CreateMultiFactorAuthenticationMaps()

        {

            CreateMap<IMultiFactorAuthenticationMethod, MultiFactorAuthenticationMethodModel>();

        }

3、重构Nop.Web.Areas.Admin.Controllers.AuthenticationController类,取消针对多因素身份认证实现方法前的所有注释。

4、重构\Nop.Web\Areas\Admin\Views\_ViewImports.cshtml页面,取消下列语句前的注释:

@using Nop.Web.Areas.Admin.Models.MultiFactorAuthentication

5、在数据库安装操作完成后,再次按F5执行程序,在执行了登录操作后,输入https://localhost:44303/Admin/Authentication/MultiFactorMethods,页面正常被显示出来,在点击配置按钮(https://localhost:44303/Plugins/GoogleAuthenticator/Configure), 页面正常也被显示出来

对以上功能更为具体实现和注释见:22-03-23-036_Nop_4.40.4(GoogleAuthenticator插件项与启动项的相互组

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值