@page "/" @using Controllers.Payment @using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments @rendermode InteractiveServer Home
@if (Session == null){

LOGIN

username
password
@loginError
}else{

Account

UserName: @Session.UserName
Money: $@Session.Money

Actions

@resultError
} @if (Session != null){

Current Signal

@foreach (Stock cur in Session.TrackedStocks){

@cur.Symbol

AI Predicted Score: @cur.Score

}

Trade History

@foreach (PurchasedStock cur in Session.TradeHistory){

@cur.Symbol

Purchased Quantity: @cur.Quantity

Purchased Price: @cur.PurchasePrice

Sell Price: @cur.PurchasePrice

}
}
@code { ///////////////////////////////////////////////////////////////////////////////////////////// /// Code Region ///////////////////////////////////////////////////////////////////////////////////////////// loginSession? Session = null; string resultError = ""; // Login Stuff string userName = ""; string passWord = ""; string loginError = ""; async Task LoginSession(){ string dbPrefix = $"[{userName.ToLower()}]:"; // Check if user already exists string passwordhash = dbDriver.Get( dbPrefix + "password" ); if (string.IsNullOrEmpty(passwordhash)){ loginError = "no account found with that username"; return; } // Check the password is valid if (!BCrypt.Verify( passWord, passwordhash )){ loginError = "wrong password"; return; } // Load the users account List? history = JsonConvert.DeserializeObject>( dbDriver.Get( dbPrefix + "history" ) ); List? stocks = JsonConvert.DeserializeObject>( dbDriver.Get( dbPrefix + "watched" ) ); bool moneyLoaded = float.TryParse(dbDriver.Get( dbPrefix + "money" ), out float moneyResult); Session = new loginSession(){ UserName = userName.ToLower(), TradeHistory = history != null ? history : new List(), TrackedStocks = stocks != null ? stocks : new List(), Money = moneyLoaded ? moneyResult : 1000 }; } async Task registerSession(){ string dbPrefix = $"[{userName.ToLower()}]:"; // Check if user already exists string passwordhash = dbDriver.Get( dbPrefix + "password" ); if (!string.IsNullOrEmpty(passwordhash)){ loginError = "account is taken"; return; } // Create User Object on the database dbDriver.Set( dbPrefix + "password", BCrypt.HashPassword( passWord, BCrypt.GenerateSalt() ) ); dbDriver.Set( dbPrefix + "money", "1000" ); Session = new loginSession(){ UserName = userName.ToLower(), TradeHistory = new List(), TrackedStocks = new List(), Money = 1000 }; // Add the users to a global table for automation List? Users = JsonConvert.DeserializeObject>( dbDriver.Get( "Users" ) ); List verifiedUsers = Users != null ? Users : new List(); verifiedUsers.Add(userName.ToLower()); dbDriver.Set( "Users", JsonConvert.SerializeObject(verifiedUsers) ); } string addStockSymbol = ""; async Task addStock(){ // Make sure a session exists if (Session == null){ return; } // Add a tracked stock to the users account Session.TrackedStocks.Add(new Stock(){ Symbol = addStockSymbol.ToUpper() }); // Save the users account string dbPrefix = $"[{userName.ToLower()}]:"; dbDriver.Set(dbPrefix + "watched", JsonConvert.SerializeObject(Session.TrackedStocks) ); } async Task removeStock(Stock stock){ // Make sure a session exists if (Session == null){ return; } // Remove the stock Session.TrackedStocks.Remove(stock); // Save the users account string dbPrefix = $"[{userName.ToLower()}]:"; dbDriver.Set(dbPrefix + "watched", JsonConvert.SerializeObject(Session.TrackedStocks) ); } }