Account progress
This commit is contained in:
61
Account.cs
61
Account.cs
@ -2,6 +2,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
namespace NightmareCoreWeb2 {
|
||||||
|
|
||||||
public class Account
|
public class Account
|
||||||
{
|
{
|
||||||
public UInt32 Id { get; set; }
|
public UInt32 Id { get; set; }
|
||||||
@ -9,7 +11,32 @@ public class Account
|
|||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
public string LastIP { get; set; }
|
public string LastIP { get; set; }
|
||||||
public DateTime LastLogin { get; set; }
|
public DateTime LastLogin { get; set; }
|
||||||
public List<Character> characters { get; set; }
|
public List<Character> Characters { get; set; }
|
||||||
|
public List<AccountAccess> 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)
|
public Account(string username, MySqlConnection conn)
|
||||||
{
|
{
|
||||||
@ -40,7 +67,7 @@ public class Account
|
|||||||
cmd = new MySqlCommand(sql, conn);
|
cmd = new MySqlCommand(sql, conn);
|
||||||
cmd.Parameters.AddWithValue("id", this.Id);
|
cmd.Parameters.AddWithValue("id", this.Id);
|
||||||
rdr = cmd.ExecuteReader();
|
rdr = cmd.ExecuteReader();
|
||||||
this.characters = new List<Character>();
|
this.Characters = new List<Character>();
|
||||||
while (rdr.Read())
|
while (rdr.Read())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -51,7 +78,7 @@ public class Account
|
|||||||
c.Level = rdr.GetByte(2);
|
c.Level = rdr.GetByte(2);
|
||||||
c.Race = rdr.GetByte(3);
|
c.Race = rdr.GetByte(3);
|
||||||
c.Class = rdr.GetByte(4);
|
c.Class = rdr.GetByte(4);
|
||||||
this.characters.Add(c);
|
this.Characters.Add(c);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -59,7 +86,35 @@ public class Account
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rdr.Close();
|
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<AccountAccess>();
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rdr.Close();
|
||||||
|
|
||||||
conn.Close();
|
conn.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public class AccountAccess
|
||||||
|
{
|
||||||
|
public int SecurityLevel { get; set; }
|
||||||
|
public int RealmID { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,7 +5,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="json.net" Version="1.0.33" />
|
|
||||||
<PackageReference Include="MySql.Data" Version="8.0.26" />
|
<PackageReference Include="MySql.Data" Version="8.0.26" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -3,10 +3,11 @@
|
|||||||
@{
|
@{
|
||||||
}
|
}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@if (string.IsNullOrEmpty(Model.AuthToken)) {
|
@if (string.IsNullOrEmpty(Model.AuthToken))
|
||||||
|
{
|
||||||
<div id="LoginForm">
|
<div id="LoginForm">
|
||||||
<form action="?handler=Login" method="post" enctype="multipart/form-data">
|
<form action="?handler=Login" method="post" enctype="multipart/form-data">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="UserEmail">E-mail:</label>
|
<label for="UserEmail">E-mail:</label>
|
||||||
<input asp-for="UserEmail" type="text" id="UserEmail" />
|
<input asp-for="UserEmail" type="text" id="UserEmail" />
|
||||||
</div>
|
</div>
|
||||||
@ -14,40 +15,79 @@
|
|||||||
<label for="UserPassword">Password:</label>
|
<label for="UserPassword">Password:</label>
|
||||||
<input asp-for="UserPassword" type="password" id="UserPassword">
|
<input asp-for="UserPassword" type="password" id="UserPassword">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
|
||||||
} else {
|
|
||||||
<!-- Page Content -->
|
|
||||||
<div id="page-content-wrapper">
|
|
||||||
|
|
||||||
|
|
||||||
<div class="container-fluid">
|
|
||||||
<h1 class="mt-4">@Model.CharacterListType</h1>
|
|
||||||
<table class="table table-striped table-dark" >
|
|
||||||
<thead class="thead-dark">
|
|
||||||
<tr>
|
|
||||||
<th scope="col">Player</th>
|
|
||||||
<th scope="col">Character</th>
|
|
||||||
<th scope="col">Level</th>
|
|
||||||
<th scope="col">Race</th>
|
|
||||||
<th scope="col">Class</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@foreach (var character in Model.OnlineCharacters) {
|
|
||||||
<tr>
|
|
||||||
<td>@character.Username</td>
|
|
||||||
<td>@character.Name</td>
|
|
||||||
<td>@character.Level</td>
|
|
||||||
<td>@character.GetRace()</td>
|
|
||||||
<td>@character.GetClass()</td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
}
|
||||||
<!-- /#page-content-wrapper -->
|
else
|
||||||
|
{
|
||||||
|
<!-- Page Content -->
|
||||||
|
<div id="page-content-wrapper">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-5">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h6>Account Info</h6>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text">Username: @Model.UserAccount.Username</p>
|
||||||
|
<p class="card-text">Email: @Model.UserAccount.Email</p>
|
||||||
|
<p class="card-text">Last IP: @Model.UserAccount.LastIP</p>
|
||||||
|
<p class="card-text">Last Login: @Model.UserAccount.LastLogin.ToLocalTime()</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
<div class="container" style="display: flex; flex-wrap: wrap;">
|
||||||
|
@if (Model.IsGM)
|
||||||
|
{
|
||||||
|
@foreach (var ticket in Model.Tickets)
|
||||||
|
{
|
||||||
|
if (ticket.ClosedBy == null)
|
||||||
|
{
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h6>@ticket.CharacterName</h6>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text">@ticket.Description</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer text-muted">
|
||||||
|
<p>Opened @ticket.CreateTime.ToLocalTime()</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@foreach (var character in Model.OnlineCharacters)
|
||||||
|
{
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h6>@character.Name</h6>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text">Card action buttons could go here!</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer text-muted">
|
||||||
|
<p>Level @character.Level @character.GetRace() @character.GetClass()</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
<!-- /#page-content-wrapper -->
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -14,11 +14,14 @@ namespace NightmareCoreWeb2.Pages
|
|||||||
string connStr = $"SslMode=None;server={Program.MysqlServer};user={Program.MysqlUser};database={Program.MysqlDatabase};port={Program.MysqlPort};password={Program.MysqlPassword}";
|
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 UserEmail { get; set; }
|
||||||
public string UserPassword { get; set; }
|
public string UserPassword { get; set; }
|
||||||
public string CharacterListType {get; set;}
|
public string CharacterListType { get; set; }
|
||||||
public string AuthToken { 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<Character> OnlineCharacters = new List<Character>();
|
public List<Character> OnlineCharacters = new List<Character>();
|
||||||
|
public List<GMTicket> Tickets = new List<GMTicket>();
|
||||||
|
|
||||||
private readonly ILogger<AccountModel> _logger;
|
private readonly ILogger<AccountModel> _logger;
|
||||||
|
|
||||||
@ -29,20 +32,51 @@ namespace NightmareCoreWeb2.Pages
|
|||||||
conn = new MySqlConnection(connStr);
|
conn = new MySqlConnection(connStr);
|
||||||
_logger = logger;
|
_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()
|
public void OnGet()
|
||||||
{
|
{
|
||||||
|
|
||||||
ViewData["Title"] = "Login";
|
ViewData["Title"] = "Login";
|
||||||
AuthToken = Request.Cookies["AuthToken"];
|
AuthToken = Request.Cookies["AuthToken"];
|
||||||
Username = Request.Cookies["Username"];
|
Username = Request.Cookies["Username"];
|
||||||
if (!string.IsNullOrEmpty(Username)) {
|
if (!string.IsNullOrEmpty(Username))
|
||||||
|
{
|
||||||
Account a = new Account(Username, conn);
|
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;
|
ViewData["Title"] = a.Username;
|
||||||
CharacterListType = $"{a.Username}'s Characters";
|
CharacterListType = $"{a.Username}'s Characters";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void OnPostLogin()
|
public void OnPostLogin()
|
||||||
{
|
{
|
||||||
UserEmail = Request.Form["UserEmail"];
|
UserEmail = Request.Form["UserEmail"];
|
||||||
@ -59,5 +93,6 @@ namespace NightmareCoreWeb2.Pages
|
|||||||
var hash = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(input));
|
var hash = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||||
return string.Concat(hash.Select(b => b.ToString("x2")));
|
return string.Concat(hash.Select(b => b.ToString("x2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,7 +71,7 @@ namespace NightmareCoreWeb2.Pages
|
|||||||
Account a = new Account(name, conn);
|
Account a = new Account(name, conn);
|
||||||
ViewData["Title"] = name;
|
ViewData["Title"] = name;
|
||||||
CharacterListType = $"{name}'s Characters";
|
CharacterListType = $"{name}'s Characters";
|
||||||
OnlineCharacters = a.characters;
|
OnlineCharacters = a.Characters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPostActivateAccount() {
|
public void OnPostActivateAccount() {
|
||||||
|
|||||||
Reference in New Issue
Block a user