CommonHandler.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace LYFZ.WeixinServers.WeiXinAPP
  6. {
  7. public class CommonHandler
  8. {
  9. public CommonHandler() {
  10. }
  11. public static LYFZ.WeixinServiceDate.Model.Model_AdminUser GetAdminUser(System.Web.UI.Page page)
  12. {
  13. LYFZ.WeixinServiceDate.Model.Model_AdminUser retModel = new WeixinServiceDate.Model.Model_AdminUser();
  14. if (CheckLogin(page))
  15. {
  16. retModel = (LYFZ.WeixinServiceDate.Model.Model_AdminUser)page.Session["Login"];
  17. }
  18. else {
  19. retModel.ID = -1;
  20. retModel.UserName = "未登录";
  21. }
  22. return retModel;
  23. }
  24. /// <summary>
  25. /// 检查当前帐号是否有操作DZKJ的权限
  26. /// </summary>
  27. /// <param name="page"></param>
  28. /// <param name="isJump">在没有权限时是否跳转到首页</param>
  29. /// <returns></returns>
  30. public static bool CheckAdmin(System.Web.UI.Page page, bool isJump=true)
  31. {
  32. bool ret = false;
  33. int Competence=GetAdminUser(page).Competence;
  34. if ( isAdmin(page, false) || (page.Request.Url.ToString().ToLower().Contains("/DZKJ_".ToLower()) && (Competence == 1 || Competence == 2)))
  35. {
  36. ret = true;
  37. }
  38. else {
  39. if (isJump)
  40. {
  41. page.Response.Write("<script>alert('对不起,你没有此操作权限。');document.location='/WeiXinAPP/index.aspx';</script>");
  42. }
  43. }
  44. return ret;
  45. }
  46. /// <summary>
  47. /// 检查当前帐号是否为超级管理员
  48. /// </summary>
  49. /// <param name="page"></param>
  50. /// <param name="isJump">在没有权限时是否跳转到首页</param>
  51. /// <returns></returns>
  52. public static bool isAdmin(System.Web.UI.Page page, bool isJump=true)
  53. {
  54. bool ret = false;
  55. int Competence = GetAdminUser(page).Competence;
  56. if (Competence == 99)
  57. {
  58. ret = true;
  59. }
  60. else {
  61. if (isJump)
  62. {
  63. page.Response.Write("<script>alert('对不起,你没有此操作权限。');document.location='/WeiXinAPP/index.aspx';</script>");
  64. }
  65. }
  66. return ret;
  67. }
  68. /// <summary>
  69. /// 退出登录
  70. /// </summary>
  71. /// <param name="page"></param>
  72. public static void Logout(System.Web.UI.Page page)
  73. {
  74. LYFZ.Command.Command_Session.Del("Login");
  75. page.Response.Write("<script>document.location='/WeiXinAPP/Login.aspx';</script>"); return;
  76. }
  77. /// <summary>
  78. /// 检查是否已登录,如果没有登录就跳转到登录页
  79. /// </summary>
  80. /// <param name="page"></param>
  81. public static void CheckLoginJump(System.Web.UI.Page page)
  82. {
  83. if (!CheckLogin(page))
  84. {
  85. page.Response.Write("<script>alert('你还没有登录或已超时,请重新登录!');document.location='/WeiXinAPP/Login.aspx';</script>"); return;
  86. }
  87. }
  88. /// <summary>
  89. /// 检查是否已登录
  90. /// </summary>
  91. /// <param name="page"></param>
  92. public static bool CheckLogin(System.Web.UI.Page page)
  93. {
  94. if (page.Session["Login"] == null)
  95. {
  96. return false;
  97. }
  98. else
  99. {
  100. LYFZ.Command.Command_Session.AddObject("Login", page.Session["Login"],300);
  101. return true;
  102. }
  103. }
  104. public static string I18NAccountType(int TypeFlag){
  105. switch (TypeFlag)
  106. {
  107. case 0: return "普通用户";
  108. case 1: return "点赞科技管理员";
  109. case 2: return "点赞科技分销商";
  110. case 99: return "超级管理员";
  111. default: return "参数错误";
  112. }
  113. }
  114. }
  115. }