111
This commit is contained in:
parent
e646d86004
commit
7c2420a00b
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -38,3 +38,4 @@ dist/
|
|||
*.air
|
||||
*.ipa
|
||||
*.apk
|
||||
/src/frontend/package-lock.json
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
using MilitaryTrainingManagement.Authorization;
|
||||
using MilitaryTrainingManagement.Data;
|
||||
using MilitaryTrainingManagement.Models.Enums;
|
||||
|
|
@ -53,15 +55,15 @@ builder.Services.AddAuthorization(options =>
|
|||
// 师团级权限策略
|
||||
options.AddPolicy("DivisionLevel", policy =>
|
||||
policy.Requirements.Add(new OrganizationalLevelRequirement(OrganizationalLevel.Division)));
|
||||
|
||||
|
||||
// 团级及以上权限策略
|
||||
options.AddPolicy("RegimentLevel", policy =>
|
||||
policy.Requirements.Add(new OrganizationalLevelRequirement(OrganizationalLevel.Regiment)));
|
||||
|
||||
|
||||
// 营级及以上权限策略
|
||||
options.AddPolicy("BattalionLevel", policy =>
|
||||
policy.Requirements.Add(new OrganizationalLevelRequirement(OrganizationalLevel.Battalion)));
|
||||
|
||||
|
||||
// 连级及以上权限策略(所有已认证用户)
|
||||
options.AddPolicy("CompanyLevel", policy =>
|
||||
policy.Requirements.Add(new OrganizationalLevelRequirement(OrganizationalLevel.Company)));
|
||||
|
|
@ -119,6 +121,7 @@ builder.Services.AddSwaggerGen(c =>
|
|||
});
|
||||
|
||||
// 配置CORS
|
||||
#if DEBUG
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", policy =>
|
||||
|
|
@ -128,18 +131,19 @@ builder.Services.AddCors(options =>
|
|||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
#endif
|
||||
var app = builder.Build();
|
||||
|
||||
// 配置HTTP请求管道
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
#if DEBUG
|
||||
app.UseCors("AllowAll");
|
||||
#endif
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
|
@ -149,10 +153,10 @@ using (var scope = app.Services.CreateScope())
|
|||
{
|
||||
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
var authService = scope.ServiceProvider.GetRequiredService<IAuthenticationService>();
|
||||
|
||||
|
||||
// 确保数据库已创建
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
|
||||
// 如果没有组织单位,创建种子数据
|
||||
if (!context.OrganizationalUnits.Any())
|
||||
{
|
||||
|
|
@ -165,7 +169,7 @@ using (var scope = app.Services.CreateScope())
|
|||
};
|
||||
context.OrganizationalUnits.Add(division);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
|
||||
// 创建团级组织
|
||||
var regiment = new MilitaryTrainingManagement.Models.Entities.OrganizationalUnit
|
||||
{
|
||||
|
|
@ -176,7 +180,7 @@ using (var scope = app.Services.CreateScope())
|
|||
};
|
||||
context.OrganizationalUnits.Add(regiment);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
|
||||
// 创建营级组织
|
||||
var battalion = new MilitaryTrainingManagement.Models.Entities.OrganizationalUnit
|
||||
{
|
||||
|
|
@ -187,7 +191,7 @@ using (var scope = app.Services.CreateScope())
|
|||
};
|
||||
context.OrganizationalUnits.Add(battalion);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
|
||||
// 创建连级组织
|
||||
var company = new MilitaryTrainingManagement.Models.Entities.OrganizationalUnit
|
||||
{
|
||||
|
|
@ -198,19 +202,19 @@ using (var scope = app.Services.CreateScope())
|
|||
};
|
||||
context.OrganizationalUnits.Add(company);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
|
||||
// 创建师团管理员账户
|
||||
await authService.CreateUserAsync("admin", "admin123", "师团管理员", division.Id);
|
||||
|
||||
|
||||
// 创建团级账户
|
||||
await authService.CreateUserAsync("regiment", "regiment123", "团级管理员", regiment.Id);
|
||||
|
||||
|
||||
// 创建营级账户
|
||||
await authService.CreateUserAsync("battalion", "battalion123", "营级管理员", battalion.Id);
|
||||
|
||||
|
||||
// 创建连级账户
|
||||
await authService.CreateUserAsync("company", "company123", "连级管理员", company.Id);
|
||||
|
||||
|
||||
Console.WriteLine("种子数据已创建!");
|
||||
Console.WriteLine("默认账户:");
|
||||
Console.WriteLine(" 师团管理员: admin / admin123");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user