-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
74 lines (73 loc) · 2.54 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Microsoft.Owin;
using Owin;
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security.Cookies;
using Project.Identity;
[assembly: OwinStartup(typeof(Project.Startup))]
namespace Project
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationCookie,
LoginPath=new PathString("/Account/Login")
});
CreateRolesAndUsers();
}
public void CreateRolesAndUsers()
{
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new AppDBContext()));
var appDbContext = new AppDBContext();
var appUserStore = new AppUserStore(appDbContext);
var userManager = new AppUserManager(appUserStore);
if (!roleManager.RoleExists("Admin"))
{
var role = new IdentityRole();
role.Name = "Admin";
roleManager.Create(role);
}
if (userManager.FindByName("admin") == null)
{
var user = new AppUser();
user.UserName = "admin";
user.Email = "[email protected]";
string userPwd = "admin0209";
var ckuser = userManager.Create(user, userPwd);
if (ckuser.Succeeded)
{
userManager.AddToRole(user.Id, "Admin");
}
}
if (!roleManager.RoleExists("Manager"))
{
var role = new IdentityRole();
role.Name = "Manager";
roleManager.Create(role);
}
if (userManager.FindByName("manager") == null)
{
var user = new AppUser();
user.UserName = "managern";
user.Email = "[email protected]";
string userPwd = "manager123";
var ckuser = userManager.Create(user, userPwd);
if (ckuser.Succeeded)
{
userManager.AddToRole(user.Id, "Manager");
}
}
if (!roleManager.RoleExists("Customer"))
{
var role = new IdentityRole();
role.Name = "Customer";
roleManager.Create(role);
}
}
}
}