tesses-cms/Tesses.CMS/UserAccount.cs

119 lines
3.1 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);
2024-07-28 22:59:28 +00:00
Salt = Convert.ToBase64String(bytes);
2023-12-16 01:40:05 +00:00
}
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;}
2024-07-28 22:59:28 +00:00
[JsonProperty("username")]
2023-12-16 01:40:05 +00:00
public string Username {get;set;}="";
[JsonIgnore]
public string PasswordHash {get;set;}="";
[JsonIgnore]
public string Email {get;set;}="";
[JsonIgnore]
public string Salt {get;set;}="";
2024-07-28 22:59:28 +00:00
[JsonProperty("proper_name")]
2023-12-16 01:40:05 +00:00
public string ProperName {get;set;}="";
2024-07-28 22:59:28 +00:00
[JsonProperty("about_me")]
2023-12-16 01:40:05 +00:00
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;}
2024-07-28 22:59:28 +00:00
public bool EnableAlbums {get;set;}
2023-12-16 01:40:05 +00:00
2024-07-28 22:59:28 +00:00
public bool EnableSingles {get;set;}
2023-12-16 01:40:05 +00:00
2024-07-28 22:59:28 +00:00
public bool EnableShows {get;set;}
2023-12-16 01:40:05 +00:00
2024-07-28 22:59:28 +00:00
public bool EnableSoftware {get;set;}
2023-12-16 01:40:05 +00:00
2024-07-28 22:59:28 +00:00
public bool EnableOther {get;set;}
2023-12-16 01:40:05 +00:00
}
2024-07-28 22:59:28 +00:00
public enum WebHookType
{
Ntfy,
Gotify,
Other
}
2023-12-16 01:40:05 +00:00
public class WebHook
{
2024-07-28 22:59:28 +00:00
public string WebhookName {get;set;}="";
public string Username {get;set;}="";
2023-12-16 01:40:05 +00:00
2024-07-28 22:59:28 +00:00
public string Url {get;set;}="";
2023-12-16 01:40:05 +00:00
2024-07-28 22:59:28 +00:00
public string Key {get;set;}="";
public int Priority {get;set;}=2;
public WebHookType Type {get;set;}= WebHookType.Other;
public bool EnabledMovies {get;set;}
2023-12-16 01:40:05 +00:00
public bool EnabledAlbums {get;set;}
2024-07-28 22:59:28 +00:00
public bool EnabledMusicVideos {get;set;}
2023-12-16 01:40:05 +00:00
public bool EnabledShows {get;set;}
public bool EnabledSoftware {get;set;}
public bool EnabledOther {get;set;}
}
}