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

50 lines
1.7 KiB

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