Browse Source

Merge pull request #18 from dotnet-architecture/ardalis/login

Adding Login and Logging Features
main
Steve Smith 8 years ago
committed by GitHub
parent
commit
b645cb35c1
  1. 2
      src/Web/Controllers/AccountController.cs
  2. 30
      src/Web/Controllers/CatalogController.cs
  3. 24
      src/Web/Infrastructure/CatalogContextSeed.cs
  4. 6
      src/Web/Program.cs
  5. 2
      src/Web/Properties/launchSettings.json
  6. 20
      src/Web/Startup.cs
  7. 4
      src/Web/Views/Account/Signin.cshtml
  8. 19
      src/Web/Web.csproj
  9. 3
      src/Web/appsettings.json
  10. 0
      src/Web/wwwroot/images/products/1.png
  11. 0
      src/Web/wwwroot/images/products/10.png
  12. 0
      src/Web/wwwroot/images/products/11.png
  13. 0
      src/Web/wwwroot/images/products/12.png
  14. 0
      src/Web/wwwroot/images/products/2.png
  15. 0
      src/Web/wwwroot/images/products/3.png
  16. 0
      src/Web/wwwroot/images/products/4.png
  17. 0
      src/Web/wwwroot/images/products/5.png
  18. 0
      src/Web/wwwroot/images/products/6.png
  19. 0
      src/Web/wwwroot/images/products/7.png
  20. 0
      src/Web/wwwroot/images/products/8.png
  21. 0
      src/Web/wwwroot/images/products/9.png

2
src/Web/Controllers/AccountController.cs

@ -89,7 +89,7 @@ namespace Microsoft.eShopWeb.Controllers
} }
else else
{ {
return RedirectToAction(nameof(CatalogController.Index), "Home"); return RedirectToAction(nameof(CatalogController.Index), "Catalog");
} }
} }

30
src/Web/Controllers/CatalogController.cs

@ -56,21 +56,21 @@ namespace Microsoft.eShopWeb.Controllers
return View(vm); return View(vm);
} }
[HttpGet("[controller]/pic/{id}")] //[HttpGet("[controller]/pic/{id}")]
public IActionResult GetImage(int id) //public IActionResult GetImage(int id)
{ //{
byte[] imageBytes; // byte[] imageBytes;
try // try
{ // {
imageBytes = _imageService.GetImageBytesById(id); // imageBytes = _imageService.GetImageBytesById(id);
} // }
catch (CatalogImageMissingException ex) // catch (CatalogImageMissingException ex)
{ // {
_logger.LogWarning($"No image found for id: {id}"); // _logger.LogWarning($"No image found for id: {id}");
return NotFound(); // return NotFound();
} // }
return File(imageBytes, "image/png"); // return File(imageBytes, "image/png");
} //}
public IActionResult Error() public IActionResult Error()

24
src/Web/Infrastructure/CatalogContextSeed.cs

@ -85,18 +85,18 @@
{ {
return new List<CatalogItem>() return new List<CatalogItem>()
{ {
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/1" }, new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/1.png" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/2" }, new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://catalogbaseurltobereplaced/images/products/2.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/3" }, new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/3.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/4" }, new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/4.png" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/5" }, new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/5.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/6" }, new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/6.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/7" }, new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/7.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/8" }, new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/8.png" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/9" }, new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/9.png" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/10" }, new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/10.png" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/11" }, new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/11.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/12" } new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/12.png" }
}; };
} }
} }

6
src/Web/Program.cs

@ -1,5 +1,6 @@
using System.IO; using System.IO;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
namespace Microsoft.eShopWeb namespace Microsoft.eShopWeb
{ {
@ -11,6 +12,11 @@ namespace Microsoft.eShopWeb
.UseKestrel() .UseKestrel()
.UseUrls("http://0.0.0.0:5106") .UseUrls("http://0.0.0.0:5106")
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureLogging(factory =>
{
factory.AddConsole(LogLevel.Warning);
factory.AddDebug();
})
.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>() .UseStartup<Startup>()
.UseApplicationInsights() .UseApplicationInsights()

2
src/Web/Properties/launchSettings.json

@ -21,7 +21,7 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
}, },
"applicationUrl": "http://localhost:58299" "applicationUrl": "http://localhost:5106"
} }
} }
} }

20
src/Web/Startup.cs

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http;
using ApplicationCore.Interfaces; using ApplicationCore.Interfaces;
using Infrastructure.FileSystem; using Infrastructure.FileSystem;
using Infrastructure.Logging; using Infrastructure.Logging;
using Microsoft.AspNetCore.Identity;
namespace Microsoft.eShopWeb namespace Microsoft.eShopWeb
{ {
@ -41,8 +42,8 @@ namespace Microsoft.eShopWeb
{ {
try try
{ {
//c.UseInMemoryDatabase("Catalog"); c.UseInMemoryDatabase("Catalog");
c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection")); //c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
c.ConfigureWarnings(wb => c.ConfigureWarnings(wb =>
{ {
//By default, in this application, we don't want to have client evaluations //By default, in this application, we don't want to have client evaluations
@ -57,8 +58,8 @@ namespace Microsoft.eShopWeb
// Add Identity DbContext // Add Identity DbContext
services.AddDbContext<AppIdentityDbContext>(options => services.AddDbContext<AppIdentityDbContext>(options =>
//options.UseInMemoryDatabase("Identity")); options.UseInMemoryDatabase("Identity"));
options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection"))); //options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>() services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<AppIdentityDbContext>() .AddEntityFrameworkStores<AppIdentityDbContext>()
@ -76,11 +77,11 @@ namespace Microsoft.eShopWeb
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
UserManager<ApplicationUser> userManager)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
@ -124,6 +125,9 @@ namespace Microsoft.eShopWeb
//Seed Data //Seed Data
CatalogContextSeed.SeedAsync(app, loggerFactory) CatalogContextSeed.SeedAsync(app, loggerFactory)
.Wait(); .Wait();
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
} }
} }
} }

4
src/Web/Views/Account/Signin.cshtml

@ -7,7 +7,7 @@
} }
<div class="brand-header-block"> <div class="brand-header-block">
<ul class="container"> <ul class="container">
<li><a asp-area="" asp-controller="Account" asp-action="Register">REGISTER</a></li> @*<li><a asp-area="" asp-controller="Account" asp-action="Register">REGISTER</a></li>*@
<li class="active" style="margin-right: 65px;">LOGIN</li> <li class="active" style="margin-right: 65px;">LOGIN</li>
</ul> </ul>
</div> </div>
@ -15,7 +15,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<section> <section>
<form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal"> <form asp-controller="Account" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
<h4>ARE YOU REGISTERED?</h4> <h4>ARE YOU REGISTERED?</h4>
<div asp-validation-summary="All" class="text-danger"></div> <div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group"> <div class="form-group">

19
src/Web/Web.csproj

@ -41,5 +41,24 @@
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="wwwroot\images\products\1.png" />
<None Include="wwwroot\images\products\10.png" />
<None Include="wwwroot\images\products\11.png" />
<None Include="wwwroot\images\products\12.png" />
<None Include="wwwroot\images\products\2.png" />
<None Include="wwwroot\images\products\3.png" />
<None Include="wwwroot\images\products\4.png" />
<None Include="wwwroot\images\products\5.png" />
<None Include="wwwroot\images\products\6.png" />
<None Include="wwwroot\images\products\7.png" />
<None Include="wwwroot\images\products\8.png" />
<None Include="wwwroot\images\products\9.png" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project> </Project>

3
src/Web/appsettings.json

@ -8,7 +8,8 @@
"IncludeScopes": false, "IncludeScopes": false,
"LogLevel": { "LogLevel": {
"Default": "Warning", "Default": "Warning",
"Microsoft" : "Warning" "Microsoft": "Warning",
"System": "Warning"
} }
} }
} }

0
src/Web/Pics/1.png → src/Web/wwwroot/images/products/1.png

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

0
src/Web/Pics/10.png → src/Web/wwwroot/images/products/10.png

Before

Width:  |  Height:  |  Size: 223 KiB

After

Width:  |  Height:  |  Size: 223 KiB

0
src/Web/Pics/11.png → src/Web/wwwroot/images/products/11.png

Before

Width:  |  Height:  |  Size: 212 KiB

After

Width:  |  Height:  |  Size: 212 KiB

0
src/Web/Pics/12.png → src/Web/wwwroot/images/products/12.png

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

0
src/Web/Pics/2.png → src/Web/wwwroot/images/products/2.png

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

0
src/Web/Pics/3.png → src/Web/wwwroot/images/products/3.png

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 170 KiB

0
src/Web/Pics/4.png → src/Web/wwwroot/images/products/4.png

Before

Width:  |  Height:  |  Size: 152 KiB

After

Width:  |  Height:  |  Size: 152 KiB

0
src/Web/Pics/5.png → src/Web/wwwroot/images/products/5.png

Before

Width:  |  Height:  |  Size: 226 KiB

After

Width:  |  Height:  |  Size: 226 KiB

0
src/Web/Pics/6.png → src/Web/wwwroot/images/products/6.png

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 179 KiB

0
src/Web/Pics/7.png → src/Web/wwwroot/images/products/7.png

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 182 KiB

0
src/Web/Pics/8.png → src/Web/wwwroot/images/products/8.png

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 167 KiB

0
src/Web/Pics/9.png → src/Web/wwwroot/images/products/9.png

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Loading…
Cancel
Save