• Abp 实现通过手机号注册用户


    前言

    Abp 的 Identity 模块,实现了用户的管理,但是对于国内来讲,很多场景不能很好适配。比如:通过手机号进行注册的场景。

    Abp vnext Identity 以及 asp.net core identity  默认只有 Email 必填以及唯一的校验,缺少手机号必要的校验;对此我们需要进行适当的调整,以作适配。

     

    准备

     

    建议先参考 IdentityUserAppService 对用户注册的实现;

    由于手机号验证的场景基本上是需要的,所以本次采用重写的方式,当然也可以参考其代码,自定义自己的实现。

     

    Application 

      

    Domain

    由于 IIdentityUserRepository 缺少对手机号是否存在的默认实现,我们可以新增对应Repository 来实现相关功能。

    尽量遵守DDD 分层的原则。

    1  public interface IAccountRepository
    2     {
    3         Task<bool> IsPhoneNumberExistAsync(string phoneNumber);
    4     }
    View Code

     

    Repository

    实现Domain 层定义的接口

     1  public class AccountRepository: IAccountRepository, ITransientDependency
     2     {
     3         private readonly IRepository _identityUserRepository;
     4 
     5         public AccountRepository(IRepository identityUserRepository)
     6         {
     7             _identityUserRepository = identityUserRepository;
     8         }
     9 
    10         public async Task<bool> IsPhoneNumberExistAsync(string phoneNumber)
    11         {
    12             return await _identityUserRepository.AnyAsync(
    13                 c => c.PhoneNumber == phoneNumber);
    14         }
    15     }
    View Code

     

    替换默认实例

    我们已经完成了对 IdentityUserAppService 创建方法的重写,需要替换默认的接口实例对象,可以参考 Customizing Application Modules Overriding Services | Documentation Center | ABP.IO

        [Dependency(ReplaceServices = true)]
        [ExposeServices(typeof(IIdentityUserAppService), typeof(IdentityUserAppService), typeof(PublicAccountAppService))]
        public class PublicAccountAppService: IdentityUserAppService
        {...}
    View Code

     

    其他

    主要的修改已经调整完毕。但是由于AbpUser 表没有 PhoneNumber 的相关索引,可以自行通过 Migration 进行添加。

    Abp 框架比较优秀,很多方面也算是最佳实践,推荐使用。

    改动比较小,修改起来也比较方便;当然也可以完全重写 注册的方法。下次有时间可以再整理下通过手机号登陆的实现。

     

  • 相关阅读:
    WPS EXCEL 筛选指定长度的文本 内容 字符串
    ESP8266-Arduino编程实例-BMP180气压温度传感器驱动
    Windows照片查看器无法查看某些照片的解决方案
    医疗图像分割指标
    Figma UI UX设计教程
    大数据名词——MPP(Massively Parallel Processing)数据集市
    猫头虎的技术笔记:Spring Boot启动报错解决方案
    世强硬创获昕感科技授权代理,SiC MOSFET实现超低导通电阻
    社区买菜系统 毕业设计 JAVA+Vue+SpringBoot+MySQL
    微服务架构介绍
  • 原文地址:https://www.cnblogs.com/qiu-gu/p/16130602.html