-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
63 lines (54 loc) · 1.99 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
using OnlineShopDAW.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(OnlineShopDAW.Startup))]
namespace OnlineShopDAW
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
CreateApplicationRoles();
}
private void CreateApplicationRoles()
{
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
// Se adauga rolurile aplicatiei
if (!roleManager.RoleExists("administrator"))
{
// Se adauga rolul de administrator
var role = new IdentityRole();
role.Name = "administrator";
roleManager.Create(role);
// se adauga utilizatorul administrator
var user = new ApplicationUser();
user.UserName = "admin@gmail.com";
user.Email = "admin@gmail.com";
user.FirstName = "admin";
user.LastName = "admin";
var adminCreated = UserManager.Create(user, "admin123");
if (adminCreated.Succeeded)
{
UserManager.AddToRole(user.Id, "administrator");
}
}
if (!roleManager.RoleExists("collaborator"))
{
var role = new IdentityRole();
role.Name = "collaborator";
roleManager.Create(role);
}
if (!roleManager.RoleExists("registered"))
{
var role = new IdentityRole();
role.Name = "registered";
roleManager.Create(role);
}
}
}
}