Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Identity UserManager and RoleManager implementations for interacting with Users and Roles. #1641

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Piranha.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "identity", "identity", "{9C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piranha.Manager.LocalAuth", "core\Piranha.Manager.LocalAuth\Piranha.Manager.LocalAuth.csproj", "{A88D6D8D-725E-494F-91CD-440D87BFF21B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Piranha.AspNetCore.Identity.EntityFrameworkCore", "identity\Piranha.AspNetCore.Identity.EntityFrameworkCore\Piranha.AspNetCore.Identity.EntityFrameworkCore.csproj", "{52E9EC4E-1E63-47E1-92EC-EE6BB09AEFFC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
5 changes: 4 additions & 1 deletion examples/MvcWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Piranha;
using Piranha.AspNetCore.Identity;
using Piranha.AspNetCore.Identity.EntityFrameworkCore;
using Piranha.Data.EF.SQLite;
using Piranha.AspNetCore.Identity.SQLite;
using Piranha.AttributeBuilder;
Expand All @@ -39,8 +41,9 @@ public void ConfigureServices(IServiceCollection services)

options.UseEF<SQLiteDb>(db =>
db.UseSqlite("Filename=./piranha.mvcweb.db"));
options.UseIdentityWithSeed<IdentitySQLiteDb>(db =>
options.UseIdentityEF<IdentitySQLiteDb>(db =>
db.UseSqlite("Filename=./piranha.mvcweb.db"));
options.UseIdentityWithSeed();

options.UseSecurity(o =>
{
Expand Down
1 change: 0 additions & 1 deletion examples/RazorWeb/RazorWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<ProjectReference Include="..\..\core\Piranha\Piranha.csproj" />
<ProjectReference Include="..\..\core\Piranha.AspNetCore\Piranha.AspNetCore.csproj" />
<ProjectReference Include="..\..\core\Piranha.AttributeBuilder\Piranha.AttributeBuilder.csproj" />
<ProjectReference Include="..\..\core\Piranha.Azure.BlobStorage\Piranha.Azure.BlobStorage.csproj" />
<ProjectReference Include="..\..\core\Piranha.ImageSharp\Piranha.ImageSharp.csproj" />
<ProjectReference Include="..\..\core\Piranha.Local.FileStorage\Piranha.Local.FileStorage.csproj" />
<ProjectReference Include="..\..\core\Piranha.Manager\Piranha.Manager.csproj" />
Expand Down
6 changes: 4 additions & 2 deletions examples/RazorWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Piranha;
using Piranha.AspNetCore.Identity;
using Piranha.AspNetCore.Identity.EntityFrameworkCore;
using Piranha.Data.EF.SQLite;
using Piranha.AspNetCore.Identity.SQLite;
using Piranha.AttributeBuilder;
Expand All @@ -39,8 +41,8 @@ public void ConfigureServices(IServiceCollection services)

options.UseEF<SQLiteDb>(db =>
db.UseSqlite("Filename=./piranha.razorweb.db"));
options.UseIdentityWithSeed<IdentitySQLiteDb>(db =>
db.UseSqlite("Filename=./piranha.razorweb.db"));
options.UseIdentityEF<IdentitySQLiteDb>(db =>
db.UseSqlite("Filename=./piranha.mvcweb.db"));

options.UseSecurity(o =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Microsoft.EntityFrameworkCore;
using Piranha.AspNetCore.Identity.Data;

namespace Piranha.AspNetCore.Identity
namespace Piranha.AspNetCore.Identity.EntityFrameworkCore
{
public abstract class Db<T> :
IdentityDbContext<User, Role, Guid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Microsoft.EntityFrameworkCore;
using Piranha.AspNetCore.Identity.Data;

namespace Piranha.AspNetCore.Identity
namespace Piranha.AspNetCore.Identity.EntityFrameworkCore
{
public interface IDb
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) .NET Foundation and Contributors
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
* http://github.com/piranhacms/piranha.core
*
*/

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Piranha.AspNetCore.Identity.Data;

namespace Piranha.AspNetCore.Identity.EntityFrameworkCore
{
public static class IdentityModuleExtensions
{
/// <summary>
/// Adds the Piranha identity module.
/// </summary>
/// <param name="services">The current service collection</param>
/// <param name="dbOptions">Options for configuring the database</param>
/// <returns>The services</returns>
public static IServiceCollection AddPiranhaIdentityEF<T>(this IServiceCollection services, Action<DbContextOptionsBuilder> dbOptions) where T : DbContext, IDb
{
services.AddDbContext<T>(dbOptions);
services.AddScoped<IDb, T>();
services.AddScoped<T, T>();
services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<T>();

return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) .NET Foundation and Contributors
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
* http://github.com/piranhacms/piranha.core
*
*/

using System;
using Microsoft.EntityFrameworkCore;

namespace Piranha.AspNetCore.Identity.EntityFrameworkCore
{
public static class IdentityStartupExtensions
{
/// <summary>
/// Extensions method for simplified setup.
/// </summary>
/// <param name="serviceBuilder">The current service builder</param>
/// <param name="dbOptions">The db options</param>
/// <typeparam name="T">The DbContext type</typeparam>
/// <returns>The builder</returns>
public static PiranhaServiceBuilder UseIdentityEF<T>(this PiranhaServiceBuilder serviceBuilder, Action<DbContextOptionsBuilder> dbOptions)
where T : Db<T>
{
serviceBuilder.Services.AddPiranhaIdentityEF<T>(dbOptions);

return serviceBuilder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<NoWarn>$(NoWarn);1591</NoWarn>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<Description>Piranha CMS security provider for AspNetCore Identity</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
<ProjectReference Include="..\Piranha.AspNetCore.Identity\Piranha.AspNetCore.Identity.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Piranha.AspNetCore.Identity.MySQL
{
public class IdentityMySQLDb : Identity.Db<IdentityMySQLDb>
public class IdentityMySQLDb : EntityFrameworkCore.Db<IdentityMySQLDb>
{
/// <summary>
/// Default constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.1" />
<ProjectReference Include="..\Piranha.AspNetCore.Identity\Piranha.AspNetCore.Identity.csproj" />
<ProjectReference Include="..\Piranha.AspNetCore.Identity.EntityFrameworkCore\Piranha.AspNetCore.Identity.EntityFrameworkCore.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Piranha.AspNetCore.Identity.PostgreSQL
{
public class IdentityPostgreSQLDb : Db<IdentityPostgreSQLDb>
public class IdentityPostgreSQLDb : EntityFrameworkCore.Db<IdentityPostgreSQLDb>
{
/// <summary>
/// Default constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0-rc2" />
<ProjectReference Include="..\Piranha.AspNetCore.Identity\Piranha.AspNetCore.Identity.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Piranha.AspNetCore.Identity.EntityFrameworkCore\Piranha.AspNetCore.Identity.EntityFrameworkCore.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Piranha.AspNetCore.Identity.SQLite
{
public class IdentitySQLiteDb : Db<IdentitySQLiteDb>
public class IdentitySQLiteDb : EntityFrameworkCore.Db<IdentitySQLiteDb>
{
/// <summary>
/// Default constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.0" />
<ProjectReference Include="..\Piranha.AspNetCore.Identity\Piranha.AspNetCore.Identity.csproj" />
<ProjectReference Include="..\Piranha.AspNetCore.Identity.EntityFrameworkCore\Piranha.AspNetCore.Identity.EntityFrameworkCore.csproj" />
</ItemGroup>

</Project>
Loading