Skip to content

Commit

Permalink
Separar clases dentro de IdentityConfig.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
feliperomero3 committed Apr 20, 2018
1 parent 4f4ea67 commit 30a39d0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 46 deletions.
5 changes: 4 additions & 1 deletion ApplicantTracking.Data/ApplicantTracking.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Identity\ApplicationSignInManager.cs" />
<Compile Include="Identity\ApplicationUserManager.cs" />
<Compile Include="Identity\EmailService.cs" />
<Compile Include="Identity\SmsService.cs" />
<Compile Include="Migrations\201803082336377_InitialCreate.cs" />
<Compile Include="Migrations\201803082336377_InitialCreate.Designer.cs">
<DependentUpon>201803082336377_InitialCreate.cs</DependentUpon>
Expand All @@ -98,7 +102,6 @@
<Compile Include="Identity\ApplicationDbContext.cs" />
<Compile Include="Identity\ApplicationUser.cs" />
<Compile Include="Repositories\IApplicantRepository.cs" />
<Compile Include="Identity\IdentityConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions ApplicantTracking.Data/Identity/ApplicationSignInManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security;

namespace ApplicantTracking.Data.Identity
{
// Configure the application sign-in manager which is used in this application.
public class ApplicationSignInManager : SignInManager<ApplicationUser, string>
{
public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
: base(userManager, authenticationManager)
{
}

public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser user)
{
return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
}

public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
{
return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security;

namespace ApplicantTracking.Data.Identity
{
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
return Task.FromResult(0);
}
}

public class SmsService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your SMS service here to send a text message.
return Task.FromResult(0);
}
}

// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
// Configure the application user manager used in this application.
// UserManager is defined in ASP.NET Identity and is used by the application.
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
}

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
// Configure validation logic for usernames
Expand Down Expand Up @@ -67,39 +46,25 @@ public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUs
{
MessageFormat = "Your security code is {0}"
});

manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<ApplicationUser>
{
Subject = "Security Code",
BodyFormat = "Your security code is {0}"
});

manager.EmailService = new EmailService();
manager.SmsService = new SmsService();

var dataProtectionProvider = options.DataProtectionProvider;

if (dataProtectionProvider != null)
{
manager.UserTokenProvider =
manager.UserTokenProvider =
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
}
return manager;
}
}

// Configure the application sign-in manager which is used in this application.
public class ApplicationSignInManager : SignInManager<ApplicationUser, string>
{
public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
: base(userManager, authenticationManager)
{
}

public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser user)
{
return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
}

public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
{
return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
return manager;
}
}
}
14 changes: 14 additions & 0 deletions ApplicantTracking.Data/Identity/EmailService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;

namespace ApplicantTracking.Data.Identity
{
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
return Task.FromResult(0);
}
}
}
14 changes: 14 additions & 0 deletions ApplicantTracking.Data/Identity/SmsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;

namespace ApplicantTracking.Data.Identity
{
public class SmsService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your SMS service here to send a text message.
return Task.FromResult(0);
}
}
}
2 changes: 1 addition & 1 deletion ApplicantTracking.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(ApplicantTracking.Web.Startup))]
[assembly: OwinStartup(typeof(ApplicantTracking.Web.Startup))]
namespace ApplicantTracking.Web
{
public partial class Startup
Expand Down

0 comments on commit 30a39d0

Please sign in to comment.