Tens of millions of spike system-7. User microservice integration Identity+vue registration implementation

User Microservice Identity

1. Create table

Introduce the Volo.Abp.Identity.Domain package in WBC.User.Domain first

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

Using integration modules in UserDomainModule

typeof(AbpIdentityDomainModule)//integrated Identity domain module

Because ef needs to be used to create a table, Identity also needs to be integrated in ef

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

Used in UserEntityFrameworkCoreModule

typeof(AbpIdentityEntityFrameworkCoreModule)//Integrated AbpIdentityEntityFrameworkCoreModule

            //Add Identity table
            //remove the prefix
            AbpIdentityDbProperties.DbTablePrefix = "";
            builder. ConfigureIdentity();

Generate the migration file and generate the table in the user microservice (the original one can be deleted if there is one so that it is not easy to make mistakes)

dotnet ef migrations add user
dotnet ef database update

Created successfully

Introduce and use Volo.Abp.Identity.Application in WBC.User.Application

nuget package

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

UserApplicationModule uses

typeof(AbpIdentityApplicationModule)//integrate AbpIdentityApplicationModule

WBC.User.HttpApi integrates Volo.Abp.Identity.HttpApi

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

Used in UserHttpApiModule

typeof(AbpIdentityHttpApiModule)//Integrated AbpIdentityHttpApiModule

Integrate Volo.Abp.Account.Application

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

UserApplicationModule uses

typeof(AbpAccountApplicationModule)//AbpAccountApplicationModule

Integrate Volo.Abp.Account.Application

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

UserHttpApiModule uses

typeof(AbpAccountHttpApiModule)//Integrated AbpAccountHttpApiModule

Because the table prefix is removed during creation, it should also be removed during microservice access, otherwise the access will fail

Run the user microservice to see if it can be used normally


Integrate into gateway

Because of the microservice directly used by the gateway, it can be called directly

Add a configuration file at the gateway layer (the path is different, so you need to add a configuration)

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

Call the gateway layer to see if it can be added normally


Aggregation service integration

Introduce the Volo.Abp.Account.HttpApi.Client nuget package

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

Used in SeckillAggregateModule

typeof(AbpAccountHttpApiClientModule)//Integrated AbpAccountHttpApiClientModule

Add the address of AbpAccount in appsettings.json

 "AbpAccount": {<!-- -->
      "BaseUrl": "http://localhost:8002/"
    }

Add a Users controller and create a registration method

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; }

        //user registration
        [HttpPost("Registry")]
        public async Task<IdentityUserDto> CreateUser(RegisterDto req)
        {<!-- -->
            return await _accountAppService. RegisterAsync(req);
        }
    }
}

Run aggregation service to test whether it can be used normally


vue project call registration

Create a registration page and define routes

Registration function implementation (the layout is simple and written with elementpuls)

<template>
  <el-form :model="form" label-width="120px">
    <el-form-item label="name">
      <el-input v-model="form.userName" />
    </el-form-item>
    <el-form-item label="Email">
      <el-input v-model="form.emailAddress" />
    </el-form-item>
    <el-form-item label="password">
      <el-input type="password" v-model="form.password" />
    </el-form-item>
    <el-form-item label="service name">
      <el-input v-model="form.appName" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">Add</el-button>
      <router-link to="index"><el-button>Back to Homepage</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";
//Introduce rouer routing
import {<!-- --> useRoute, useRouter } from "vue-router";
const router = useRouter();
// do not use same name with ref
const form = ref({<!-- -->
  userName: "wangbenchi",
  emailAddress: "[email protected]",
  password: "Wbc123!@#",
  appName: "Aggregation Service",
});
onMounted(() => {<!-- -->
});
const onSubmit = () => {<!-- -->
  console.log(form.value);
  //request interface
  Post("/Users/Registry", form. value).then((res: any) => {<!-- -->
    console. log(res);
    if (res.data.Success) {<!-- -->
      Success();
    }
  });
};
const Success = () => {<!-- -->
  ElMessage({<!-- -->
    message: "Successful registration",
    type: "success",
    duration: 2000,
    onClose: () => {<!-- -->
      router. push("login");
    },
  });
};
</script>
  

Business process