diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs index 55c7b1f..0f5e2a7 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs @@ -22,7 +22,7 @@ public class LoginController : Controller { } public class LoginUser { - public string username { get; set; } = ""; + public string email { get; set; } = ""; public string password { get; set; } = ""; } @@ -35,7 +35,7 @@ public class LoginController : Controller { [HttpPost, Route("Login"), AllowAnonymous] public async Task Login(LoginUser user, bool rememberMe = false) { - return await _signInMan.PasswordSignInAsync(user.username, user.password, rememberMe, false); + return await _signInMan.PasswordSignInAsync(await _userMan.FindByEmailAsync(user.email), user.password, rememberMe, false); } [HttpPost, Route("Logout")] diff --git a/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs b/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs index d442f54..234494f 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs @@ -204,6 +204,7 @@ public class InventoryContext : IdentityDbContext { InventoryUser admin = new InventoryUser() { NormalizedUserName = "admin", UserName = "Admin", NormalizedEmail = "admin@admin.com", Email = "admin@admin.com" }; admin.PasswordHash = new PasswordHasher().HashPassword(admin, "Qwerty123!"); modelBuilder.Entity().HasData(admin); + } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var configuration = new ConfigurationBuilder() diff --git a/GrossesMitaines/GrossesMitainesAPI/Data/InventoryUser.cs b/GrossesMitaines/GrossesMitainesAPI/Data/InventoryUser.cs index 86cc6a5..4f25639 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Data/InventoryUser.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Data/InventoryUser.cs @@ -1,6 +1,28 @@ using Microsoft.AspNetCore.Identity; +using System.ComponentModel.DataAnnotations; namespace GrossesMitainesAPI.Data; public class InventoryUser : IdentityUser { + public class Address { + [Key] + public int Id { get; set; } + [Required, Range(1, int.MaxValue)] + public int CivicNumber { get; set; } + public string? Appartment { get; set; } + [Required, MinLength(3), MaxLength(50)] + public string Street { get; set; } + [Required, MinLength(4), MaxLength(50)] + public string City { get; set; } + [Required, MaxLength(2)] + public string Province { get; set; } + [Required, MinLength(4), MaxLength(30)] + public string Country { get; set; } + // Source pour regex: https://stackoverflow.com/questions/15774555/efficient-regex-for-canadian-postal-code-function + [Required, RegularExpression(@"/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i")] + public string PostalCode { get; set; } + } + + public List
Adresses { get; set; } + } diff --git a/GrossesMitaines/GrossesMitainesAPI/Models/InvoiceModel.cs b/GrossesMitaines/GrossesMitainesAPI/Models/InvoiceModel.cs new file mode 100644 index 0000000..967ce71 --- /dev/null +++ b/GrossesMitaines/GrossesMitainesAPI/Models/InvoiceModel.cs @@ -0,0 +1,12 @@ +using GrossesMitainesAPI.Data; +using System.Collections.Generic; + +namespace GrossesMitainesAPI.Models; +public class InvoiceModel { + public InventoryUser Account { get; set; } + public DateTime PurchaseDate { get; set; } + public Dictionary Products { get; set; } + public InventoryUser.Address BillingAddress { get; set; } + public InventoryUser.Address ShippingAddress { get; set; } +} + diff --git a/TP03_-_Commerce_electronique.pdf b/TP03_-_Commerce_electronique.pdf new file mode 100644 index 0000000..052b9c3 Binary files /dev/null and b/TP03_-_Commerce_electronique.pdf differ