-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
77 lines (68 loc) · 2.5 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
75
76
77
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
using System;
using System.Threading.Tasks;
[assembly: OwinStartup(typeof(WebEnterprise.Startup))]
namespace WebEnterprise
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Authen/Login")
});
CreateUserRoles();
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
}
private void CreateUserRoles()
{
var userStore = new UserStore<IdentityUser>();
var manager = new UserManager<IdentityUser>(userStore);
var roleStore = new RoleStore<IdentityRole>();
var roleManager = new RoleManager<IdentityRole>(roleStore);
if (!roleManager.RoleExists("ManagerMarketing"))
{
var role = new IdentityRole("ManagerMarketing");
roleManager.Create(role);
var user = new IdentityUser("managermarketing");
var result = manager.Create(user, "123456");
if (result.Succeeded)
{
manager.AddToRole(user.Id, "ManagerMarketing");
}
}
if (!roleManager.RoleExists("Admin"))
{
var role = new IdentityRole("Admin");
roleManager.Create(role);
var user = new IdentityUser("admin");
var result = manager.Create(user, "123456");
if (result.Succeeded)
{
manager.AddToRole(user.Id, "Admin");
}
}
if (!roleManager.RoleExists("MarketingCoordinator"))
{
var role = new IdentityRole("MarketingCoordinator");
roleManager.Create(role);
}
if (!roleManager.RoleExists("Student"))
{
var role = new IdentityRole("Student");
roleManager.Create(role);
}
if (!roleManager.RoleExists("Guest"))
{
var role = new IdentityRole("Guest");
roleManager.Create(role);
}
}
}
}