The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
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.

ApplicationUser.cs 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Microsoft.AspNetCore.Identity;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Security.Claims;
  7. using System.Threading.Tasks;
  8. using Teknik.Utilities;
  9. namespace Teknik.IdentityServer.Models
  10. {
  11. public class ApplicationUser : IdentityUser
  12. {
  13. public DateTime CreationDate { get; set; }
  14. public DateTime LastSeen { get; set; }
  15. public AccountType AccountType { get; set; }
  16. public AccountStatus AccountStatus { get; set; }
  17. public string PGPPublicKey { get; set; }
  18. public DateTime LastEdit { get; set; }
  19. public ApplicationUser() : base()
  20. {
  21. Init();
  22. }
  23. public ApplicationUser(string userName) : base(userName)
  24. {
  25. Init();
  26. }
  27. private void Init()
  28. {
  29. CreationDate = DateTime.Now;
  30. LastSeen = DateTime.Now;
  31. LastEdit = DateTime.Now;
  32. AccountType = AccountType.Basic;
  33. AccountStatus = AccountStatus.Active;
  34. PGPPublicKey = null;
  35. }
  36. public List<Claim> ToClaims()
  37. {
  38. var claims = new List<Claim>();
  39. claims.Add(new Claim("username", UserName));
  40. claims.Add(new Claim("creation-date", CreationDate.ToString("o")));
  41. claims.Add(new Claim("last-seen", LastSeen.ToString("o")));
  42. claims.Add(new Claim("last-edit", LastEdit.ToString("o")));
  43. claims.Add(new Claim("account-type", AccountType.ToString()));
  44. claims.Add(new Claim("account-status", AccountStatus.ToString()));
  45. claims.Add(new Claim("recovery-email", Email ?? string.Empty));
  46. claims.Add(new Claim("recovery-verified", EmailConfirmed.ToString()));
  47. claims.Add(new Claim("2fa-enabled", TwoFactorEnabled.ToString()));
  48. claims.Add(new Claim("pgp-public-key", PGPPublicKey ?? string.Empty));
  49. return claims;
  50. }
  51. public JObject ToJson()
  52. {
  53. return new JObject()
  54. {
  55. new JProperty("username", UserName),
  56. new JProperty("creation-date", CreationDate),
  57. new JProperty("last-seen", LastSeen),
  58. new JProperty("last-edit", LastEdit),
  59. new JProperty("account-type", AccountType),
  60. new JProperty("account-status", AccountStatus),
  61. new JProperty("recovery-email", Email),
  62. new JProperty("recovery-verified", EmailConfirmed),
  63. new JProperty("2fa-enabled", TwoFactorEnabled),
  64. new JProperty("pgp-public-key", PGPPublicKey)
  65. };
  66. }
  67. }
  68. }