Skip to content

Commit

Permalink
Add custome managers
Browse files Browse the repository at this point in the history
  • Loading branch information
dev.soheilalizadeh committed Dec 19, 2018
1 parent 23362d2 commit 5db49c6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
20 changes: 20 additions & 0 deletions App/Services/Identity/Managers/AppRoleManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using App.Domain.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;

namespace App.Services.Identity.Managers
{
public class AppRoleManager : RoleManager<Role>
{
public AppRoleManager(
IRoleStore<Role> store,
IEnumerable<IRoleValidator<Role>> roleValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
ILogger<RoleManager<Role>> logger
) : base(store, roleValidators, keyNormalizer, errors, logger)
{
}
}
}
23 changes: 23 additions & 0 deletions App/Services/Identity/Managers/AppSignInManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using App.Domain.Identity;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace App.Services.Identity.Managers
{
public class AppSignInManager : SignInManager<User>
{
public AppSignInManager(
UserManager<User> userManager,
IHttpContextAccessor contextAccessor,
IUserClaimsPrincipalFactory<User> claimsFactory,
IOptions<IdentityOptions> optionsAccessor,
ILogger<SignInManager<User>> logger,
IAuthenticationSchemeProvider schemes
) : base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemes)
{
}
}
}
28 changes: 28 additions & 0 deletions App/Services/Identity/Managers/AppUserManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using App.Domain.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace App.Services.Identity.Managers
{
public class AppUserManager : UserManager<User>
{
public AppUserManager(
IUserStore<User> store,
IOptions<IdentityOptions> optionsAccessor,
IPasswordHasher<User> passwordHasher,
IEnumerable<IUserValidator<User>> userValidators,
IEnumerable<IPasswordValidator<User>> passwordValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
IServiceProvider services,
ILogger<UserManager<User>> logger
) : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors,
services, logger)
{
}

}
}
8 changes: 5 additions & 3 deletions App/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using App.Data;
using App.Domain;
using App.Domain.Identity;
using App.Services.Identity.Managers;
using App.Services.Identity.Stores;
using App.Services.Identity.Validators;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -53,17 +54,18 @@ public void ConfigureServices(IServiceCollection services)
option.Password.RequireUppercase = true;
option.SignIn.RequireConfirmedEmail = true;
})
.AddUserStore<AppUserStore>()
.AddRoleStore<AppRoleStore>()
.AddUserValidator<AppUserValidator>()
.AddRoleValidator<AppRoleValidator>()
.AddUserManager<AppUserManager>()
.AddRoleManager<AppRoleManager>()
.AddSignInManager<AppSignInManager>()
.AddDefaultTokenProviders();

}


public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
Expand Down

0 comments on commit 5db49c6

Please sign in to comment.