Skip to content

Commit

Permalink
chore: added user data and read from csv
Browse files Browse the repository at this point in the history
  • Loading branch information
A-5ingh committed Oct 9, 2022
1 parent 29be607 commit 7c7cd5a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 47 deletions.
1 change: 1 addition & 0 deletions generators/common/templates/dotnetcore/Dockerfile-Back.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ WORKDIR /app
COPY docker-entrypoint-back.sh .
RUN chmod +x /app/docker-entrypoint-back.sh
COPY --from=build /app/out .
COPY src/<%= mainProjectDir %>/Configuration/users-data.csv ./Configuration/users-data.csv
ENV ASPNETCORE_ENVIRONMENT=Production
<%_ if(!skipClient && clientFramework === "Blazor") { _%>
ARG INCLUDE_BLAZOR
Expand Down
18 changes: 18 additions & 0 deletions generators/server/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,15 @@ const serverFiles = {
},
],
},
{
path: SERVER_SRC_DIR,
templates: [
{
file: 'Project/Configuration/users-data.csv',
renameTo: generator => `${generator.mainProjectDir}/Configuration/users-data.csv`,
},
],
},
{
path: SERVER_SRC_DIR,
templates: [
Expand Down Expand Up @@ -1378,6 +1387,15 @@ const serverFiles = {
},
],
},
{
path: SERVER_TEST_DIR,
templates: [
{
file: 'Project.Test/Configuration/users-data.csv',
renameTo: generator => `${generator.testProjectDir}/bin/Debug/net6.0/Configuration/users-data.csv`,
},
],
},
],
serverMisc: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@
<PackageVersion Include="FluentAssertions" Version="5.10.3" />
<PackageVersion Include="FluentAssertions.AspNetCore.Mvc" Version="3.2.0" />
<PackageVersion Include="FluentAssertions.Json" Version="5.5.0" />
<PackageVersion Include="CsvHelper" Version="28.0.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,35 @@
-%>
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using <%= namespace %>.Domain.Entities;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using CsvHelper;
using CsvHelper.Configuration;
using System.Text;
using System.IO;

namespace <%= namespace %>.Configuration;

public sealed class UserMap : ClassMap<User>
{
public UserMap()
{
Map(m => m.Id).Name("Id");
Map(m => m.UserName).Name("UserName");
Map(m => m.PasswordHash).Name("PasswordHash");
Map(m => m.FirstName).Name("FirstName");
Map(m => m.LastName).Name("LastName");
Map(m => m.Email).Name("Email");
Map(m => m.Activated).Name("Activated");
Map(m => m.LangKey).Name("LangKey");
}
}

public static class IdentityConfiguration
{
public static IApplicationBuilder UseApplicationIdentity(this IApplicationBuilder builder)
Expand Down Expand Up @@ -52,53 +72,10 @@ public static class IdentityConfiguration

private static IEnumerable<User> Users()
{
return new List<User>
{
new User
{
Id = "user-0",
UserName = "system",
PasswordHash = "$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG",
FirstName = "",
LastName = "System",
Email = "system@localhost",
Activated = true,
LangKey = "en"
},
new User
{
Id = "user-1",
UserName = "anonymoususer",
PasswordHash = "$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO",
FirstName = "Anonymous",
LastName = "User",
Email = "anonymous@localhost",
Activated = true,
LangKey = "en"
},
new User
{
Id = "user-2",
UserName = "admin",
PasswordHash = "$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC",
FirstName = "admin",
LastName = "Administrator",
Email = "admin@localhost",
Activated = true,
LangKey = "en"
},
new User
{
Id = "user-3",
UserName = "user",
PasswordHash = "$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K",
FirstName = "",
LastName = "User",
Email = "user@localhost",
Activated = true,
LangKey = "en"
}
};
var reader = new StreamReader("./Configuration/users-data.csv", Encoding.Default);
var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
csv.Context.RegisterClassMap<UserMap>();
return csv.GetRecords<User>();
}

private static IDictionary<string, string[]> UserRoles()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Id,UserName,PasswordHash,FirstName,LastName,Email,Activated,LangKey
user-0,system,$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG,,System,system@localhost,TRUE,en
user-1,anonymoususer,$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO,Anonymous,User,anonymous@localhost,TRUE,en
user-2,admin,$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC,admin,Administrator,admin@localhost,TRUE,en
user-3,user,$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K,,User,user@localhost,TRUE,en
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<%_ if(!skipClient && clientFramework === "Blazor") { _%>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
<%_ } _%>
<PackageReference Include="CsvHelper" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Id,UserName,PasswordHash,FirstName,LastName,Email,Activated,LangKey
user-0,system,$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG,,System,system@localhost,TRUE,en
user-1,anonymoususer,$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO,Anonymous,User,anonymous@localhost,TRUE,en
user-2,admin,$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC,admin,Administrator,admin@localhost,TRUE,en
user-3,user,$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K,,User,user@localhost,TRUE,en

0 comments on commit 7c7cd5a

Please sign in to comment.