Add AuthController and configure authentication/identity services
This commit is contained in:
10
API/Controllers/AuthController.cs
Normal file
10
API/Controllers/AuthController.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/account")]
|
||||||
|
public class AuthController : ControllerBase
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using API.Database;
|
using API.Database;
|
||||||
using API.Models.Internal.User;
|
using API.Models.Internal.User;
|
||||||
using API.Repository.AgeGroup;
|
using API.Repository.AgeGroup;
|
||||||
|
using API.Services;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
var webRoot = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..", "wwwroot"));
|
var webRoot = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..", "wwwroot"));
|
||||||
@@ -21,9 +23,12 @@ builder.Services.AddAuthorization();
|
|||||||
builder.Services.AddAuthentication()
|
builder.Services.AddAuthentication()
|
||||||
.AddCookie(IdentityConstants.ApplicationScheme);
|
.AddCookie(IdentityConstants.ApplicationScheme);
|
||||||
|
|
||||||
builder.Services.AddIdentityCore<User>()
|
builder.Services.AddIdentityCore<User>(options =>
|
||||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
{
|
||||||
.AddApiEndpoints();
|
options.SignIn.RequireConfirmedAccount = true;
|
||||||
|
options.User.RequireUniqueEmail = true;
|
||||||
|
}).AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
|
||||||
|
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
var postgresConnection = builder.Configuration.GetConnectionString("PostgresConnection");
|
var postgresConnection = builder.Configuration.GetConnectionString("PostgresConnection");
|
||||||
@@ -37,6 +42,9 @@ else
|
|||||||
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite("Data Source=app.db"));
|
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite("Data Source=app.db"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adding Email Service (Plunk)
|
||||||
|
builder.Services.AddHttpClient<IEmailSender, PlunkEmailSender>();
|
||||||
|
|
||||||
// Adding Database Services
|
// Adding Database Services
|
||||||
builder.Services.AddScoped<IAgeGroupService, AgeGroupService>();
|
builder.Services.AddScoped<IAgeGroupService, AgeGroupService>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user