ASP.NET Razor website for https://wotdn.nightmare.haus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.4 KiB

3 years ago
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
{
public string UserEmail { get; set; }
3 years ago
public string UserPassword { get; set; }
3 years ago
public string CharacterListType { get; set; }
3 years ago
public string AuthToken { get; set; }
3 years ago
public string Username { get; set; }
public bool IsGM { get; set; }
public Account UserAccount { get; set; }
3 years ago
public List<Character> OnlineCharacters = new List<Character>();
3 years ago
public List<GMTicket> Tickets = new List<GMTicket>();
3 years ago
private readonly ILogger<AccountModel> _logger;
private MySqlConnection conn;
public AccountModel(ILogger<AccountModel> logger)
{
3 years ago
conn = new MySqlConnection(Program.connStr);
3 years ago
_logger = logger;
}
3 years ago
public void OnGetAccount(string name)
{
Account a = new Account(name);
AuthToken = "OK";
3 years ago
UserAccount = a;
OnlineCharacters = a.Characters;
foreach (var access in a.Access)
{
if (access.RealmID == -1 && access.SecurityLevel >= 1)
3 years ago
{
this.IsGM = true;
this.Tickets = GMTicket.GetAllTickets();
3 years ago
}
}
ViewData["Title"] = a.Username;
CharacterListType = $"{a.Username}'s Characters";
}
public void OnGetCharacterAction(int guid, int action)
{
Character c = new Character(guid);
if ((c.AtLogin & Character.AtLoginOptions.AT_LOGIN_FIRST) == 0)
{
c.AtLogin |= (Character.AtLoginOptions)action;
}
c.SetAtLogin();
}
3 years ago
public void OnGet()
{
ViewData["Title"] = "Login";
AuthToken = Request.Cookies["AuthToken"];
Username = Request.Cookies["Username"];
3 years ago
if (!string.IsNullOrEmpty(Username))
{
Account a = new Account(Username);
3 years ago
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();
3 years ago
}
}
3 years ago
ViewData["Title"] = a.Username;
CharacterListType = $"{a.Username}'s Characters";
3 years ago
}
3 years ago
}
3 years ago
3 years ago
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")));
}
3 years ago
3 years ago
}
}