diff --git a/.gitignore b/.gitignore index 7ade57d..8307032 100644 --- a/.gitignore +++ b/.gitignore @@ -292,4 +292,5 @@ __pycache__/ *.btp.cs *.btm.cs *.odx.cs -*.xsd.cs \ No newline at end of file +*.xsd.cs +/Src/SampleWebSite/MyConnectionStrings.config diff --git a/README.md b/README.md index aa33195..65e6baf 100644 --- a/README.md +++ b/README.md @@ -16,28 +16,28 @@ This is an example to implement a OracleDatabase store for ASP.NET Identity 2.0 Steps to run project -- Open project in VS with Update 2 or later installed +- Open project in Latest Visual Studio 2017 or later installed - Build project to restore packages and build project - In the solution, add a new one ASP.NET project with MVC and Individual Authentication - Uninstall Microsoft.AspNet.Identity.EntityFramework package from the web application - Update connection string to use the OracleDatabase database as needed - - Make the file "MyConnectionStrings.config" into the project SampleWebSite's root folder - - e.g. - ``` + - Make the file `MyConnectionStrings.config` into the project SampleWebSite's root folder + - e.g. +``` - ``` +``` - In the IdentityModel.cs (in the SampleWebProject), let ApplicationUser class extend from Identity user in AspNet.Identity.Oracle - - e.g - ``` + - e.g +``` using AspNet.Identity.Oracle; // using Microsoft.AspNet.Identity.EntityFramework; - ``` +``` - ApplicationDbContext extend from OracleDatabase and the contructor take a single parameter with the connectionstring name ``` public class ApplicationDbContext : OracleDatabase @@ -61,18 +61,17 @@ var manager = new ApplicationRoleManager(new RoleStore(context.Get you can write some code block at the InitializeDb method or InitializeIdentity method in the ApplicationDbInitializer class (in the IdentityConfig.cs) - This SampleWebSite project enabled initial admin account as shoen below - ``` +``` const string name = "admin@admin.com"; const string password = "Admin@123456"; const string roleName = "Admin"; - ``` +``` - Before you do debugging, you must create the tables in the database. - Please run DDL Script, "OracleIdentity.sql.txt" in the AspNet.Identity.Oracle project. + Please run DDL Script, `OracleIdentity.sql.txt` in the AspNet.Identity.Oracle project. - If you have an error appears at the start of debugging, please try the following below. - - To start the Visual Studio by "Run as Administrator". - - Debugging on the "Local IIS" not "IIS Express". - - Check build platform Win32 or x64, this project and installed ODP.NET. + - Debugging on the `IIS Express`. + - Check build platform Win32 or x64, this project and installed ODP.NET. (means Not Oracle.ManagedAccess) Notice diff --git a/Src/AspNet.Identity.Oracle/AspNet.Identity.Oracle.csproj b/Src/AspNet.Identity.Oracle/AspNet.Identity.Oracle.csproj index 883f035..03de596 100644 --- a/Src/AspNet.Identity.Oracle/AspNet.Identity.Oracle.csproj +++ b/Src/AspNet.Identity.Oracle/AspNet.Identity.Oracle.csproj @@ -58,8 +58,8 @@ MinimumRecommendedRules.ruleset - - ..\packages\Microsoft.AspNet.Identity.Core.2.0.0\lib\net45\Microsoft.AspNet.Identity.Core.dll + + ..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll False diff --git a/Src/AspNet.Identity.Oracle/Properties/AssemblyInfo.cs b/Src/AspNet.Identity.Oracle/Properties/AssemblyInfo.cs index 8451ac8..d82509d 100644 --- a/Src/AspNet.Identity.Oracle/Properties/AssemblyInfo.cs +++ b/Src/AspNet.Identity.Oracle/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.3.0")] +[assembly: AssemblyFileVersion("1.0.3.0")] diff --git a/Src/AspNet.Identity.Oracle/Readme.txt b/Src/AspNet.Identity.Oracle/Readme.txt index cc78559..9e97034 100644 --- a/Src/AspNet.Identity.Oracle/Readme.txt +++ b/Src/AspNet.Identity.Oracle/Readme.txt @@ -2,28 +2,28 @@ Steps to run project -- Open project in VS with Update 2 or later installed +- Open project in Latest Visual Studio 2017 or later installed - Build project to restore packages and build project - In the solution, add a new one ASP.NET project with MVC and Individual Authentication - Uninstall Microsoft.AspNet.Identity.EntityFramework package from the web application - Update connection string to use the OracleDatabase database as needed - - Make the file "MyConnectionStrings.config" into the project SampleWebSite's root folder - - e.g. - ``` + - Make the file `MyConnectionStrings.config` into the project SampleWebSite's root folder + - e.g. +``` - ``` +``` - In the IdentityModel.cs (in the SampleWebProject), let ApplicationUser class extend from Identity user in AspNet.Identity.Oracle - - e.g - ``` + - e.g +``` using AspNet.Identity.Oracle; // using Microsoft.AspNet.Identity.EntityFramework; - ``` +``` - ApplicationDbContext extend from OracleDatabase and the contructor take a single parameter with the connectionstring name ``` public class ApplicationDbContext : OracleDatabase @@ -47,17 +47,15 @@ var manager = new ApplicationRoleManager(new RoleStore(context.Get you can write some code block at the InitializeDb method or InitializeIdentity method in the ApplicationDbInitializer class (in the IdentityConfig.cs) - This SampleWebSite project enabled initial admin account as shoen below - ``` +``` const string name = "admin@admin.com"; const string password = "Admin@123456"; const string roleName = "Admin"; - ``` +``` - Before you do debugging, you must create the tables in the database. - Please run DDL Script, "OracleIdentity.sql.txt" in the AspNet.Identity.Oracle project. + Please run DDL Script, `OracleIdentity.sql.txt` in the AspNet.Identity.Oracle project. - If you have an error appears at the start of debugging, please try the following below. - - To start the Visual Studio by "Run as Administrator". - - Debugging on the "Local IIS" not "IIS Express". - - Check build platform Win32 or x64, this project and installed ODP.NET. + - Debugging on the `IIS Express`. + - Check build platform Win32 or x64, this project and installed ODP.NET. (means Not Oracle.ManagedAccess) -// \ No newline at end of file diff --git a/Src/AspNet.Identity.Oracle/packages.config b/Src/AspNet.Identity.Oracle/packages.config index d741e82..c1706a6 100644 --- a/Src/AspNet.Identity.Oracle/packages.config +++ b/Src/AspNet.Identity.Oracle/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Src/SampleWebSite/App_Start/BundleConfig.cs b/Src/SampleWebSite/App_Start/BundleConfig.cs index 5a52701..66dba65 100644 --- a/Src/SampleWebSite/App_Start/BundleConfig.cs +++ b/Src/SampleWebSite/App_Start/BundleConfig.cs @@ -1,6 +1,6 @@ using System.Web.Optimization; -namespace IdentitySample +namespace SampleWebSite { public class BundleConfig { diff --git a/Src/SampleWebSite/App_Start/FilterConfig.cs b/Src/SampleWebSite/App_Start/FilterConfig.cs index f545453..5d2c508 100644 --- a/Src/SampleWebSite/App_Start/FilterConfig.cs +++ b/Src/SampleWebSite/App_Start/FilterConfig.cs @@ -1,6 +1,6 @@ using System.Web.Mvc; -namespace IdentitySample +namespace SampleWebSite { public class FilterConfig { diff --git a/Src/SampleWebSite/App_Start/IdentityConfig.cs b/Src/SampleWebSite/App_Start/IdentityConfig.cs index f006f4a..d696cd5 100644 --- a/Src/SampleWebSite/App_Start/IdentityConfig.cs +++ b/Src/SampleWebSite/App_Start/IdentityConfig.cs @@ -10,8 +10,9 @@ using System.Threading.Tasks; using System.Web; using AspNet.Identity.Oracle; +using SampleWebSite.Models; -namespace IdentitySample.Models +namespace SampleWebSite { // 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 @@ -156,107 +157,6 @@ public Task SendAsync(IdentityMessage message) } } - - //This is useful if you do not want to tear down the database each time you run the application. - public sealed class ApplicationDbInitializer : IDisposable - { - private static readonly object ThisLock = new object(); - private static volatile ApplicationDbInitializer _applicationDbInitializer; - - private bool _isInitialized; - - private ApplicationDbInitializer(IOwinContext context) - { - Seed(context); - } - - public static ApplicationDbInitializer Create(IdentityFactoryOptions options, IOwinContext context) - { - if (_applicationDbInitializer != null) - return _applicationDbInitializer; - - lock (ThisLock) - { - if (_applicationDbInitializer != null) return _applicationDbInitializer; - _applicationDbInitializer = new ApplicationDbInitializer(context); - } - return _applicationDbInitializer; - } - - /// - /// Run Once Initialize code blocks. - /// - /// - private void Seed(IOwinContext context) - { - if (_isInitialized) return; - - InitializeDb(context); - InitializeIdentity(context); - - _isInitialized = true; - } - - // Verify Db or Tables and Create it, If you need. - private static void InitializeDb(IOwinContext context) - { - // var oracleDatabase = context.Get() as OracleDatabase; - // e.g. Run the DDL if Table is not. - } - - // Create Sample Admin User: admin@admin.com with password: Admin@123456 in the Admin role - private static void InitializeIdentity(IOwinContext context) - { - var userManager = context.GetUserManager(); - var roleManager = context.Get(); - - const string name = "admin@admin.com"; - const string password = "Admin@123456"; - const string roleName = "Admin"; - - //Create Role Admin if it does not exist - var role = roleManager.FindByName(roleName); - if (role == null) { - role = new IdentityRole(roleName); - var roleresult = roleManager.Create(role); - } - - var user = userManager.FindByName(name); - if (user == null) { - user = new ApplicationUser { UserName = name, Email = name }; - var result = userManager.Create(user, password); - result = userManager.SetLockoutEnabled(user.Id, false); - } - - // Add user admin to Role Admin if not already added - var rolesForUser = userManager.GetRoles(user.Id); - if (!rolesForUser.Contains(role.Name)) { - var result = userManager.AddToRole(user.Id, role.Name); - } - } - - bool _disposed; - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (_disposed) return; - - if (disposing) - { - // Free any other managed objects here. - } - - // Free any unmanaged objects here. - _disposed = true; - } - } - public enum SignInStatus { Success, diff --git a/Src/SampleWebSite/App_Start/RouteConfig.cs b/Src/SampleWebSite/App_Start/RouteConfig.cs index 4f0167f..9ca2476 100644 --- a/Src/SampleWebSite/App_Start/RouteConfig.cs +++ b/Src/SampleWebSite/App_Start/RouteConfig.cs @@ -1,7 +1,7 @@ using System.Web.Mvc; using System.Web.Routing; -namespace IdentitySample { +namespace SampleWebSite { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); diff --git a/Src/SampleWebSite/App_Start/Startup.Auth.cs b/Src/SampleWebSite/App_Start/Startup.Auth.cs index d3c7086..256d662 100644 --- a/Src/SampleWebSite/App_Start/Startup.Auth.cs +++ b/Src/SampleWebSite/App_Start/Startup.Auth.cs @@ -1,18 +1,18 @@ -using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Identity.Owin; -using Microsoft.Owin; -using Microsoft.Owin.Security.Cookies; -using IdentitySample.Models; -using Owin; -using System; - -namespace IdentitySample { - public partial class Startup { - // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 - public void ConfigureAuth(IAppBuilder app) { - // Configure the db context, user manager and role manager to use a single instance per request - app.CreatePerOwinContext(ApplicationDbContext.Create); - app.CreatePerOwinContext(ApplicationUserManager.Create); +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.Owin; +using Microsoft.Owin; +using Microsoft.Owin.Security.Cookies; +using Owin; +using System; +using SampleWebSite.Models; + +namespace SampleWebSite { + public partial class Startup { + // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 + public void ConfigureAuth(IAppBuilder app) { + // Configure the db context, user manager and role manager to use a single instance per request + app.CreatePerOwinContext(ApplicationDbContext.Create); + app.CreatePerOwinContext(ApplicationUserManager.Create); app.CreatePerOwinContext(ApplicationRoleManager.Create); // Run once initializing code. @@ -20,46 +20,46 @@ public void ConfigureAuth(IAppBuilder app) { // .CreatePerOwinContext(ApplicationUserManager.Create); // .CreatePerOwinContext(ApplicationRoleManager.Create); // callings. - app.CreatePerOwinContext(ApplicationDbInitializer.Create); - - // Enable the application to use a cookie to store information for the signed in user - // and to use a cookie to temporarily store information about a user logging in with a third party login provider - // Configure the sign in cookie - app.UseCookieAuthentication(new CookieAuthenticationOptions { - AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, - LoginPath = new PathString("/Account/Login"), - Provider = new CookieAuthenticationProvider { - // Enables the application to validate the security stamp when the user logs in. - // This is a security feature which is used when you change a password or add an external login to your account. - OnValidateIdentity = SecurityStampValidator.OnValidateIdentity( - validateInterval: TimeSpan.FromMinutes(30), - regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) - } - }); - app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); - - // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. - app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); - - // Enables the application to remember the second login verification factor such as phone or email. - // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. - // This is similar to the RememberMe option when you log in. - app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); - - // Uncomment the following lines to enable logging in with third party login providers - //app.UseMicrosoftAccountAuthentication( - // clientId: "", - // clientSecret: ""); - - //app.UseTwitterAuthentication( - // consumerKey: "", - // consumerSecret: ""); - - //app.UseFacebookAuthentication( - // appId: "", - // appSecret: ""); - - //app.UseGoogleAuthentication(); - } - } + app.CreatePerOwinContext(ApplicationDbInitializer.Create); + + // Enable the application to use a cookie to store information for the signed in user + // and to use a cookie to temporarily store information about a user logging in with a third party login provider + // Configure the sign in cookie + app.UseCookieAuthentication(new CookieAuthenticationOptions { + AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, + LoginPath = new PathString("/Account/Login"), + Provider = new CookieAuthenticationProvider { + // Enables the application to validate the security stamp when the user logs in. + // This is a security feature which is used when you change a password or add an external login to your account. + OnValidateIdentity = SecurityStampValidator.OnValidateIdentity( + validateInterval: TimeSpan.FromMinutes(30), + regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) + } + }); + app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); + + // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. + app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); + + // Enables the application to remember the second login verification factor such as phone or email. + // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. + // This is similar to the RememberMe option when you log in. + app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); + + // Uncomment the following lines to enable logging in with third party login providers + //app.UseMicrosoftAccountAuthentication( + // clientId: "", + // clientSecret: ""); + + //app.UseTwitterAuthentication( + // consumerKey: "", + // consumerSecret: ""); + + //app.UseFacebookAuthentication( + // appId: "", + // appSecret: ""); + + //app.UseGoogleAuthentication(); + } + } } \ No newline at end of file diff --git a/Src/SampleWebSite/Controllers/AccountController.cs b/Src/SampleWebSite/Controllers/AccountController.cs index 5715e1b..e84619c 100644 --- a/Src/SampleWebSite/Controllers/AccountController.cs +++ b/Src/SampleWebSite/Controllers/AccountController.cs @@ -1,5 +1,4 @@ using System.Globalization; -using IdentitySample.Models; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.Owin; using Microsoft.Owin.Security; @@ -9,8 +8,10 @@ using System.Threading.Tasks; using System.Web; using System.Web.Mvc; +using SampleWebSite.Models; +using SampleWebSite.ViewModels; -namespace IdentitySample.Controllers +namespace SampleWebSite.Controllers { [Authorize] public class AccountController : Controller diff --git a/Src/SampleWebSite/Controllers/HomeController.cs b/Src/SampleWebSite/Controllers/HomeController.cs index 25c9393..7caa588 100644 --- a/Src/SampleWebSite/Controllers/HomeController.cs +++ b/Src/SampleWebSite/Controllers/HomeController.cs @@ -1,6 +1,6 @@ using System.Web.Mvc; -namespace IdentitySample.Controllers { +namespace SampleWebSite.Controllers { public class HomeController : Controller { public ActionResult Index() { diff --git a/Src/SampleWebSite/Controllers/ManageController.cs b/Src/SampleWebSite/Controllers/ManageController.cs index 542ca74..45cc244 100644 --- a/Src/SampleWebSite/Controllers/ManageController.cs +++ b/Src/SampleWebSite/Controllers/ManageController.cs @@ -1,13 +1,14 @@ -using IdentitySample.Models; -using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.Owin; using Microsoft.Owin.Security; using System.Linq; using System.Threading.Tasks; using System.Web; using System.Web.Mvc; +using SampleWebSite.Models; +using SampleWebSite.ViewModels; -namespace IdentitySample.Controllers +namespace SampleWebSite.Controllers { [Authorize] public class ManageController : Controller diff --git a/Src/SampleWebSite/Controllers/RolesAdminController.cs b/Src/SampleWebSite/Controllers/RolesAdminController.cs index 4b00f85..e1e0c96 100644 --- a/Src/SampleWebSite/Controllers/RolesAdminController.cs +++ b/Src/SampleWebSite/Controllers/RolesAdminController.cs @@ -1,5 +1,4 @@ -using IdentitySample.Models; -using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.Owin; using System.Linq; using System.Net; @@ -8,8 +7,10 @@ using System.Web.Mvc; using System.Collections.Generic; using AspNet.Identity.Oracle; +using SampleWebSite.Models; +using SampleWebSite.ViewModels; -namespace IdentitySample.Controllers +namespace SampleWebSite.Controllers { [Authorize(Roles = "Admin")] public class RolesAdminController : Controller diff --git a/Src/SampleWebSite/Controllers/UserAdminController.cs b/Src/SampleWebSite/Controllers/UserAdminController.cs index 3f43b2e..daab6ea 100644 --- a/Src/SampleWebSite/Controllers/UserAdminController.cs +++ b/Src/SampleWebSite/Controllers/UserAdminController.cs @@ -1,5 +1,4 @@ -using IdentitySample.Models; -using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.Owin; using System; using System.Collections.Generic; @@ -9,8 +8,10 @@ using System.Threading.Tasks; using System.Web; using System.Web.Mvc; +using SampleWebSite.Models; +using SampleWebSite.ViewModels; -namespace IdentitySample.Controllers +namespace SampleWebSite.Controllers { [Authorize(Roles = "Admin")] public class UsersAdminController : Controller diff --git a/Src/SampleWebSite/Global.asax b/Src/SampleWebSite/Global.asax index 011baa3..22b96a5 100644 --- a/Src/SampleWebSite/Global.asax +++ b/Src/SampleWebSite/Global.asax @@ -1 +1 @@ -<%@ Application Codebehind="Global.asax.cs" Inherits="IdentitySample.MvcApplication" Language="C#" %> +<%@ Application Codebehind="Global.asax.cs" Inherits="SampleWebSite.MvcApplication" Language="C#" %> diff --git a/Src/SampleWebSite/Global.asax.cs b/Src/SampleWebSite/Global.asax.cs index d618d93..3438539 100644 --- a/Src/SampleWebSite/Global.asax.cs +++ b/Src/SampleWebSite/Global.asax.cs @@ -1,10 +1,10 @@ -using IdentitySample.Models; +using SampleWebSite.Models; using System.Data.Entity; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; -namespace IdentitySample +namespace SampleWebSite { // Note: For instructions on enabling IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=301868 diff --git a/Src/SampleWebSite/Models/ApplicationDbInitializer.cs b/Src/SampleWebSite/Models/ApplicationDbInitializer.cs new file mode 100644 index 0000000..6a891ff --- /dev/null +++ b/Src/SampleWebSite/Models/ApplicationDbInitializer.cs @@ -0,0 +1,109 @@ +using System; +using AspNet.Identity.Oracle; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.Owin; +using Microsoft.Owin; + +namespace SampleWebSite.Models +{ + //This is useful if you do not want to tear down the database each time you run the application. + public sealed class ApplicationDbInitializer : IDisposable + { + private static readonly object ThisLock = new object(); + private static volatile ApplicationDbInitializer _applicationDbInitializer; + + private bool _isInitialized; + + private ApplicationDbInitializer(IOwinContext context) + { + Seed(context); + } + + public static ApplicationDbInitializer Create(IdentityFactoryOptions options, IOwinContext context) + { + if (_applicationDbInitializer != null) + return _applicationDbInitializer; + + lock (ThisLock) + { + if (_applicationDbInitializer != null) return _applicationDbInitializer; + _applicationDbInitializer = new ApplicationDbInitializer(context); + } + return _applicationDbInitializer; + } + + /// + /// Run Once Initialize code blocks. + /// + /// + private void Seed(IOwinContext context) + { + if (_isInitialized) return; + + InitializeDb(context); + InitializeIdentity(context); + + _isInitialized = true; + } + + // Verify Db or Tables and Create it, If you need. + private static void InitializeDb(IOwinContext context) + { + // var oracleDatabase = context.Get() as OracleDatabase; + // e.g. Run the DDL if Table is not. + } + + // Create Sample Admin User: admin@admin.com with password: Admin@123456 in the Admin role + private static void InitializeIdentity(IOwinContext context) + { + var userManager = context.GetUserManager(); + var roleManager = context.Get(); + + // TODO: !!ATTENTION!! Please change yours setting. + const string name = "admin@admin.com"; + const string password = "Admin@123456"; + const string roleName = "Admin"; + + //Create Role Admin if it does not exist + var role = roleManager.FindByName(roleName); + if (role == null) { + role = new IdentityRole(roleName); + roleManager.Create(role); + } + + var user = userManager.FindByName(name); + if (user == null) { + user = new ApplicationUser { UserName = name, Email = name }; + userManager.Create(user, password); + userManager.SetLockoutEnabled(user.Id, false); + } + + // Add user admin to Role Admin if not already added + var rolesForUser = userManager.GetRoles(user.Id); + if (!rolesForUser.Contains(role.Name)) { + userManager.AddToRole(user.Id, role.Name); + } + } + + bool _disposed; + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (_disposed) return; + + if (disposing) + { + // Free any other managed objects here. + } + + // Free any unmanaged objects here. + _disposed = true; + } + } +} \ No newline at end of file diff --git a/Src/SampleWebSite/Models/IdentityModels.cs b/Src/SampleWebSite/Models/IdentityModels.cs index e2541c7..af4a50a 100644 --- a/Src/SampleWebSite/Models/IdentityModels.cs +++ b/Src/SampleWebSite/Models/IdentityModels.cs @@ -4,7 +4,7 @@ using System.Security.Claims; using System.Threading.Tasks; -namespace IdentitySample.Models { +namespace SampleWebSite.Models { // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. public class ApplicationUser : IdentityUser { public async Task GenerateUserIdentityAsync(UserManager manager) { diff --git a/Src/SampleWebSite/SampleWebSite.csproj b/Src/SampleWebSite/SampleWebSite.csproj index f7f5b01..87b303c 100644 --- a/Src/SampleWebSite/SampleWebSite.csproj +++ b/Src/SampleWebSite/SampleWebSite.csproj @@ -81,8 +81,8 @@ ..\packages\Microsoft.Owin.Security.Twitter.2.1.0\lib\net45\Microsoft.Owin.Security.Twitter.dll - - True + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll ..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll @@ -218,6 +218,7 @@ + @@ -231,10 +232,10 @@ Global.asax - - + + - + diff --git a/Src/SampleWebSite/Startup.cs b/Src/SampleWebSite/Startup.cs index f0bd2f0..c75f21d 100644 --- a/Src/SampleWebSite/Startup.cs +++ b/Src/SampleWebSite/Startup.cs @@ -1,6 +1,6 @@ using Owin; -namespace IdentitySample +namespace SampleWebSite { public partial class Startup { diff --git a/Src/SampleWebSite/Models/AccountViewModels.cs b/Src/SampleWebSite/ViewModels/AccountViewModels.cs similarity index 98% rename from Src/SampleWebSite/Models/AccountViewModels.cs rename to Src/SampleWebSite/ViewModels/AccountViewModels.cs index be9150d..e143db3 100644 --- a/Src/SampleWebSite/Models/AccountViewModels.cs +++ b/Src/SampleWebSite/ViewModels/AccountViewModels.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -namespace IdentitySample.Models { +namespace SampleWebSite.ViewModels { public class ExternalLoginConfirmationViewModel { [Required] [Display(Name = "Email")] diff --git a/Src/SampleWebSite/Models/AdminViewModel.cs b/Src/SampleWebSite/ViewModels/AdminViewModel.cs similarity index 94% rename from Src/SampleWebSite/Models/AdminViewModel.cs rename to Src/SampleWebSite/ViewModels/AdminViewModel.cs index 38078bc..58e10c6 100644 --- a/Src/SampleWebSite/Models/AdminViewModel.cs +++ b/Src/SampleWebSite/ViewModels/AdminViewModel.cs @@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.Web.Mvc; -namespace IdentitySample.Models +namespace SampleWebSite.ViewModels { public class RoleViewModel { diff --git a/Src/SampleWebSite/Models/ManageViewModels.cs b/Src/SampleWebSite/ViewModels/ManageViewModels.cs similarity index 98% rename from Src/SampleWebSite/Models/ManageViewModels.cs rename to Src/SampleWebSite/ViewModels/ManageViewModels.cs index cc1327d..3c80e19 100644 --- a/Src/SampleWebSite/Models/ManageViewModels.cs +++ b/Src/SampleWebSite/ViewModels/ManageViewModels.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNet.Identity; -using Microsoft.Owin.Security; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Microsoft.AspNet.Identity; +using Microsoft.Owin.Security; -namespace IdentitySample.Models { +namespace SampleWebSite.ViewModels { public class IndexViewModel { public bool HasPassword { get; set; } public IList Logins { get; set; } diff --git a/Src/SampleWebSite/Views/Account/ExternalLoginConfirmation.cshtml b/Src/SampleWebSite/Views/Account/ExternalLoginConfirmation.cshtml index 0b94786..9232f20 100644 --- a/Src/SampleWebSite/Views/Account/ExternalLoginConfirmation.cshtml +++ b/Src/SampleWebSite/Views/Account/ExternalLoginConfirmation.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ExternalLoginConfirmationViewModel +@model SampleWebSite.ViewModels.ExternalLoginConfirmationViewModel @{ ViewBag.Title = "Register"; } diff --git a/Src/SampleWebSite/Views/Account/ForgotPassword.cshtml b/Src/SampleWebSite/Views/Account/ForgotPassword.cshtml index 375f79a..17c1bd6 100644 --- a/Src/SampleWebSite/Views/Account/ForgotPassword.cshtml +++ b/Src/SampleWebSite/Views/Account/ForgotPassword.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ForgotPasswordViewModel +@model SampleWebSite.ViewModels.ForgotPasswordViewModel @{ ViewBag.Title = "Forgot your password?"; } diff --git a/Src/SampleWebSite/Views/Account/Login.cshtml b/Src/SampleWebSite/Views/Account/Login.cshtml index 691bd41..a0e2cc7 100644 --- a/Src/SampleWebSite/Views/Account/Login.cshtml +++ b/Src/SampleWebSite/Views/Account/Login.cshtml @@ -1,4 +1,5 @@ -@model IdentitySample.Models.LoginViewModel +@using SampleWebSite.ViewModels +@model SampleWebSite.ViewModels.LoginViewModel @{ ViewBag.Title = "Log in"; @@ -51,7 +52,7 @@
- @Html.Partial("_ExternalLoginsListPartial", new IdentitySample.Models.ExternalLoginListViewModel { ReturnUrl = ViewBag.ReturnUrl }) + @Html.Partial("_ExternalLoginsListPartial", new ExternalLoginListViewModel { ReturnUrl = ViewBag.ReturnUrl })
diff --git a/Src/SampleWebSite/Views/Account/Register.cshtml b/Src/SampleWebSite/Views/Account/Register.cshtml index 67d3cb2..b57e575 100644 --- a/Src/SampleWebSite/Views/Account/Register.cshtml +++ b/Src/SampleWebSite/Views/Account/Register.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.RegisterViewModel +@model SampleWebSite.ViewModels.RegisterViewModel @{ ViewBag.Title = "Register"; } diff --git a/Src/SampleWebSite/Views/Account/ResetPassword.cshtml b/Src/SampleWebSite/Views/Account/ResetPassword.cshtml index 3d59450..f11f523 100644 --- a/Src/SampleWebSite/Views/Account/ResetPassword.cshtml +++ b/Src/SampleWebSite/Views/Account/ResetPassword.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ResetPasswordViewModel +@model SampleWebSite.ViewModels.ResetPasswordViewModel @{ ViewBag.Title = "Reset password"; } diff --git a/Src/SampleWebSite/Views/Account/SendCode.cshtml b/Src/SampleWebSite/Views/Account/SendCode.cshtml index 30bf502..be927c4 100644 --- a/Src/SampleWebSite/Views/Account/SendCode.cshtml +++ b/Src/SampleWebSite/Views/Account/SendCode.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.SendCodeViewModel +@model SampleWebSite.ViewModels.SendCodeViewModel @{ ViewBag.Title = "Send Verification Code"; } diff --git a/Src/SampleWebSite/Views/Account/VerifyCode.cshtml b/Src/SampleWebSite/Views/Account/VerifyCode.cshtml index 4171eac..00ffa01 100644 --- a/Src/SampleWebSite/Views/Account/VerifyCode.cshtml +++ b/Src/SampleWebSite/Views/Account/VerifyCode.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.VerifyCodeViewModel +@model SampleWebSite.ViewModels.VerifyCodeViewModel @{ ViewBag.Title = "Enter Verification Code"; } diff --git a/Src/SampleWebSite/Views/Account/_ExternalLoginsListPartial.cshtml b/Src/SampleWebSite/Views/Account/_ExternalLoginsListPartial.cshtml index 09f3d58..f970bd4 100644 --- a/Src/SampleWebSite/Views/Account/_ExternalLoginsListPartial.cshtml +++ b/Src/SampleWebSite/Views/Account/_ExternalLoginsListPartial.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ExternalLoginListViewModel +@model SampleWebSite.ViewModels.ExternalLoginListViewModel @using Microsoft.Owin.Security

Use another service to log in.

diff --git a/Src/SampleWebSite/Views/Manage/AddPhoneNumber.cshtml b/Src/SampleWebSite/Views/Manage/AddPhoneNumber.cshtml index 554cf34..7647599 100644 --- a/Src/SampleWebSite/Views/Manage/AddPhoneNumber.cshtml +++ b/Src/SampleWebSite/Views/Manage/AddPhoneNumber.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.AddPhoneNumberViewModel +@model SampleWebSite.ViewModels.AddPhoneNumberViewModel @{ ViewBag.Title = "Add Phone Number"; } diff --git a/Src/SampleWebSite/Views/Manage/ChangePassword.cshtml b/Src/SampleWebSite/Views/Manage/ChangePassword.cshtml index 0c0418d..2daa9ca 100644 --- a/Src/SampleWebSite/Views/Manage/ChangePassword.cshtml +++ b/Src/SampleWebSite/Views/Manage/ChangePassword.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ChangePasswordViewModel +@model SampleWebSite.ViewModels.ChangePasswordViewModel @{ ViewBag.Title = "Change Password"; } diff --git a/Src/SampleWebSite/Views/Manage/Index.cshtml b/Src/SampleWebSite/Views/Manage/Index.cshtml index 7794f9f..51c6398 100644 --- a/Src/SampleWebSite/Views/Manage/Index.cshtml +++ b/Src/SampleWebSite/Views/Manage/Index.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.IndexViewModel +@model SampleWebSite.ViewModels.IndexViewModel @{ ViewBag.Title = "Manage your account"; } diff --git a/Src/SampleWebSite/Views/Manage/ManageLogins.cshtml b/Src/SampleWebSite/Views/Manage/ManageLogins.cshtml index 5faa3c2..a0234f9 100644 --- a/Src/SampleWebSite/Views/Manage/ManageLogins.cshtml +++ b/Src/SampleWebSite/Views/Manage/ManageLogins.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ManageLoginsViewModel +@model SampleWebSite.ViewModels.ManageLoginsViewModel @using Microsoft.Owin.Security @{ ViewBag.Title = "Manage your external logins"; diff --git a/Src/SampleWebSite/Views/Manage/SetPassword.cshtml b/Src/SampleWebSite/Views/Manage/SetPassword.cshtml index 73d555f..388b835 100644 --- a/Src/SampleWebSite/Views/Manage/SetPassword.cshtml +++ b/Src/SampleWebSite/Views/Manage/SetPassword.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.SetPasswordViewModel +@model SampleWebSite.ViewModels.SetPasswordViewModel

You do not have a local username/password for this site. Add a local diff --git a/Src/SampleWebSite/Views/Manage/VerifyPhoneNumber.cshtml b/Src/SampleWebSite/Views/Manage/VerifyPhoneNumber.cshtml index 4d7b739..38037a9 100644 --- a/Src/SampleWebSite/Views/Manage/VerifyPhoneNumber.cshtml +++ b/Src/SampleWebSite/Views/Manage/VerifyPhoneNumber.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.VerifyPhoneNumberViewModel +@model SampleWebSite.ViewModels.VerifyPhoneNumberViewModel @{ ViewBag.Title = "Verify Phone Number"; } diff --git a/Src/SampleWebSite/Views/RolesAdmin/Create.cshtml b/Src/SampleWebSite/Views/RolesAdmin/Create.cshtml index 79ac47a..1228976 100644 --- a/Src/SampleWebSite/Views/RolesAdmin/Create.cshtml +++ b/Src/SampleWebSite/Views/RolesAdmin/Create.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.RoleViewModel +@model SampleWebSite.ViewModels.RoleViewModel @{ ViewBag.Title = "Create"; diff --git a/Src/SampleWebSite/Views/RolesAdmin/Edit.cshtml b/Src/SampleWebSite/Views/RolesAdmin/Edit.cshtml index ff4148f..d8146a2 100644 --- a/Src/SampleWebSite/Views/RolesAdmin/Edit.cshtml +++ b/Src/SampleWebSite/Views/RolesAdmin/Edit.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.RoleViewModel +@model SampleWebSite.ViewModels.RoleViewModel @{ ViewBag.Title = "Edit"; diff --git a/Src/SampleWebSite/Views/UsersAdmin/Create.cshtml b/Src/SampleWebSite/Views/UsersAdmin/Create.cshtml index 415f310..e40c222 100644 --- a/Src/SampleWebSite/Views/UsersAdmin/Create.cshtml +++ b/Src/SampleWebSite/Views/UsersAdmin/Create.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.RegisterViewModel +@model SampleWebSite.ViewModels.RegisterViewModel @{ ViewBag.Title = "Create"; } diff --git a/Src/SampleWebSite/Views/UsersAdmin/Delete.cshtml b/Src/SampleWebSite/Views/UsersAdmin/Delete.cshtml index bbe4ca7..820a0b3 100644 --- a/Src/SampleWebSite/Views/UsersAdmin/Delete.cshtml +++ b/Src/SampleWebSite/Views/UsersAdmin/Delete.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ApplicationUser +@model SampleWebSite.Models.ApplicationUser @{ ViewBag.Title = "Delete"; diff --git a/Src/SampleWebSite/Views/UsersAdmin/Details.cshtml b/Src/SampleWebSite/Views/UsersAdmin/Details.cshtml index 34961ea..96d657e 100644 --- a/Src/SampleWebSite/Views/UsersAdmin/Details.cshtml +++ b/Src/SampleWebSite/Views/UsersAdmin/Details.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.ApplicationUser +@model SampleWebSite.Models.ApplicationUser @{ ViewBag.Title = "Details"; diff --git a/Src/SampleWebSite/Views/UsersAdmin/Edit.cshtml b/Src/SampleWebSite/Views/UsersAdmin/Edit.cshtml index 7f0dc5c..f513ff8 100644 --- a/Src/SampleWebSite/Views/UsersAdmin/Edit.cshtml +++ b/Src/SampleWebSite/Views/UsersAdmin/Edit.cshtml @@ -1,4 +1,4 @@ -@model IdentitySample.Models.EditUserViewModel +@model SampleWebSite.ViewModels.EditUserViewModel @{ ViewBag.Title = "Edit"; diff --git a/Src/SampleWebSite/Views/UsersAdmin/Index.cshtml b/Src/SampleWebSite/Views/UsersAdmin/Index.cshtml index 2155cb0..1ec84b3 100644 --- a/Src/SampleWebSite/Views/UsersAdmin/Index.cshtml +++ b/Src/SampleWebSite/Views/UsersAdmin/Index.cshtml @@ -1,4 +1,4 @@ -@model IEnumerable +@model IEnumerable @{ ViewBag.Title = "Index"; diff --git a/Src/SampleWebSite/Web.config b/Src/SampleWebSite/Web.config index 46675c0..a0a14a8 100644 --- a/Src/SampleWebSite/Web.config +++ b/Src/SampleWebSite/Web.config @@ -4,9 +4,9 @@ http://go.microsoft.com/fwlink/?LinkId=169433 を参照してください --> - + - +