纽威
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.

51 lines
1.7 KiB

3 years ago
  1. using System;
  2. namespace NFine.Code
  3. {
  4. public class OperatorProvider
  5. {
  6. public static OperatorProvider Provider
  7. {
  8. get { return new OperatorProvider(); }
  9. }
  10. private string LoginUserKey = "nfine_loginuserkey_2016";
  11. private string LoginProvider = Configs.GetValue("LoginProvider");
  12. public OperatorModel GetCurrent()
  13. {
  14. OperatorModel operatorModel = new OperatorModel();
  15. if (LoginProvider == "Cookie")
  16. {
  17. operatorModel = DESEncrypt.Decrypt(WebHelper.GetCookie(LoginUserKey).ToString()).ToObject<OperatorModel>();
  18. }
  19. else
  20. {
  21. operatorModel = DESEncrypt.Decrypt(WebHelper.GetSession(LoginUserKey).ToString()).ToObject<OperatorModel>();
  22. }
  23. return operatorModel;
  24. }
  25. public void AddCurrent(OperatorModel operatorModel)
  26. {
  27. if (LoginProvider == "Cookie")
  28. {
  29. WebHelper.WriteCookie(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson()), 60);
  30. }
  31. else
  32. {
  33. WebHelper.WriteSession(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson()));
  34. }
  35. WebHelper.WriteCookie("nfine_mac", Md5.md5(Net.GetMacByNetworkInterface().ToJson(), 32));
  36. WebHelper.WriteCookie("nfine_licence", Licence.GetLicence());
  37. }
  38. public void RemoveCurrent()
  39. {
  40. if (LoginProvider == "Cookie")
  41. {
  42. WebHelper.RemoveCookie(LoginUserKey.Trim());
  43. }
  44. else
  45. {
  46. WebHelper.RemoveSession(LoginUserKey.Trim());
  47. }
  48. }
  49. }
  50. }