Compare commits
No commits in common. "e62390abc999867c1cac6a6f8031b8e1aa99b64f" and "9f142abd51a8e8e0e847c778ac222c8bafb6ac46" have entirely different histories.
e62390abc9
...
9f142abd51
@ -26,22 +26,6 @@ namespace Api.Controllers
|
|||||||
_tokenParameters = tokenParameters;
|
_tokenParameters = tokenParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("register")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<ActionResult> Register(RegisterViewModel command)
|
|
||||||
{
|
|
||||||
var user = new User(command.Username);
|
|
||||||
var result = await _usersManager.CreateAsync(user, command.Password);
|
|
||||||
|
|
||||||
if (!result.Succeeded)
|
|
||||||
{
|
|
||||||
return BadRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
return NoContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Récupère un jeton d'accès pour un utilisateur particulier.
|
/// Récupère un jeton d'accès pour un utilisateur particulier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace Api.Models
|
|
||||||
{
|
|
||||||
public sealed class RegisterViewModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
public string Username { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string Password { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@ -56,11 +55,7 @@ namespace Api
|
|||||||
|
|
||||||
services.AddSingleton(tokenParams);
|
services.AddSingleton(tokenParams);
|
||||||
|
|
||||||
services.AddIdentityCore<User>(o =>
|
services.AddIdentityCore<User>()
|
||||||
{
|
|
||||||
o.Password.RequiredLength = o.Password.RequiredUniqueChars = 0;
|
|
||||||
o.Password.RequireDigit = o.Password.RequireLowercase = o.Password.RequireNonAlphanumeric = o.Password.RequireUppercase = false;
|
|
||||||
})
|
|
||||||
.AddRoles<Role>()
|
.AddRoles<Role>()
|
||||||
.AddEntityFrameworkStores<HNDbContext>()
|
.AddEntityFrameworkStores<HNDbContext>()
|
||||||
.AddSignInManager();
|
.AddSignInManager();
|
||||||
@ -111,8 +106,6 @@ namespace Api
|
|||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
MigrateDatabase(app);
|
|
||||||
|
|
||||||
app.UseOpenApi();
|
app.UseOpenApi();
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
@ -142,17 +135,5 @@ namespace Api
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Lance les migrations. En production, il est plutôt conseillé de générer
|
|
||||||
/// les scripts avec `dotnet ef migrations script` et de les passer à la main.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="app"></param>
|
|
||||||
private void MigrateDatabase(IApplicationBuilder app)
|
|
||||||
{
|
|
||||||
using var scope = app.ApplicationServices.CreateScope();
|
|
||||||
using var ctx = scope.ServiceProvider.GetRequiredService<HNDbContext>();
|
|
||||||
ctx.Database.Migrate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,39 +6,6 @@
|
|||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
},
|
},
|
||||||
"paths": {
|
"paths": {
|
||||||
"/api/accounts/register": {
|
|
||||||
"post": {
|
|
||||||
"tags": [
|
|
||||||
"Accounts"
|
|
||||||
],
|
|
||||||
"operationId": "Accounts_Register",
|
|
||||||
"requestBody": {
|
|
||||||
"x-name": "command",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/RegisterViewModel"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": true,
|
|
||||||
"x-position": 1
|
|
||||||
},
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/octet-stream": {
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "binary"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/api/accounts/login": {
|
"/api/accounts/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
@ -342,24 +309,6 @@
|
|||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"schemas": {
|
"schemas": {
|
||||||
"RegisterViewModel": {
|
|
||||||
"type": "object",
|
|
||||||
"additionalProperties": false,
|
|
||||||
"required": [
|
|
||||||
"username",
|
|
||||||
"password"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"username": {
|
|
||||||
"type": "string",
|
|
||||||
"minLength": 1
|
|
||||||
},
|
|
||||||
"password": {
|
|
||||||
"type": "string",
|
|
||||||
"minLength": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"LoginViewModel": {
|
"LoginViewModel": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|||||||
@ -6,11 +6,8 @@ COPY Application/*.csproj ./Application/
|
|||||||
COPY Domain/*.csproj ./Domain/
|
COPY Domain/*.csproj ./Domain/
|
||||||
COPY Infrastructure/*.csproj ./Infrastructure/
|
COPY Infrastructure/*.csproj ./Infrastructure/
|
||||||
COPY Apps/Api/*.csproj ./Apps/Api/
|
COPY Apps/Api/*.csproj ./Apps/Api/
|
||||||
|
|
||||||
WORKDIR /source/Apps/Api
|
|
||||||
RUN dotnet restore
|
RUN dotnet restore
|
||||||
|
|
||||||
WORKDIR /source
|
|
||||||
COPY Application/. ./Application/
|
COPY Application/. ./Application/
|
||||||
COPY Domain/. ./Domain/
|
COPY Domain/. ./Domain/
|
||||||
COPY Infrastructure/. ./Infrastructure/
|
COPY Infrastructure/. ./Infrastructure/
|
||||||
@ -22,6 +19,5 @@ RUN dotnet publish -c release -o /app --no-restore
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:5.0
|
FROM mcr.microsoft.com/dotnet/aspnet:5.0
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=build /app ./
|
COPY --from=build /app ./
|
||||||
ENV "ConnectionStrings:Default"="Data Source=hn.db"
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
ENTRYPOINT ["dotnet", "Api.dll"]
|
ENTRYPOINT ["dotnet", "Api.dll"]
|
||||||
@ -1,3 +0,0 @@
|
|||||||
build:
|
|
||||||
docker:
|
|
||||||
web: Dockerfile
|
|
||||||
Loading…
x
Reference in New Issue
Block a user