千万级秒杀系统-7.用户微服务集成Identity+vue注册实现

文章详细介绍了如何构建用户微服务的Identity模块,包括引入必要的Abp包,创建数据库表,生成迁移,以及在应用层和服务层集成Identity。接着,文章展示了如何在HTTPAPI模块中集成Identity和Account模块,以便通过API访问。此外,还说明了在Vue前端应用中调用注册接口的过程,以及在聚合服务中集成AccountHTTPAPI客户端的步骤。
摘要由CSDN通过智能技术生成

用户微服务Identity

1、创建表

先引入WBC.User.Domain中Volo.Abp.Identity.Domain 包

		<PackageReference Include="Volo.Abp.Identity.Domain" Version="4.4.3" />
		<PackageReference Include="Volo.Abp.IdentityServer.Domain" Version="4.4.3" />

在UserDomainModule中使用集成模块

typeof(AbpIdentityDomainModule)//集成Identity领域模块

在这里插入图片描述

由于创建表需要使用ef所以在ef中也需要集成Identity

    <PackageReference Include="Volo.Abp.EntityFrameworkCore" Version="4.4.3" />
    <PackageReference Include="Volo.Abp.Identity.EntityFrameworkCore" Version="4.4.3" />

在这里插入图片描述

在UserEntityFrameworkCoreModule使用

typeof(AbpIdentityEntityFrameworkCoreModule)//集成AbpIdentityEntityFrameworkCoreModule

在这里插入图片描述


            //添加Identity表
            //去除前缀
            AbpIdentityDbProperties.DbTablePrefix = "";
            builder.ConfigureIdentity();

在这里插入图片描述

在用户微服务中生成迁移文件并生成表(原有的如果有可以删除这样不容易出错)

dotnet ef migrations add user
dotnet ef database update

在这里插入图片描述

创建成功

在这里插入图片描述

在WBC.User.Application引入Volo.Abp.Identity.Application并使用

nuget包

    <PackageReference Include="Volo.Abp.Identity.Application" Version="4.4.3" />

UserApplicationModule使用

typeof(AbpIdentityApplicationModule)//集成AbpIdentityApplicationModule

在这里插入图片描述

WBC.User.HttpApi集成Volo.Abp.Identity.HttpApi

<PackageReference Include="Volo.Abp.Identity.HttpApi" Version="4.4.3" />

在这里插入图片描述

在UserHttpApiModule使用

typeof(AbpIdentityHttpApiModule)//集成AbpIdentityHttpApiModule

在这里插入图片描述

集成Volo.Abp.Account.Application

<PackageReference Include="Volo.Abp.Account.Application" Version="4.4.3" />

在这里插入图片描述

UserApplicationModule使用

typeof(AbpAccountApplicationModule)//AbpAccountApplicationModule

集成Volo.Abp.Account.Application

<PackageReference Include="Volo.Abp.Account.HttpApi" Version="4.4.3" />

在这里插入图片描述

UserHttpApiModule使用

typeof(AbpAccountHttpApiModule)//集成AbpAccountHttpApiModule

在这里插入图片描述

由于创建时去掉了表前缀所以在微服务访问时也要去掉否则会访问失败

在这里插入图片描述

运行用户微服务看看是否能够正常使用

在这里插入图片描述
在这里插入图片描述

集成到网关

由于网关直接使用的微服务所以可以直接调用

在网关层加入配置文件(路径不一样所以需要添加一个配置)

在这里插入图片描述

{
      "UpstreamPathTemplate": "/api/account/{everything}",
      "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ],
      "DownstreamPathTemplate": "/api/account/{everything}",
      "DownstreamScheme": "http",
      "ServiceName": "userservices",
      "LoadBalancerOptions": {
        "Type": "RoundRobin"
      }

调用网关层看看能不能正常添加

在这里插入图片描述
在这里插入图片描述

聚合服务集成

引入Volo.Abp.Account.HttpApi.Client nuget包

<PackageReference Include="Volo.Abp.Account.HttpApi.Client" Version="4.4.3" />

在这里插入图片描述

SeckillAggregateModule中使用

typeof(AbpAccountHttpApiClientModule)//集成AbpAccountHttpApiClientModule

在这里插入图片描述

在appsettings.json中加入AbpAccount的地址

 "AbpAccount": {
      "BaseUrl": "http://localhost:8002/"
    }

在这里插入图片描述

添加Users控制器并创建注册方法

在这里插入图片描述

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Account;
using Volo.Abp.Identity;

namespace WBC.SeckillAggregate.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UsersController : ControllerBase
    {
        public IAccountAppService _accountAppService { get; set; }

        //用户注册
        [HttpPost("Registry")]
        public async Task<IdentityUserDto> CreateUser(RegisterDto req)
        {
            return await _accountAppService.RegisterAsync(req);
        }
    }
}

运行聚合服务测试是否能够正常使用

在这里插入图片描述
在这里插入图片描述

vue项目调用注册

创建注册页面并定义路由

在这里插入图片描述

注册功能实现(布局简单使用elementpuls写了一下)

在这里插入图片描述

<template>
  <el-form :model="form" label-width="120px">
    <el-form-item label="姓名">
      <el-input v-model="form.userName" />
    </el-form-item>
    <el-form-item label="邮箱">
      <el-input v-model="form.emailAddress" />
    </el-form-item>
    <el-form-item label="密码">
      <el-input type="password" v-model="form.password" />
    </el-form-item>
    <el-form-item label="服务名称">
      <el-input v-model="form.appName" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">添加</el-button>
      <router-link to="index"><el-button>返回主页</el-button></router-link>
    </el-form-item>
  </el-form>
</template>
  
  <script lang="ts" setup>
import { onMounted, ref } from "vue";
import { Post } from "@/http";
import { ElMessage } from "element-plus";
//引入rouer路由
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
// do not use same name with ref
const form = ref({
  userName: "wangbenchi",
  emailAddress: "69945864@qq.com",
  password: "Wbc123!@#",
  appName: "聚合服务",
});
onMounted(() => {
});
const onSubmit = () => {
  console.log(form.value);
  //请求接口
  Post("/Users/Registry", form.value).then((res: any) => {
    console.log(res);
    if (res.data.Success) {
      Success();
    }
  });
};
const Success = () => {
  ElMessage({
    message: "注册成功",
    type: "success",
    duration: 2000,
    onClose: () => {
      router.push("login");
    },
  });
};
</script>
  

业务流程

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值