Compare commits
5 Commits
9f142abd51
...
e62390abc9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e62390abc9 | ||
|
|
8a80b80e5c | ||
|
|
0d8082448d | ||
|
|
0972ec304a | ||
|
|
2776586ad7 |
@ -26,6 +26,22 @@ namespace Api.Controllers
|
||||
_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>
|
||||
/// Récupère un jeton d'accès pour un utilisateur particulier.
|
||||
/// </summary>
|
||||
|
||||
13
Apps/Api/Models/RegisterViewModel.cs
Normal file
13
Apps/Api/Models/RegisterViewModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Api.Models
|
||||
{
|
||||
public sealed class RegisterViewModel
|
||||
{
|
||||
[Required]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@ -55,7 +56,11 @@ namespace Api
|
||||
|
||||
services.AddSingleton(tokenParams);
|
||||
|
||||
services.AddIdentityCore<User>()
|
||||
services.AddIdentityCore<User>(o =>
|
||||
{
|
||||
o.Password.RequiredLength = o.Password.RequiredUniqueChars = 0;
|
||||
o.Password.RequireDigit = o.Password.RequireLowercase = o.Password.RequireNonAlphanumeric = o.Password.RequireUppercase = false;
|
||||
})
|
||||
.AddRoles<Role>()
|
||||
.AddEntityFrameworkStores<HNDbContext>()
|
||||
.AddSignInManager();
|
||||
@ -106,6 +111,8 @@ namespace Api
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
MigrateDatabase(app);
|
||||
|
||||
app.UseOpenApi();
|
||||
|
||||
if (env.IsDevelopment())
|
||||
@ -135,5 +142,17 @@ 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,6 +6,39 @@
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"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": {
|
||||
"post": {
|
||||
"tags": [
|
||||
@ -309,6 +342,24 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"RegisterViewModel": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"username",
|
||||
"password"
|
||||
],
|
||||
"properties": {
|
||||
"username": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"password": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
"LoginViewModel": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
|
||||
@ -6,8 +6,11 @@ COPY Application/*.csproj ./Application/
|
||||
COPY Domain/*.csproj ./Domain/
|
||||
COPY Infrastructure/*.csproj ./Infrastructure/
|
||||
COPY Apps/Api/*.csproj ./Apps/Api/
|
||||
|
||||
WORKDIR /source/Apps/Api
|
||||
RUN dotnet restore
|
||||
|
||||
WORKDIR /source
|
||||
COPY Application/. ./Application/
|
||||
COPY Domain/. ./Domain/
|
||||
COPY Infrastructure/. ./Infrastructure/
|
||||
@ -19,5 +22,6 @@ RUN dotnet publish -c release -o /app --no-restore
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:5.0
|
||||
WORKDIR /app
|
||||
COPY --from=build /app ./
|
||||
ENV "ConnectionStrings:Default"="Data Source=hn.db"
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["dotnet", "Api.dll"]
|
||||
3
heroku.yml
Normal file
3
heroku.yml
Normal file
@ -0,0 +1,3 @@
|
||||
build:
|
||||
docker:
|
||||
web: Dockerfile
|
||||
Loading…
x
Reference in New Issue
Block a user