develop #3
@ -10,13 +10,19 @@
|
||||
<PackageReference Include="Auth0.ManagementApi" Version="7.38.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Middleware\" />
|
||||
<Folder Include="Models\DTOs\" />
|
||||
<Folder Include="Utilities\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
31
AGSS/Controllers/User/UserInfoController.cs
Normal file
31
AGSS/Controllers/User/UserInfoController.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using AGSS.Models;
|
||||
using AGSS.Models.Entities;
|
||||
using AGSS.Models.Template;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AGSS.Controllers.User;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class UserInfoController : ControllerBase
|
||||
{
|
||||
private readonly DBContext _context;
|
||||
|
||||
public UserInfoController(DBContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> My()
|
||||
{
|
||||
UserModel user = new UserModel
|
||||
{
|
||||
AuthId = "123"
|
||||
};
|
||||
|
||||
_context.UserModels.Add(user);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(new ReturnTemplate(200, "成功",user));
|
||||
}
|
||||
}
|
14
AGSS/Models/DBContext.cs
Normal file
14
AGSS/Models/DBContext.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using AGSS.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AGSS.Models;
|
||||
|
||||
public class DBContext : DbContext
|
||||
{
|
||||
public DBContext(DbContextOptions<DBContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<UserModel> UserModels { get; set; }
|
||||
}
|
8
AGSS/Models/Entities/User.cs
Normal file
8
AGSS/Models/Entities/User.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace AGSS.Models.Entities;
|
||||
|
||||
public class UserModel
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string AuthId { get; set; }
|
||||
|
||||
}
|
3
AGSS/Models/Template/ReturnTemplate.cs
Normal file
3
AGSS/Models/Template/ReturnTemplate.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace AGSS.Models.Template;
|
||||
|
||||
public record ReturnTemplate(int Code, string Msg, object Data);
|
@ -1,4 +1,6 @@
|
||||
using AGSS.Models;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
|
||||
@ -16,10 +18,11 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
||||
|
||||
// ¶ÁÈ¡ÅäÖÃ
|
||||
var domain = builder.Configuration["Auth0:Domain"];
|
||||
var audience =builder.Configuration["Auth0:Audience"];
|
||||
|
||||
builder.Services.AddDbContext<DBContext>(opt =>
|
||||
opt.UseNpgsql(builder.Configuration.GetConnectionString("DBContext")));
|
||||
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
@ -59,10 +62,6 @@ app.UseAuthentication();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
#pragma warning disable ASP0014 // Suggest using top level route registrations
|
||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
#pragma warning restore ASP0014 // Suggest using top level route registrations
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
|
@ -4,5 +4,14 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Auth0": {
|
||||
"Domain": "",
|
||||
"Audience": "",
|
||||
"ClientId": ""
|
||||
},
|
||||
"DataBase": {
|
||||
"ConnectionString": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;"
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,8 @@
|
||||
"Domain": "",
|
||||
"Audience": "",
|
||||
"ClientId": ""
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DBContext": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=luolan12323;"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user