diff --git a/.gitignore b/.gitignore index e640e65..6c31557 100644 --- a/.gitignore +++ b/.gitignore @@ -121,7 +121,7 @@ Temporary Items # ---> VisualStudioCode .vscode/* -!.vscode/settings.json +.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json @@ -130,4 +130,4 @@ Temporary Items config.json bin/* obj/* -vendor \ No newline at end of file +vendor diff --git a/Pages/Account.cshtml b/Pages/Account.cshtml new file mode 100644 index 0000000..611addd --- /dev/null +++ b/Pages/Account.cshtml @@ -0,0 +1,53 @@ +@page +@model NightmareCoreWeb2.Pages.AccountModel +@{ +} +
+ @if (string.IsNullOrEmpty(Model.AuthToken)) { +
+
+
+ + +
+
+ + +
+
+
+ } else { + +
+ + +
+

@Model.CharacterListType

+ + + + + + + + + + + + @foreach (var character in Model.OnlineCharacters) { + + + + + + + + } + +
PlayerCharacterLevelRaceClass
@character.Username@character.Name@character.Level@character.GetRace()@character.GetClass()
+
+
+ + } + +
\ No newline at end of file diff --git a/Pages/Account.cshtml.cs b/Pages/Account.cshtml.cs new file mode 100644 index 0000000..783add7 --- /dev/null +++ b/Pages/Account.cshtml.cs @@ -0,0 +1,63 @@ +using System; +using System.Text; +using System.Linq; +using System.Collections.Generic; +using MySql.Data.MySqlClient; +using System.Security.Cryptography; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Extensions.Logging; + +namespace NightmareCoreWeb2.Pages +{ + public class AccountModel : PageModel + { + 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 AuthToken { get; set; } + public string Username {get; set;} + + public List OnlineCharacters = new List(); + + private readonly ILogger _logger; + + private MySqlConnection conn; + public AccountModel(ILogger logger) + { + + conn = new MySqlConnection(connStr); + _logger = logger; + } + public void OnGet() + { + + ViewData["Title"] = "Login"; + AuthToken = Request.Cookies["AuthToken"]; + Username = Request.Cookies["Username"]; + if (!string.IsNullOrEmpty(Username)) { + Account a = new Account(Username, conn); + OnlineCharacters = a.characters; + + ViewData["Title"] = a.Username; + CharacterListType = $"{a.Username}'s Characters"; + } + } + public void OnPostLogin() + { + UserEmail = Request.Form["UserEmail"]; + UserPassword = Request.Form["UserPassword"]; + Username = UserEmail.Substring(0, UserEmail.IndexOf("@")); + AuthToken = Hash($"{Username.ToUpper()}:{UserPassword.ToUpper()}"); + + Response.Cookies.Append("Username", Username); + Response.Cookies.Append("AuthToken", AuthToken); + } + + static string Hash(string input) + { + var hash = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(input)); + return string.Concat(hash.Select(b => b.ToString("x2"))); + } + } +}