diff --git a/Account.cs b/Account.cs index b82bb63..e6f1432 100644 --- a/Account.cs +++ b/Account.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; using MySql.Data.MySqlClient; +namespace NightmareCoreWeb2 { + public class Account { public UInt32 Id { get; set; } @@ -9,7 +11,32 @@ public class Account public string Email { get; set; } public string LastIP { get; set; } public DateTime LastLogin { get; set; } - public List characters { get; set; } + public List Characters { get; set; } + public List Access { get; set; } + + + public Account AccountByID(int id, MySqlConnection conn) + { + conn.Open(); + string sql = "select username from account where id=@id"; + MySqlCommand cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("id", id); + MySqlDataReader rdr = cmd.ExecuteReader(); + while (rdr.Read()) + { + try + { + this.Username = rdr.GetString(0); + return new Account(this.Username, conn); + + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + return null; + } public Account(string username, MySqlConnection conn) { @@ -40,7 +67,7 @@ public class Account cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("id", this.Id); rdr = cmd.ExecuteReader(); - this.characters = new List(); + this.Characters = new List(); while (rdr.Read()) { try @@ -51,7 +78,28 @@ public class Account c.Level = rdr.GetByte(2); c.Race = rdr.GetByte(3); c.Class = rdr.GetByte(4); - this.characters.Add(c); + this.Characters.Add(c); + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + rdr.Close(); + + sql = "select SecurityLevel,RealmID from account_access where AccountID=@id"; + cmd = new MySqlCommand(sql, conn); + cmd.Parameters.AddWithValue("id", this.Id); + rdr = cmd.ExecuteReader(); + this.Access = new List(); + while (rdr.Read()) + { + try + { + AccountAccess acctA = new AccountAccess(); + acctA.SecurityLevel = rdr.GetByte(0); + acctA.RealmID = rdr.GetInt32(1); + this.Access.Add(acctA); } catch (Exception e) { @@ -59,7 +107,14 @@ public class Account } } rdr.Close(); + conn.Close(); } +} +public class AccountAccess +{ + public int SecurityLevel { get; set; } + public int RealmID { get; set; } +} } \ No newline at end of file diff --git a/NightmareCoreWeb2.csproj b/NightmareCoreWeb2.csproj index f3c43b7..6913b94 100644 --- a/NightmareCoreWeb2.csproj +++ b/NightmareCoreWeb2.csproj @@ -4,10 +4,9 @@ net5.0 - - - - + + + diff --git a/Pages/Account.cshtml b/Pages/Account.cshtml index 611addd..5646e31 100644 --- a/Pages/Account.cshtml +++ b/Pages/Account.cshtml @@ -3,51 +3,91 @@ @{ }
- @if (string.IsNullOrEmpty(Model.AuthToken)) { + @if (string.IsNullOrEmpty(Model.AuthToken)) + {
-
-
+ +
- -
+ +
-
-
- } else { - -
+ +
+ } + else + { + +
+
+
+
+
+
Account Info
+
+
+

Username: @Model.UserAccount.Username

+

Email: @Model.UserAccount.Email

+

Last IP: @Model.UserAccount.LastIP

+

Last Login: @Model.UserAccount.LastLogin.ToLocalTime()

+
+
+
+
+
+
+ @if (Model.IsGM) + { + @foreach (var ticket in Model.Tickets) + { + if (ticket.ClosedBy == null) + { +
+
+
+
@ticket.CharacterName
+
+
+

@ticket.Description

+
+ +
+
+ } + } -
-

@Model.CharacterListType

- - - - - - - - - - - - @foreach (var character in Model.OnlineCharacters) { - - - - - - - } - -
PlayerCharacterLevelRaceClass
@character.Username@character.Name@character.Level@character.GetRace()@character.GetClass()
+ else + { + @foreach (var character in Model.OnlineCharacters) + { +
+
+
+
@character.Name
+
+
+

Card action buttons could go here!

+
+ +
+
+ } + } + + +
-
- +
+ }
\ No newline at end of file diff --git a/Pages/Account.cshtml.cs b/Pages/Account.cshtml.cs index 783add7..3fb1b56 100644 --- a/Pages/Account.cshtml.cs +++ b/Pages/Account.cshtml.cs @@ -14,35 +14,69 @@ namespace NightmareCoreWeb2.Pages string connStr = $"SslMode=None;server={Program.MysqlServer};user={Program.MysqlUser};database={Program.MysqlDatabase};port={Program.MysqlPort};password={Program.MysqlPassword}"; public string UserEmail { get; set; } public string UserPassword { get; set; } - public string CharacterListType {get; set;} + public string CharacterListType { get; set; } public string AuthToken { get; set; } - public string Username {get; set;} - + public string Username { get; set; } + public bool IsGM { get; set; } + public Account UserAccount { get; set; } + public List OnlineCharacters = new List(); + public List Tickets = new List(); private readonly ILogger _logger; private MySqlConnection conn; public AccountModel(ILogger logger) { - + conn = new MySqlConnection(connStr); _logger = logger; } + public void OnGetAccount(string name) + { + + Account a = new Account(name, conn); + //AuthToken = "OK"; + UserAccount = a; + OnlineCharacters = a.Characters; + foreach (var access in a.Access) + { + if (access.RealmID == -1 && access.RealmID >= 1) + { + this.IsGM = true; + this.Tickets = GMTicket.GetAllTickets(conn); + } + } + ViewData["Title"] = a.Username; + CharacterListType = $"{a.Username}'s Characters"; + } public void OnGet() { ViewData["Title"] = "Login"; AuthToken = Request.Cookies["AuthToken"]; Username = Request.Cookies["Username"]; - if (!string.IsNullOrEmpty(Username)) { + if (!string.IsNullOrEmpty(Username)) + { Account a = new Account(Username, conn); - OnlineCharacters = a.characters; - + AuthToken = "OK"; + UserAccount = a; + OnlineCharacters = a.Characters; + foreach (var access in a.Access) + { + if (access.RealmID == -1 && access.RealmID >= 1) + { + this.IsGM = true; + this.Tickets = GMTicket.GetAllTickets(conn); + } + } ViewData["Title"] = a.Username; CharacterListType = $"{a.Username}'s Characters"; - } + } } + + + public void OnPostLogin() { UserEmail = Request.Form["UserEmail"]; @@ -59,5 +93,6 @@ namespace NightmareCoreWeb2.Pages var hash = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(input)); return string.Concat(hash.Select(b => b.ToString("x2"))); } + } } diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs index 9563c39..dc1c07f 100644 --- a/Pages/Index.cshtml.cs +++ b/Pages/Index.cshtml.cs @@ -71,7 +71,7 @@ namespace NightmareCoreWeb2.Pages Account a = new Account(name, conn); ViewData["Title"] = name; CharacterListType = $"{name}'s Characters"; - OnlineCharacters = a.characters; + OnlineCharacters = a.Characters; } public void OnPostActivateAccount() {