Skip to content

Commit 5fed5b1

Browse files
committed
Roles added and ng build fix
1 parent 94ddf22 commit 5fed5b1

File tree

13 files changed

+309
-48
lines changed

13 files changed

+309
-48
lines changed

eFormAPI/eFormAPI/Controllers/SettingsController.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
using System;
22
using System.Configuration;
3-
using System.Data;
43
using System.Data.Entity.Infrastructure;
54
using System.Data.Entity.Migrations;
6-
using System.Data.SqlClient;
75
using System.IO;
86
using System.Web.Configuration;
97
using System.Web.Http;
10-
using eFormAPI.Web.Migrations;
118
using eFormCore;
129
using eFromAPI.Common.API;
1310
using eFromAPI.Common.Models.Settings;

eFormAPI/eFormAPI/Infrastructure/Data/Entities/EformUser.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.ComponentModel.DataAnnotations;
3-
using System.Security.Claims;
1+
using System.Security.Claims;
42
using System.Threading.Tasks;
53
using Microsoft.AspNet.Identity;
64
using Microsoft.AspNet.Identity.EntityFramework;
@@ -10,20 +8,6 @@ namespace eFormAPI.Web.Infrastructure.Data.Entities
108
public class EformUser : IdentityUser<int, EformUserLogin, EformUserRole,
119
EformUserClaim>
1210
{
13-
[Required]
14-
[MaxLength(100)]
15-
public string FirstName { get; set; }
16-
17-
[Required]
18-
[MaxLength(100)]
19-
public string LastName { get; set; }
20-
21-
[Required]
22-
public byte Level { get; set; }
23-
24-
[Required]
25-
public DateTime JoinDate { get; set; }
26-
2711
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(
2812
UserManager<EformUser, int> manager, string authenticationType)
2913
{

eFormAPI/eFormAPI/Infrastructure/Identity/EformRoleManager.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
using eFormAPI.Web.Infrastructure.Data;
2+
using eFormAPI.Web.Infrastructure.Data.Entities;
23
using Microsoft.AspNet.Identity;
34
using Microsoft.AspNet.Identity.EntityFramework;
45
using Microsoft.AspNet.Identity.Owin;
56
using Microsoft.Owin;
67

78
namespace eFormAPI.Web.Infrastructure.Identity
89
{
9-
public class EformRoleManager : RoleManager<IdentityRole>
10+
public class EformRoleManager : RoleManager<EformRole, int>
1011
{
11-
public EformRoleManager(IRoleStore<IdentityRole, string> roleStore)
12+
public EformRoleManager(IRoleStore<EformRole, int> roleStore)
1213
: base(roleStore) {}
1314

1415
public static EformRoleManager Create(IdentityFactoryOptions<EformRoleManager> options, IOwinContext context)
1516
{
16-
var appRoleManager = new EformRoleManager(new RoleStore<IdentityRole>(context.Get<BaseDbContext>()));
17+
var appRoleManager = new EformRoleManager(new EformRoleStore(context.Get<BaseDbContext>()));
1718

1819
return appRoleManager;
1920
}

eFormAPI/eFormAPI/Migrations/201707190837078_InitialCreate.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
namespace eFormAPI.Web.Migrations
2+
{
3+
using System;
4+
using System.Data.Entity.Migrations;
5+
6+
public partial class InitialCreate : DbMigration
7+
{
8+
public override void Up()
9+
{
10+
CreateTable(
11+
"dbo.Roles",
12+
c => new
13+
{
14+
Id = c.Int(nullable: false, identity: true),
15+
Name = c.String(nullable: false, maxLength: 256),
16+
})
17+
.PrimaryKey(t => t.Id)
18+
.Index(t => t.Name, unique: true, name: "RoleNameIndex");
19+
20+
CreateTable(
21+
"dbo.UserRoles",
22+
c => new
23+
{
24+
UserId = c.Int(nullable: false),
25+
RoleId = c.Int(nullable: false),
26+
})
27+
.PrimaryKey(t => new { t.UserId, t.RoleId })
28+
.ForeignKey("dbo.Roles", t => t.RoleId, cascadeDelete: true)
29+
.ForeignKey("dbo.Users", t => t.UserId, cascadeDelete: true)
30+
.Index(t => t.UserId)
31+
.Index(t => t.RoleId);
32+
33+
CreateTable(
34+
"dbo.Users",
35+
c => new
36+
{
37+
Id = c.Int(nullable: false, identity: true),
38+
Email = c.String(maxLength: 256),
39+
EmailConfirmed = c.Boolean(nullable: false),
40+
PasswordHash = c.String(),
41+
SecurityStamp = c.String(),
42+
PhoneNumber = c.String(),
43+
PhoneNumberConfirmed = c.Boolean(nullable: false),
44+
TwoFactorEnabled = c.Boolean(nullable: false),
45+
LockoutEndDateUtc = c.DateTime(),
46+
LockoutEnabled = c.Boolean(nullable: false),
47+
AccessFailedCount = c.Int(nullable: false),
48+
UserName = c.String(nullable: false, maxLength: 256),
49+
})
50+
.PrimaryKey(t => t.Id)
51+
.Index(t => t.UserName, unique: true, name: "UserNameIndex");
52+
53+
CreateTable(
54+
"dbo.UserClaims",
55+
c => new
56+
{
57+
Id = c.Int(nullable: false, identity: true),
58+
UserId = c.Int(nullable: false),
59+
ClaimType = c.String(),
60+
ClaimValue = c.String(),
61+
})
62+
.PrimaryKey(t => t.Id)
63+
.ForeignKey("dbo.Users", t => t.UserId, cascadeDelete: true)
64+
.Index(t => t.UserId);
65+
66+
CreateTable(
67+
"dbo.UserLogins",
68+
c => new
69+
{
70+
LoginProvider = c.String(nullable: false, maxLength: 128),
71+
ProviderKey = c.String(nullable: false, maxLength: 128),
72+
UserId = c.Int(nullable: false),
73+
})
74+
.PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
75+
.ForeignKey("dbo.Users", t => t.UserId, cascadeDelete: true)
76+
.Index(t => t.UserId);
77+
78+
}
79+
80+
public override void Down()
81+
{
82+
DropForeignKey("dbo.UserRoles", "UserId", "dbo.Users");
83+
DropForeignKey("dbo.UserLogins", "UserId", "dbo.Users");
84+
DropForeignKey("dbo.UserClaims", "UserId", "dbo.Users");
85+
DropForeignKey("dbo.UserRoles", "RoleId", "dbo.Roles");
86+
DropIndex("dbo.UserLogins", new[] { "UserId" });
87+
DropIndex("dbo.UserClaims", new[] { "UserId" });
88+
DropIndex("dbo.Users", "UserNameIndex");
89+
DropIndex("dbo.UserRoles", new[] { "RoleId" });
90+
DropIndex("dbo.UserRoles", new[] { "UserId" });
91+
DropIndex("dbo.Roles", "RoleNameIndex");
92+
DropTable("dbo.UserLogins");
93+
DropTable("dbo.UserClaims");
94+
DropTable("dbo.Users");
95+
DropTable("dbo.UserRoles");
96+
DropTable("dbo.Roles");
97+
}
98+
}
99+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<data name="Target" xml:space="preserve">
121+
<value>H4sIAAAAAAAEAO1c3W7jNha+X2DfQdDV7iKNkgxatIHdIuMkW6OTH4wz7d4NaIl2iEqkK1KZBEWfrBd9pL5CSYmSKYqUKFuxPYtigEEskt85PPzIQ1Kf/efvf4y+e05i7wmmFBE89k+PT3wP4pBECC/HfsYWX3ztf/ftP/8xuoqSZ+/Hst4bUY+3xHTsPzK2Og8CGj7CBNDjBIUpoWTBjkOSBCAiwdnJyTfB6WkAOYTPsTxv9D7DDCUw/8A/TggO4YplIL4hEYypfM5LZjmqdwsSSFcghGMfXpM0ubifHv8E58dTvEgBZWkWsiyFx5eAAd+7iBHgfs1gvPA9gDFhgHGvzz9QOGMpwcvZij8A8cPLCvJ6CxBTKHtzvq7u2rGTM9GxYN2whAozykjSE/D0jYx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YbWd6sJ3dTz9oDbVLO7AQM+M2msMVnl+tTtla+DYe+Iwq+oht2/AHYtlNiX7nWnEhxng5+ZwvUwFF5S37I3KetOqWS7RT1Y5aCrZvUwuCSlTXsTp+6US7br04PlkqMK9TCotL/8tnMiOee3vStLmzIdy+uMxi1qq3q0uGzmZ+Y54UNe7OnMAqlWYWm3rtRkyK7Gshprl57ajPQwIBNvpyjVZsqiN2wXrTpoVm32LKK+HWpamyo7k5K4bamxyn4OV8Bqdtqt0zWKmd4UH65YdZtu15huept5qMLUbTo9GMF7qFCbrx55NlJ+Ko2nQ4qWawjxw2kYhrU8VNWZ4gUp06HmUVlFu2a4gQxEPEldpAwtQMh4sbgNzb+9m988iTv5OYym+C5jq4zxLsNkHtdubURabbOfS23rPo/uVvmPLQzRBe4mErfId/hthuKo8vvacNthgRD5Wl4/irFk4hpy+VIh3RLsCCTDV20zHmCyijkYvcMz8AQ38Y3T7x1cgvBlfY1lA+keiHrYR5cILFOQUImxbs8/cg5HyfO3fwGhx2xoMVAAAA==</value>
122+
</data>
123+
<data name="DefaultSchema" xml:space="preserve">
124+
<value>dbo</value>
125+
</data>
126+
</root>
Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using System.Linq;
12
using eFormAPI.Web.Infrastructure.Data;
23
using eFormAPI.Web.Infrastructure.Data.Entities;
34
using eFormAPI.Web.Infrastructure.Identity;
45
using Microsoft.AspNet.Identity;
6+
using Microsoft.AspNet.Identity.EntityFramework;
57

68
namespace eFormAPI.Web.Migrations
79
{
@@ -15,23 +17,42 @@ public Configuration()
1517
AutomaticMigrationsEnabled = false;
1618
}
1719

18-
protected override void Seed(eFormAPI.Web.Infrastructure.Data.BaseDbContext context)
20+
protected override void Seed(BaseDbContext context)
1921
{
22+
// Seed roles
23+
var roleManager = new EformRoleManager(new EformRoleStore(new BaseDbContext()));
24+
if (!roleManager.RoleExists("admin"))
25+
{
26+
roleManager.Create(new EformRole("admin"));
27+
}
28+
if (!roleManager.RoleExists("user"))
29+
{
30+
roleManager.Create(new EformRole("user"));
31+
}
32+
// Seed admin and demo users
2033
var manager = new EformUserManager(new EformUserStore(new BaseDbContext()));
21-
22-
var user = new EformUser()
34+
var adminUser = new EformUser()
2335
{
2436
UserName = "admin",
2537
Email = "[email protected]",
2638
EmailConfirmed = true,
27-
FirstName = "Taiseer",
28-
LastName = "Joudeh",
29-
Level = 1,
30-
JoinDate = DateTime.Now.AddYears(-3)
3139
};
32-
33-
manager.Create(user, "MySuperP@ssword!");
34-
//manager.AddToRole(user.Id, "admin");
40+
var testUser = new EformUser()
41+
{
42+
UserName = "test",
43+
Email = "[email protected]",
44+
EmailConfirmed = true,
45+
};
46+
if (!manager.Users.Any(x => x.Email.Equals(adminUser.Email)))
47+
{
48+
manager.Create(adminUser, "AdminP@ssword!");
49+
manager.AddToRole(adminUser.Id, "admin");
50+
}
51+
if (!manager.Users.Any(x => x.Email.Equals(testUser.Email)))
52+
{
53+
manager.Create(testUser, "TestP@ssword!");
54+
manager.AddToRole(testUser.Id, "user");
55+
}
3556
}
3657
}
3758
}

0 commit comments

Comments
 (0)