tesses-cms/Tesses.CMS/UserAccount.cs

107 lines
2.7 KiB
C#
Raw Normal View History

2023-12-16 01:40:05 +00:00
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;
namespace Tesses.CMS
{
public class UserAccount
{
[JsonIgnore]
public bool IsVerified {get;set;}=false;
[JsonIgnore]
public bool IsInvited {get;set;}=false;
[JsonIgnore]
public bool IsAdmin {get;set;}=false;
public void NewSalt()
{
byte[] bytes=new byte[32];
using(var rnd = RandomNumberGenerator.Create())
rnd.GetBytes(bytes);
}
public string GetPasswordHash(string password)
{
string pass = $"{password}{Salt}";
using(var sha256Managed = SHA256Managed.Create())
{
return Convert.ToBase64String(sha256Managed.ComputeHash(Encoding.UTF8.GetBytes(pass)));
}
}
public bool PasswordCorrect(string password)
{
string hash=GetPasswordHash(password);
return PasswordHash == hash ;
}
[JsonIgnore]
public long Id {get;set;}
public string Username {get;set;}="";
[JsonIgnore]
public string PasswordHash {get;set;}="";
[JsonIgnore]
public string Email {get;set;}="";
[JsonIgnore]
public string Salt {get;set;}="";
public string ProperName {get;set;}="";
public string AboutMe {get;set;}="";
[JsonIgnore]
public List<MailEntry> AccountsToMail {get;set;}=new List<MailEntry> ();
[JsonIgnore]
public List<WebHook> Webhooks {get;set;}=new List<WebHook>();
public object Scriban()
{
return new {
Username = System.Web.HttpUtility.HtmlEncode(Username),
Proper = System.Web.HttpUtility.HtmlEncode(ProperName),
About = System.Web.HttpUtility.HtmlEncode(AboutMe)
};
}
}
public class MailEntry
{
public long UserId {get;set;}
2024-01-04 02:53:13 +00:00
public bool EnableUpdates {get;set;}
2023-12-16 01:40:05 +00:00
public bool EnableMovies {get;set;}
public bool EnabledAlbums {get;set;}
public bool EnabledSingles {get;set;}
public bool EnabledShows {get;set;}
public bool EnabledSoftware {get;set;}
public bool EnabledOther {get;set;}
}
public class WebHook
{
public long UserId {get;set;}
public string Url {get;set;}
public bool EnableMovies {get;set;}
public bool EnabledAlbums {get;set;}
public bool EnabledSingles {get;set;}
public bool EnabledShows {get;set;}
public bool EnabledSoftware {get;set;}
public bool EnabledOther {get;set;}
}
}