Skip to content

Commit

Permalink
target identityLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
logcorner committed Jan 6, 2018
1 parent ed21b98 commit b4b3eae
Show file tree
Hide file tree
Showing 18 changed files with 270 additions and 43 deletions.
12 changes: 12 additions & 0 deletions IdentityCore.Library/IdentityCore.Library.csproj
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.1" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions IdentityCore.Library/MyIdentityRole.cs
@@ -0,0 +1,26 @@
namespace IdentityCore.Library
{
using Microsoft.AspNetCore.Identity;
using System;

public class MyIdentityRole<T> : IdentityRole<string>
{
public MyIdentityRole()
{
Id = Guid.NewGuid().ToString();
}

public MyIdentityRole(string name) : this()
{
Name = name;
}

public MyIdentityRole(string name, string id)
{
Name = name;
Id = id;
}

public string Description { get; internal set; }
}
}
17 changes: 17 additions & 0 deletions IdentityCore.Library/MyIdentityUser.cs
@@ -0,0 +1,17 @@
namespace IdentityCore.Library
{
using Microsoft.AspNetCore.Identity;
using System;

public class MyIdentityUser : IdentityUser
{
public DateTime? JoinDate { get; set; }
public string JobTitle { get; set; }
public string Contract { get; set; }

public MyIdentityUser()
{
Id = Guid.NewGuid().ToString();
}
}
}
65 changes: 65 additions & 0 deletions IdentityCore.Library/MyRoleStore.cs
@@ -0,0 +1,65 @@
using Microsoft.AspNetCore.Identity;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace IdentityCore.Library
{
public class MyRoleStore<T> : IRoleStore<T> where T : MyIdentityRole<string>
{
public Task<IdentityResult> CreateAsync(T role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<IdentityResult> DeleteAsync(T role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public void Dispose()
{
//throw new NotImplementedException();
}

public Task<T> FindByIdAsync(string roleId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<T> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<string> GetNormalizedRoleNameAsync(T role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<string> GetRoleIdAsync(T role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<string> GetRoleNameAsync(T role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task SetNormalizedRoleNameAsync(T role, string normalizedName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task SetRoleNameAsync(T role, string roleName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<IdentityResult> UpdateAsync(T role, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
66 changes: 66 additions & 0 deletions IdentityCore.Library/MyUserStore.cs
@@ -0,0 +1,66 @@
using Microsoft.AspNetCore.Identity;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace IdentityCore.Library
{
public class MyUserStore<T> : IUserStore<T> where T : MyIdentityUser
{
public Task<IdentityResult> CreateAsync(T user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<IdentityResult> DeleteAsync(T user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public void Dispose()
{
//throw new NotImplementedException();
}

public Task<T> FindByIdAsync(string userId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<T> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
{
//TODO : implement database logic to get the user by name
throw new NotImplementedException();
}

public Task<string> GetNormalizedUserNameAsync(T user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<string> GetUserIdAsync(T user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<string> GetUserNameAsync(T user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task SetNormalizedUserNameAsync(T user, string normalizedName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task SetUserNameAsync(T user, string userName, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task<IdentityResult> UpdateAsync(T user, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
31 changes: 31 additions & 0 deletions WebApplication.sln
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2003
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication", "WebApplication\WebApplication.csproj", "{ACFBC569-D489-4CF0-90D6-BA973A1EF058}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityCore.Library", "IdentityCore.Library\IdentityCore.Library.csproj", "{EA25B28F-7C10-4815-9276-70E8DBEB11E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ACFBC569-D489-4CF0-90D6-BA973A1EF058}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACFBC569-D489-4CF0-90D6-BA973A1EF058}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACFBC569-D489-4CF0-90D6-BA973A1EF058}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACFBC569-D489-4CF0-90D6-BA973A1EF058}.Release|Any CPU.Build.0 = Release|Any CPU
{EA25B28F-7C10-4815-9276-70E8DBEB11E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA25B28F-7C10-4815-9276-70E8DBEB11E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA25B28F-7C10-4815-9276-70E8DBEB11E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA25B28F-7C10-4815-9276-70E8DBEB11E9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {530A232D-3D7A-4367-9825-7D79A21DCD51}
EndGlobalSection
EndGlobal
16 changes: 8 additions & 8 deletions WebApplication/Controllers/AccountController.cs
@@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Authentication;
using IdentityCore.Library;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using WebApplication.Models;
using WebApplication.Models.AccountViewModels;
using WebApplication.Services;

Expand All @@ -16,14 +16,14 @@ namespace WebApplication.Controllers
[Route("[controller]/[action]")]
public class AccountController : Controller
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly UserManager<MyIdentityUser> _userManager;
private readonly SignInManager<MyIdentityUser> _signInManager;
private readonly IEmailSender _emailSender;
private readonly ILogger _logger;

public AccountController(
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager,
UserManager<MyIdentityUser> userManager,
SignInManager<MyIdentityUser> signInManager,
IEmailSender emailSender,
ILogger<AccountController> logger)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ public async Task<IActionResult> Register(RegisterViewModel model, string return
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var user = new MyIdentityUser { UserName = model.Email, Email = model.Email };
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
Expand Down Expand Up @@ -306,7 +306,7 @@ public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginViewMode
{
throw new ApplicationException("Error loading external login information during confirmation.");
}
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var user = new MyIdentityUser { UserName = model.Email, Email = model.Email };
var result = await _userManager.CreateAsync(user);
if (result.Succeeded)
{
Expand Down
12 changes: 6 additions & 6 deletions WebApplication/Controllers/ManageController.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authentication;
using IdentityCore.Library;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -8,7 +9,6 @@
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using WebApplication.Models;
using WebApplication.Models.ManageViewModels;
using WebApplication.Services;

Expand All @@ -18,17 +18,17 @@ namespace WebApplication.Controllers
[Route("[controller]/[action]")]
public class ManageController : Controller
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly UserManager<MyIdentityUser> _userManager;
private readonly SignInManager<MyIdentityUser> _signInManager;
private readonly IEmailSender _emailSender;
private readonly ILogger _logger;
private readonly UrlEncoder _urlEncoder;

private const string AuthenicatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";

public ManageController(
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager,
UserManager<MyIdentityUser> userManager,
SignInManager<MyIdentityUser> signInManager,
IEmailSender emailSender,
ILogger<ManageController> logger,
UrlEncoder urlEncoder)
Expand Down
6 changes: 3 additions & 3 deletions WebApplication/Data/ApplicationDbContext.cs
@@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using IdentityCore.Library;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using WebApplication.Models;

namespace WebApplication.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
public class ApplicationDbContext : IdentityDbContext<MyIdentityUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b4b3eae

Please sign in to comment.