diff --git a/src/MusicStore/Config.json b/src/MusicStore/Config.json new file mode 100644 index 0000000000..5959953d17 --- /dev/null +++ b/src/MusicStore/Config.json @@ -0,0 +1,4 @@ +{ + "DefaultAdminUsername": "Administrator", + "DefaultAdminPassword": "YouShouldChangeThisPassword" +} \ No newline at end of file diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 1b83851077..57ac262197 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -1,6 +1,7 @@ using Microsoft.AspNet; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.ConfigurationModel; +using Microsoft.AspNet.Configuration.Json; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection.Fallback; using Microsoft.AspNet.DependencyInjection.NestedProviders; @@ -47,39 +48,14 @@ public class Startup SampleData.InitializeMusicStoreDatabase(); } - //Bug: We need EF to integrate with SQL server. Until then we will use in memory store - //private async void CreateAdminUser() - //{ - // string _username = ConfigurationManager.AppSettings["DefaultAdminUsername"]; - // string _password = ConfigurationManager.AppSettings["DefaultAdminPassword"]; - // string _role = "Administrator"; - - // var context = new ApplicationDbContext(); - // var userManager = new UserManager(new UserStore(context)); - // var roleManager = new RoleManager(new RoleStore(context)); - - // var role = new IdentityRole(_role); - // var result = await roleManager.RoleExistsAsync(_role); - // if (result == false) - // { - // await roleManager.CreateAsync(role); - // } - - // var user = await userManager.FindByNameAsync(_username); - // if (user == null) - // { - // user = new ApplicationUser { UserName = _username }; - // await userManager.CreateAsync(user, _password); - // await userManager.AddToRoleAsync(user.Id, _role); - // } - //} - private async void CreateAdminUser() { - //How to read from local appSettings? var configuration = new Configuration(); - string _username = "Administrator"; // configuration.Get("DefaultAdminUsername"); - string _password = "YouShouldChangeThisPassword"; // configuration.Get("DefaultAdminPassword"); + configuration.AddEnvironmentVariables(); //If configuration flows through environment we should pick that first + configuration.AddJsonFile("Config.json"); + + string _username = configuration.Get("DefaultAdminUsername"); + string _password = configuration.Get("DefaultAdminPassword"); string _role = "Administrator"; var userManager = new UserManager(new InMemoryUserStore()); diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index c43908837d..754b2a437a 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -25,7 +25,8 @@ "Microsoft.Data.InMemory": "0.1-alpha-*", "Microsoft.AspNet.Diagnostics": "0.1-alpha-*", "Microsoft.AspNet.Hosting": "0.1-alpha-*", - "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*" + "Microsoft.AspNet.Server.WebListener": "0.1-alpha-*", + "Microsoft.AspNet.Configuration.Json": "0.1-alpha-*" }, "commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001"