diff --git a/docker-compose.yml b/docker-compose.yml index c87e6e896..094f16c94 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,10 +39,10 @@ services: image: eshop/identity environment: - SpaClient=http://localhost:5104 - - ConnectionString=Server=identity.data;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word + - ConnectionStrings__DefaultConnection=Server=identity.data;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word #- MvcClient=http://104.40.62.65:5100 #Remote: VM Needs to have public access at 5105. - MvcClient=http://localhost:5100 #Local: You need a entry in windows host file to run identity in local docker. - #10.0.75.1:5105 + #10.0.75.1:5105 CCE/TODO: try to avoid host entry. ports: - "5105:5105" depends_on: diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj b/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj index bb833177e..545e3dbfb 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj @@ -16,7 +16,7 @@ Resources\Resource.Designer.cs Off True - v7.0 + v6.0 Properties\AndroidManifest.xml diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj.bak b/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj.bak index 545e3dbfb..bb833177e 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj.bak +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/eShopOnContainers.TestRunner.Droid.csproj.bak @@ -16,7 +16,7 @@ Resources\Resource.Designer.cs Off True - v6.0 + v7.0 Properties\AndroidManifest.xml diff --git a/src/Services/Identity/eShopOnContainers.Identity/Controllers/AccountController.cs b/src/Services/Identity/eShopOnContainers.Identity/Controllers/AccountController.cs index 5c71cbf64..73d7b8c83 100644 --- a/src/Services/Identity/eShopOnContainers.Identity/Controllers/AccountController.cs +++ b/src/Services/Identity/eShopOnContainers.Identity/Controllers/AccountController.cs @@ -104,7 +104,6 @@ namespace IdentityServer4.Quickstart.UI.Controllers }; await _loginService.SignIn(user); - // make sure the returnUrl is still valid, and if yes - redirect back to authorize endpoint if (_interaction.IsValidReturnUrl(model.ReturnUrl)) { diff --git a/src/Services/Identity/eShopOnContainers.Identity/Data/ApplicationContextSeed.cs b/src/Services/Identity/eShopOnContainers.Identity/Data/ApplicationContextSeed.cs new file mode 100644 index 000000000..86bdb82c0 --- /dev/null +++ b/src/Services/Identity/eShopOnContainers.Identity/Data/ApplicationContextSeed.cs @@ -0,0 +1,86 @@ +namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure +{ + using AspNetCore.Identity; + using EntityFrameworkCore; + using Extensions.Logging; + using global::eShopOnContainers.Identity.Data; + using global::eShopOnContainers.Identity.Models; + using Microsoft.AspNetCore.Builder; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Security.Cryptography; + using System.Threading.Tasks; + + public class ApplicationContextSeed + { + private readonly IPasswordHasher _passwordHasher; + + public ApplicationContextSeed(IPasswordHasher passwordHasher) + { + _passwordHasher = passwordHasher; + } + + public async Task SeedAsync(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory, int? retry = 0) + { + int retryForAvaiability = retry.Value; + try + { + var context = (ApplicationDbContext)applicationBuilder + .ApplicationServices.GetService(typeof(ApplicationDbContext)); + + context.Database.Migrate(); + + if (!context.Users.Any()) + { + context.Users.AddRange( + GetDefaultUser()); + + await context.SaveChangesAsync(); + } + } + catch (Exception ex) + { + if (retryForAvaiability < 10) + { + retryForAvaiability++; + var log = loggerFactory.CreateLogger("catalog seed"); + log.LogError(ex.Message); + await SeedAsync(applicationBuilder, loggerFactory, retryForAvaiability); + } + } + } + + private ApplicationUser GetDefaultUser() + { + var user = + new ApplicationUser() + { + CardHolderName = "Jhon Doe", + CardNumber = "1111-2222-33-4444", + CardType = 1, + City = "Seattle", + Country = "EEUU", + CountryCode = "91", + Email = "jdoe@eshop.com", + Expiration = "12/20", + Id = Guid.NewGuid().ToString(), + LastName = "Doe", + Name = "Jhon", + PhoneNumber = "600 11 22 33", + UserName = "jdoe@eshop.com", + ZipCode = "56730", + State = "Washington", + Street = "Street..", + SecurityNumber = "256", + NormalizedEmail = "JDOE@ESHOP.COM", + NormalizedUserName = "JDOE@ESHOP.COM", + SecurityStamp = Guid.NewGuid().ToString("D") + }; + + user.PasswordHash = _passwordHasher.HashPassword(user, "eshopContainers.123"); + + return user; + } + } +} diff --git a/src/Services/Identity/eShopOnContainers.Identity/Services/EFLoginService.cs b/src/Services/Identity/eShopOnContainers.Identity/Services/EFLoginService.cs index b781f360e..d0f2532f6 100644 --- a/src/Services/Identity/eShopOnContainers.Identity/Services/EFLoginService.cs +++ b/src/Services/Identity/eShopOnContainers.Identity/Services/EFLoginService.cs @@ -19,7 +19,7 @@ namespace eShopOnContainers.Identity.Services public async Task FindByUsername(string user) { - return await _userManager.FindByNameAsync(user); + return await _userManager.FindByEmailAsync(user); } public async Task ValidateCredentials(ApplicationUser user, string password) diff --git a/src/Services/Identity/eShopOnContainers.Identity/Startup.cs b/src/Services/Identity/eShopOnContainers.Identity/Startup.cs index 7c38b74bd..e8b895fef 100644 --- a/src/Services/Identity/eShopOnContainers.Identity/Startup.cs +++ b/src/Services/Identity/eShopOnContainers.Identity/Startup.cs @@ -15,6 +15,8 @@ using eShopOnContainers.Identity.Services; using eShopOnContainers.Identity.Configuration; using IdentityServer4.Services; using System.Threading; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; +using Microsoft.AspNetCore.Identity; namespace eShopOnContainers.Identity { @@ -49,6 +51,7 @@ namespace eShopOnContainers.Identity services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); + services.AddMvc(); @@ -102,29 +105,10 @@ namespace eShopOnContainers.Identity template: "{controller=Home}/{action=Index}/{id?}"); }); - MigrateDb(app); - } - - int retries = 0; - - private void MigrateDb(IApplicationBuilder app) - { - try - { - var context = (ApplicationDbContext)app - .ApplicationServices.GetService(typeof(ApplicationDbContext)); - using (context) - { - context.Database.Migrate(); - } - - } - catch (Exception) - { - retries++; - if (retries < 2) - MigrateDb(app); - } + //Seed Data + var hasher = new PasswordHasher(); + new ApplicationContextSeed(hasher).SeedAsync(app, loggerFactory) + .Wait(); } } } diff --git a/src/Services/Identity/eShopOnContainers.Identity/appsettings.json b/src/Services/Identity/eShopOnContainers.Identity/appsettings.json index 9433af6c1..8fbc03c5a 100644 --- a/src/Services/Identity/eShopOnContainers.Identity/appsettings.json +++ b/src/Services/Identity/eShopOnContainers.Identity/appsettings.json @@ -1,9 +1,8 @@ { "ConnectionStrings": { - //"DefaultConnection": "Server=identity.data;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word" "DefaultConnection": "Server=127.0.0.1,5433;Database=aspnet-Microsoft.eShopOnContainers;User Id=sa;Password=Pass@word" }, - "MvcClient": "http://localhost:5100", + "MvcClient": "http://localhost:5001", "SpaClient": "http://localhost:5104", "Logging": { "IncludeScopes": false, diff --git a/src/Web/WebMVC/Program.cs b/src/Web/WebMVC/Program.cs index 0e78c2560..848e17679 100644 --- a/src/Web/WebMVC/Program.cs +++ b/src/Web/WebMVC/Program.cs @@ -14,8 +14,8 @@ namespace Microsoft.eShopOnContainers.WebMVC var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) - //.UseIISIntegration() .UseUrls("http://0.0.0.0:5100") + .UseIISIntegration() .UseStartup() .Build(); diff --git a/src/Web/WebMVC/Properties/launchSettings.json b/src/Web/WebMVC/Properties/launchSettings.json index f57f286c4..6a6a133af 100644 --- a/src/Web/WebMVC/Properties/launchSettings.json +++ b/src/Web/WebMVC/Properties/launchSettings.json @@ -3,14 +3,13 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:5100", + "applicationUrl": "http://localhost:5001", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", - "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/src/Web/WebMVC/appsettings.json b/src/Web/WebMVC/appsettings.json index 9fe15aa25..b9a09909d 100644 --- a/src/Web/WebMVC/appsettings.json +++ b/src/Web/WebMVC/appsettings.json @@ -2,7 +2,7 @@ "CatalogUrl": "http://localhost:5101", "OrderingUrl": "http://localhost:5102", "BasketUrl": "http://localhost:5103", - "IdentityUrl": "http://localhost:5105", + "IdentityUrl": "http://localhost:5000", "CallBackUrl": "http://localhost:5100/", "Logging": { "IncludeScopes": false,