Exercise Files
This commit is contained in:
47
Ch03/03_Challenge/Website/Models/Identity/IdentityModels.cs
Normal file
47
Ch03/03_Challenge/Website/Models/Identity/IdentityModels.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System.Data.Entity;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
|
||||
namespace HPlusSports.Models
|
||||
{
|
||||
public static class UserRoles
|
||||
{
|
||||
public const string Admin = "Admin";
|
||||
public const string ProductAdmin = "ProductAdmin";
|
||||
}
|
||||
|
||||
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
|
||||
public class ApplicationUser : IdentityUser
|
||||
{
|
||||
public ApplicationUser() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public ApplicationUser(string username) : base(username)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
|
||||
{
|
||||
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
|
||||
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
|
||||
// Add custom user claims here
|
||||
return userIdentity;
|
||||
}
|
||||
}
|
||||
|
||||
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||
{
|
||||
public ApplicationDbContext()
|
||||
: base("HPlusSports_Identity", throwIfV1Schema: false)
|
||||
{
|
||||
}
|
||||
|
||||
public static ApplicationDbContext Create()
|
||||
{
|
||||
return new ApplicationDbContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user