diff --git a/ToDo.txt b/ToDo.txt index a7eb16d..2095127 100755 --- a/ToDo.txt +++ b/ToDo.txt @@ -24,4 +24,7 @@ Store Catalog Add to cart wraps text when screen is too small Program - Probably need to turn on cors at some point \ No newline at end of file + Probably need to turn on cors at some point + +ProductController + No way to download products \ No newline at end of file diff --git a/src/MistoxWebsite.Server/Controllers/AuthenticationController.cs b/src/MistoxWebsite.Server/Controllers/AuthenticationController.cs index 3d2f724..e128c95 100755 --- a/src/MistoxWebsite.Server/Controllers/AuthenticationController.cs +++ b/src/MistoxWebsite.Server/Controllers/AuthenticationController.cs @@ -1,10 +1,11 @@ using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Mvc; -using MistoxWebsite.Shared; using System.Security.Claims; using MistoxWebsite.Server.Services; using MistoxWebsite.Server.Services.DatabaseService; -using Microsoft.AspNetCore.Authentication.Cookies; +using MistoxWebsite.Shared.Database; +using MistoxWebsite.Shared.DTO.Session; namespace MistoxWebsite.Server.Controllers { [ApiController] diff --git a/src/MistoxWebsite.Server/Controllers/PageLoad.cs b/src/MistoxWebsite.Server/Controllers/PageLoad.cs index 16b081a..9399ab9 100755 --- a/src/MistoxWebsite.Server/Controllers/PageLoad.cs +++ b/src/MistoxWebsite.Server/Controllers/PageLoad.cs @@ -1,6 +1,6 @@ using MistoxWebsite.Server.Services.DatabaseService; using System.Security.Claims; -using MistoxWebsite.Shared; +using MistoxWebsite.Shared.DTO.Session; using Microsoft.AspNetCore.Mvc; namespace MistoxWebsite.Server.Controllers { diff --git a/src/MistoxWebsite.Server/Controllers/PaymentController.cs b/src/MistoxWebsite.Server/Controllers/PaymentController.cs index ba348c1..a12ee29 100755 --- a/src/MistoxWebsite.Server/Controllers/PaymentController.cs +++ b/src/MistoxWebsite.Server/Controllers/PaymentController.cs @@ -1,12 +1,8 @@ -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using MistoxWebsite.Server.Controllers.Payment; using MistoxWebsite.Server.Services.DatabaseService; -using MistoxWebsite.Shared; -using Newtonsoft.Json; +using MistoxWebsite.Shared.Database; using Stripe; -using Stripe.Climate; -using Stripe.Tax; namespace MistoxWebsite.Server.Controllers { [ApiController] @@ -24,7 +20,7 @@ namespace MistoxWebsite.Server.Controllers { public async Task GetPaymentKey( [FromQuery] string userID ) { string OrderNumber = Guid.NewGuid().ToString().Substring(0,10); - Shared.Account? acc = await _databaseService.GetAccount(userID); + Shared.Database.Account? acc = await _databaseService.GetAccount(userID); if (acc != null) { List cart = await _databaseService.GetCart(acc); @@ -84,7 +80,7 @@ namespace MistoxWebsite.Server.Controllers { } // Clear the cart - Shared.Account account = new Shared.Account{ + Shared.Database.Account account = new() { ID = userID }; await _databaseService.ClearCart( account ); diff --git a/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs b/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs index b36973a..7250254 100644 --- a/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs +++ b/src/MistoxWebsite.Server/Controllers/PaymentMethods/IPayment.cs @@ -1,4 +1,4 @@ -using MistoxWebsite.Shared; +using MistoxWebsite.Shared.Database; namespace MistoxWebsite.Server.Controllers.Payment { diff --git a/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs b/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs index ee7f0f0..3c4d213 100644 --- a/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs +++ b/src/MistoxWebsite.Server/Controllers/PaymentMethods/StripeIntents.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections; -using System.Collections.Generic; using MistoxWebsite.Server.Controllers.Payment; using MistoxWebsite.Server.Services.DatabaseService; -using MistoxWebsite.Shared; +using MistoxWebsite.Shared.Database; using Stripe; using Stripe.Tax; @@ -17,7 +14,7 @@ namespace MistoxWebsite.Server.Controllers { _databaseService = databaseService; } - public async Task<(bool, string)> Purchase(string OrderNumber, Shared.Account user, List cart) { + public async Task<(bool, string)> Purchase(string OrderNumber, Shared.Database.Account user, List cart) { try { // build Recipt and calculate Tax var options = new CalculationCreateOptions { @@ -34,7 +31,7 @@ namespace MistoxWebsite.Server.Controllers { // Add items to receipt int subtotal = 0; foreach (Cart items in cart) { - Shared.Product? product = await _databaseService.GetProduct(items.ProductID); + Shared.Database.Product? product = await _databaseService.GetProduct(items.ProductID); if (product != null) { prods.Add(product.ID); if (product != null) { diff --git a/src/MistoxWebsite.Server/Controllers/ProductController.cs b/src/MistoxWebsite.Server/Controllers/ProductController.cs index ff4d27a..f09735d 100755 --- a/src/MistoxWebsite.Server/Controllers/ProductController.cs +++ b/src/MistoxWebsite.Server/Controllers/ProductController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; using MistoxWebsite.Server.Services.DatabaseService; -using MistoxWebsite.Shared; +using MistoxWebsite.Shared.Database; using Newtonsoft.Json; using System.Security.Claims; using System.Text; @@ -128,74 +128,6 @@ namespace MistoxWebsite.Server.Controllers { } } - DirObj RecursiveBuild( DirObj DirObj, string workingPath, List purchased ) { - - string[] files = Directory.GetFiles(workingPath); - string[] directories = Directory.GetDirectories(workingPath); - - List building = new List(); - - // Get File Names - Parallel.For( 0, files.Length, ( i ) => { - string fileName = files[i].Substring(workingPath.Length, files[i].Length - (workingPath.Length)); - building.Add( new DirObj { - Type = FileType.File, - Path = fileName - }); - } ); - - // Get Path Names - Parallel.For( 0, directories.Length, ( i ) => { - foreach( ReceiptProduct cur in purchased ) { - string dirName = directories[i].Substring(workingPath.Length, directories[i].Length - (workingPath.Length)); - if( contains( dirName, cur.product.URL ) ) { - DirObj dir = new DirObj { - Type = FileType.Directory, - Path = dirName, - }; - building.Add( dir ); - RecursiveBuild( dir, directories [i], purchased ); - } - } - } ); - - DirObj.Children = building.ToArray(); - - return DirObj; - } - - string _FolderRoot = "/home/downloads/"; - - [Route( "api/product/showdownloads" )] - [HttpPost] - public async Task ShowDownloads() { - try { - if( User.Identity != null && User.Identity.IsAuthenticated ) { - - List userClaims = User.Claims.ToList(); - int UserID = -1; - foreach( Claim claim in userClaims ) { - if( claim.Type == "ID" ) { - UserID = Convert.ToInt32( claim.Value ); - break; - } - } - - List purchased = await _databaseService.GetAllReceiptsJoinedToProduct( new Account{ ID = UserID } ); - - byte[] datapacket = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(RecursiveBuild(new DirObj { - Path = @"\", - Type = FileType.Directory, - }, _FolderRoot, purchased))); - - return new FileContentResult( datapacket, "text/html" ); - } - return Unauthorized(); - } catch { - return NotFound(); - } - } - bool contains( string outer, string inner ) { if ( outer.Length >= inner.Length ) { for ( int i=0; i> GetAllReceiptsJoinedToProduct( Account account ) { - List join = new List (); + public async Task> GetAllReceiptsJoinedToProduct( Account account ) { + List<( Receipt, Product )> join = new(); using( MySqlConnection connection = GetConnection() ) { connection.Open(); string command = @" @@ -78,24 +78,25 @@ namespace MistoxWebsite.Server.Services.DatabaseService { int _cost = !reader.IsDBNull( "Cost" ) ? reader.GetInt32("Cost") : 0; string _url = !reader.IsDBNull( "URL" ) ? reader.GetString("URL") : "Something Random That Wont Ever Be In A URL"; - join.Add( new ReceiptProduct() { - receipt = new Receipt { - AccountID = _accountid, - ProductID = _gameid, - ReceiptID = _receiptid, - Time = _receiptdate, - TotalCost = _totalcost, - TaxAmount = _taxamount, - LineItem = _lineitem - }, - product = new Product() { - ID = _id, - Cost = _cost, - Description = _desc, - Name = _name, - URL = _url - } - } ); + Receipt r = new() { + AccountID = _accountid, + ProductID = _gameid, + ReceiptID = _receiptid, + Time = _receiptdate, + TotalCost = _totalcost, + TaxAmount = _taxamount, + LineItem = _lineitem + }; + + Product p = new() { + ID = _id, + Cost = _cost, + Description = _desc, + Name = _name, + URL = _url + }; + + join.Add( (r, p) ); } } } diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/WebsiteData.cs b/src/MistoxWebsite.Server/Services/DatabaseService/WebsiteData.cs index 5911559..9bede5d 100755 --- a/src/MistoxWebsite.Server/Services/DatabaseService/WebsiteData.cs +++ b/src/MistoxWebsite.Server/Services/DatabaseService/WebsiteData.cs @@ -1,4 +1,4 @@ -using MistoxWebsite.Shared; +using MistoxWebsite.Shared.Database; using MySql.Data.MySqlClient; using System.Data; using System.Data.Common; diff --git a/src/MistoxWebsite.Server/Services/EmailService/ResetPasswordEmail.cs b/src/MistoxWebsite.Server/Services/EmailService/ResetPasswordEmail.cs index 8d075bc..4299e6d 100755 --- a/src/MistoxWebsite.Server/Services/EmailService/ResetPasswordEmail.cs +++ b/src/MistoxWebsite.Server/Services/EmailService/ResetPasswordEmail.cs @@ -1,5 +1,3 @@ -using System.Net.Mail; - namespace MistoxWebsite.Server.Services { public partial class EmailService { diff --git a/src/MistoxWebsite.Server/Services/EmailService/VerifyEmail.cs b/src/MistoxWebsite.Server/Services/EmailService/VerifyEmail.cs index a22b4a6..e067ede 100755 --- a/src/MistoxWebsite.Server/Services/EmailService/VerifyEmail.cs +++ b/src/MistoxWebsite.Server/Services/EmailService/VerifyEmail.cs @@ -1,5 +1,3 @@ -using System.Net.Mail; - namespace MistoxWebsite.Server.Services { public partial class EmailService { diff --git a/src/MistoxWebsite.Shared/DataTransferObjects/Account.cs b/src/MistoxWebsite.Shared/DataTransferObjects/Account.cs new file mode 100644 index 0000000..f4c900e --- /dev/null +++ b/src/MistoxWebsite.Shared/DataTransferObjects/Account.cs @@ -0,0 +1,20 @@ +namespace MistoxWebsite.Shared.DTO.Account { + + public class UserInventory { + public string Item { get; set; } = string.Empty; + public int Quantity { get; set; } + public string Stats { get; set; } = string.Empty; + } + + public class PaymentObject { + public string CardNumber { get; set; } = string.Empty; + public long ExperationMonth { get; set; } + public long ExperationYear { get; set; } + public string CVC { get; set; } = string.Empty; + public string FullName { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Zip { get; set; } = string.Empty; + public List productIDs { get; set; } = new List(); + } + +} \ No newline at end of file diff --git a/src/MistoxWebsite.Shared/DataTransferObjects/Session.cs b/src/MistoxWebsite.Shared/DataTransferObjects/Session.cs new file mode 100644 index 0000000..70d4667 --- /dev/null +++ b/src/MistoxWebsite.Shared/DataTransferObjects/Session.cs @@ -0,0 +1,21 @@ +using MistoxWebsite.Shared.Database; + +namespace MistoxWebsite.Shared.DTO.Session { + + public class PageLoadObject { + public Database.Account? user { get; set; } + public AccountClaims? claims { get; set; } + public List? receipts { get; set; } + public List? products { get; set; } + public List? Cart { get; set; } + } + + public class AccountClaims { + public string UserName { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string EmailVerified { get; set; } = string.Empty; + public string Role { get; set; } = string.Empty; + public string FailedPasswordLock { get; set; } = string.Empty; + } + +} \ No newline at end of file diff --git a/src/MistoxWebsite.Shared/DatabaseObjects.cs b/src/MistoxWebsite.Shared/DatabaseObjects.cs index 5988e6c..b800e56 100755 --- a/src/MistoxWebsite.Shared/DatabaseObjects.cs +++ b/src/MistoxWebsite.Shared/DatabaseObjects.cs @@ -1,27 +1,6 @@ -using System.Diagnostics; +// Reflections of SQL Database objects -// Reflections of SQL Database objects - -namespace MistoxWebsite.Shared { - - public class PageLoadObject { - public Account? user { get; set; } - public AccountClaims? claims { get; set; } - public List? receipts { get; set; } - public List? products { get; set; } - public List? Cart { get; set; } - } - - public class DirObj { - public FileType? Type { get; set; } - public string Path { get; set; } = ""; - public DirObj? [] Children { get; set; } = new DirObj?[0]; - } - - public enum FileType { - File, - Directory - } +namespace MistoxWebsite.Shared.Database { public class Account { public int ID { get; set; } // PK @@ -33,25 +12,6 @@ namespace MistoxWebsite.Shared { public string Error { get; set; } = ""; } - public class Product { - public int ID { get; set; } // PK - public string Name { get; set; } = ""; - public string Description { get; set; } = ""; - public int CurShowingIMG = 0; - public List Images { get; set; } = new List(); - public int Cost { get; set; } - public string URL { get; set; } = ""; - } - - public class WebSiteData { - public int AccountID { get; set; } // PK - public bool FailedPasswordLock { get; set; } = false; - public int PasswordAttempts { get; set; } = 5; - public int CurrentPasswordAttempts { get; set; } = 0; - public string Role { get; set; } = "Generic"; - public string EmailToken { get; set; } = ""; - } - public class AccountInventory { public int AccountID { get; set; } // PK public int ProductID { get; set; } // PK @@ -60,25 +20,14 @@ namespace MistoxWebsite.Shared { public string Stats { get; set; } = string.Empty; } - public class UserInventory { - public string Item { get; set; } = string.Empty; - public int Quantity { get; set; } - public string Stats { get; set; } = string.Empty; - } - - public class Receipt { - public int AccountID { get; set; } // PK - public int ProductID { get; set; } // PK - public string ReceiptID { get; set; } = string.Empty; - public int LineItem { get; set; } - public int TaxAmount { get; set; } - public int TotalCost { get; set; } - public DateTime Time { get; set; } - } - - public class ReceiptProduct { - public Receipt receipt { get; set; } = new Receipt(); - public Product product { get; set; } = new Product(); + public class Product { + public int ID { get; set; } // PK + public string Name { get; set; } = ""; + public string Description { get; set; } = ""; + public int CurShowingIMG = 0; + public List Images { get; set; } = new List(); + public int Cost { get; set; } + public string URL { get; set; } = ""; } public class Cart { @@ -97,23 +46,23 @@ namespace MistoxWebsite.Shared { public int Deaths { get; set; } } - public class AccountClaims { - public string UserName { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string EmailVerified { get; set; } = string.Empty; - public string Role { get; set; } = string.Empty; - public string FailedPasswordLock { get; set; } = string.Empty; + public class Receipt { + public int AccountID { get; set; } // PK + public int ProductID { get; set; } // PK + public string ReceiptID { get; set; } = string.Empty; + public int LineItem { get; set; } + public int TaxAmount { get; set; } + public int TotalCost { get; set; } + public DateTime Time { get; set; } } - public class PaymentObject { - public string CardNumber { get; set; } = string.Empty; - public long ExperationMonth { get; set; } - public long ExperationYear { get; set; } - public string CVC { get; set; } = string.Empty; - public string FullName { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Zip { get; set; } = string.Empty; - public List productIDs { get; set; } = new List(); + public class WebSiteData { + public int AccountID { get; set; } // PK + public bool FailedPasswordLock { get; set; } = false; + public int PasswordAttempts { get; set; } = 5; + public int CurrentPasswordAttempts { get; set; } = 0; + public string Role { get; set; } = "Generic"; + public string EmailToken { get; set; } = ""; } } \ No newline at end of file