Extended identity api so that the AspNetUsers table also contains a column called TenantId, so that this can be used to check what tenant a user belongs to.
This commit is contained in:
parent
71e52e9f89
commit
0365b52e66
@ -74,7 +74,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
|
||||
"cardholdername", "cardnumber", "cardtype", "city", "country",
|
||||
"email", "expiration", "lastname", "name", "phonenumber",
|
||||
"username", "zipcode", "state", "street", "securitynumber",
|
||||
"normalizedemail", "normalizedusername", "password"
|
||||
"normalizedemail", "normalizedusername", "password", "tenantid"
|
||||
};
|
||||
csvheaders = GetHeaders(requiredHeaders, csvFileUsers);
|
||||
}
|
||||
@ -104,10 +104,16 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
|
||||
}
|
||||
|
||||
string cardtypeString = column[Array.IndexOf(headers, "cardtype")].Trim('"').Trim();
|
||||
string tenantIdString = column[Array.IndexOf(headers, "tenantid")].Trim('"').Trim();
|
||||
if (!int.TryParse(cardtypeString, out int cardtype))
|
||||
{
|
||||
throw new Exception($"cardtype='{cardtypeString}' is not a number");
|
||||
}
|
||||
|
||||
if (!int.TryParse(tenantIdString, out int tenantId))
|
||||
{
|
||||
throw new Exception($"tenantid='{tenantIdString}' is not a number");
|
||||
}
|
||||
|
||||
var user = new ApplicationUser
|
||||
{
|
||||
@ -131,6 +137,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
|
||||
NormalizedUserName = column[Array.IndexOf(headers, "normalizedusername")].Trim('"').Trim(),
|
||||
SecurityStamp = Guid.NewGuid().ToString("D"),
|
||||
PasswordHash = column[Array.IndexOf(headers, "password")].Trim('"').Trim(), // Note: This is the password
|
||||
TenantId = tenantId
|
||||
};
|
||||
|
||||
user.PasswordHash = _passwordHasher.HashPassword(user, user.PasswordHash);
|
||||
@ -162,13 +169,41 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data
|
||||
NormalizedEmail = "DEMOUSER@MICROSOFT.COM",
|
||||
NormalizedUserName = "DEMOUSER@MICROSOFT.COM",
|
||||
SecurityStamp = Guid.NewGuid().ToString("D"),
|
||||
TenantId = 2
|
||||
};
|
||||
|
||||
var user2 =
|
||||
new ApplicationUser()
|
||||
{
|
||||
CardHolderName = "Espen",
|
||||
CardNumber = "4012888888881882",
|
||||
CardType = 1,
|
||||
City = "Oslo",
|
||||
Country = "Norway",
|
||||
Email = "espent1004@gmail.com",
|
||||
Expiration = "12/22",
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
LastName = "Nordli",
|
||||
Name = "Espen",
|
||||
PhoneNumber = "95791135",
|
||||
UserName = "espent1004@gmail.com",
|
||||
ZipCode = "0681",
|
||||
State = "Oslo",
|
||||
Street = "Treskeveien 28A",
|
||||
SecurityNumber = "535",
|
||||
NormalizedEmail = "ESPENT1004@GMAIL.COM",
|
||||
NormalizedUserName = "ESPENT1004@GMAIL.COM",
|
||||
SecurityStamp = Guid.NewGuid().ToString("D"),
|
||||
TenantId = 1
|
||||
};
|
||||
|
||||
user.PasswordHash = _passwordHasher.HashPassword(user, "Pass@word1");
|
||||
user2.PasswordHash = _passwordHasher.HashPassword(user2, "passord");
|
||||
|
||||
return new List<ApplicationUser>()
|
||||
{
|
||||
user
|
||||
user,
|
||||
user2
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,9 @@ namespace Identity.API.Migrations
|
||||
b.Property<string>("CardHolderName")
|
||||
.IsRequired();
|
||||
|
||||
b.Property<int>("TenantId")
|
||||
.IsRequired();
|
||||
|
||||
b.Property<string>("CardNumber")
|
||||
.IsRequired();
|
||||
|
||||
|
@ -53,7 +53,8 @@ namespace Identity.API.Migrations
|
||||
Street = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
ZipCode = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
ZipCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
TenantId = table.Column<int>(type: "int", nullable: false),
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
|
@ -24,6 +24,9 @@ namespace Identity.API.Migrations
|
||||
|
||||
b.Property<int>("AccessFailedCount");
|
||||
|
||||
b.Property<int>("TenantId")
|
||||
.IsRequired();
|
||||
|
||||
b.Property<string>("CardHolderName")
|
||||
.IsRequired();
|
||||
|
||||
|
@ -30,5 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Models
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
public string LastName { get; set; }
|
||||
[Required]
|
||||
public int TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
CardHolderName,CardNumber,CardType,City,Country,Email,Expiration,LastName,Name,PhoneNumber,UserName,ZipCode,State,Street,SecurityNumber,NormalizedEmail,NormalizedUserName,Password
|
||||
DemoUser,4012888888881881,1,Redmond,U.S.,demouser@microsoft.com,12/20,DemoLastName,DemoUser,1234567890,demouser@microsoft.com,98052,WA,15703 NE 61st Ct,535,DEMOUSER@MICROSOFT.COM,DEMOUSER@MICROSOFT.COM,Pass@word1
|
||||
CardHolderName,CardNumber,CardType,City,Country,Email,Expiration,LastName,Name,PhoneNumber,UserName,ZipCode,State,Street,SecurityNumber,NormalizedEmail,NormalizedUserName,Password,TenantId
|
||||
DemoUser,4012888888881881,1,Redmond,U.S.,demouser@microsoft.com,12/20,DemoLastName,DemoUser,1234567890,demouser@microsoft.com,98052,WA,15703 NE 61st Ct,535,DEMOUSER@MICROSOFT.COM,DEMOUSER@MICROSOFT.COM,Pass@word1,1
|
||||
Espen Nordli,4012888888881882,1,Oslo,Norway,espent1004@gmail.com,12/20,Nordli,Espen,95791135,espent1004@gmail.com,0681,Oslo,Treskeveien 28A,535,ESPENT1004@GMAIL.COM,ESPENT1004@GMAIL.COM,Pass@word1,2
|
|
Loading…
x
Reference in New Issue
Block a user