Account progress
This commit is contained in:
61
Account.cs
61
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<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)
|
||||
{
|
||||
@ -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<Character>();
|
||||
this.Characters = new List<Character>();
|
||||
while (rdr.Read())
|
||||
{
|
||||
try
|
||||
@ -51,7 +78,7 @@ 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)
|
||||
{
|
||||
@ -59,7 +86,35 @@ public class Account
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
public class AccountAccess
|
||||
{
|
||||
public int SecurityLevel { get; set; }
|
||||
public int RealmID { get; set; }
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="json.net" Version="1.0.33" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.26" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
@{
|
||||
}
|
||||
<div class="container">
|
||||
@if (string.IsNullOrEmpty(Model.AuthToken)) {
|
||||
@if (string.IsNullOrEmpty(Model.AuthToken))
|
||||
{
|
||||
<div id="LoginForm">
|
||||
<form action="?handler=Login" method="post" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
@ -16,37 +17,76 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
} else {
|
||||
}
|
||||
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 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>
|
||||
</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>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
}
|
||||
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 -->
|
||||
}
|
||||
|
||||
|
||||
@ -17,8 +17,11 @@ namespace NightmareCoreWeb2.Pages
|
||||
public string CharacterListType { get; set; }
|
||||
public string AuthToken { 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<GMTicket> Tickets = new List<GMTicket>();
|
||||
|
||||
private readonly ILogger<AccountModel> _logger;
|
||||
|
||||
@ -29,20 +32,51 @@ namespace NightmareCoreWeb2.Pages
|
||||
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")));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user