/dnt_3_5_2_0322/Discuz.Web/admin/global/global_passportsetting.aspx.cs

https://github.com/Natsuwind/DeepInSummer · C# · 150 lines · 142 code · 8 blank · 0 comment · 35 complexity · 87350e937330800e5a977fba596fa37b MD5 · raw file

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.HtmlControls;
  10. using Discuz.Forum;
  11. using Discuz.Common;
  12. using Discuz.Config;
  13. namespace Discuz.Web.Admin
  14. {
  15. public partial class global_passportsetting : AdminPage
  16. {
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. applicationtype.Items[0].Attributes.Add("onclick", "$('showurl').style.display='';");
  20. applicationtype.Items[1].Attributes.Add("onclick", "$('showurl').style.display='none';");
  21. asyncmode.Items[0].Attributes.Add("onclick", "$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='none';");
  22. asyncmode.Items[1].Attributes.Add("onclick", "$('tr_asyncurl').style.display='none';$('tr_asynclist').style.display='none';");
  23. asyncmode.Items[2].Attributes.Add("onclick", "$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='';");
  24. if (!IsPostBack)
  25. {
  26. string apikey = DNTRequest.GetString("apikey");
  27. if (apikey != "")
  28. {
  29. APIConfigInfo aci = APIConfigs.GetConfig();
  30. foreach (ApplicationInfo ai in aci.AppCollection)
  31. {
  32. if (ai.APIKey == apikey)
  33. {
  34. appname.Text = ai.AppName;
  35. applicationtype.SelectedValue = ai.ApplicationType.ToString();
  36. if (applicationtype.SelectedIndex == 1)
  37. {
  38. base.RegisterStartupScript("applicationtype", "<script>$('showurl').style.display='none';</script>");
  39. }
  40. appurl.Text = ai.AppUrl;
  41. callbackurl.Text = ai.CallbackUrl;
  42. ipaddresses.Text = ai.IPAddresses;
  43. asyncmode.SelectedValue = ai.SyncMode.ToString();
  44. if (asyncmode.SelectedIndex == 1)
  45. {
  46. base.RegisterStartupScript("asyncmode", "<script>$('tr_asyncurl').style.display='none';$('tr_asynclist').style.display='none';</script>");
  47. }
  48. if (asyncmode.SelectedIndex == 2)
  49. {
  50. base.RegisterStartupScript("asyncmode", "<script>$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='';</script>");
  51. }
  52. asyncurl.Text = ai.SyncUrl;
  53. asynclist.Text = ai.SyncList;
  54. break;
  55. }
  56. }
  57. }
  58. apikeyhidd.Value = apikey;
  59. }
  60. }
  61. protected void savepassportinfo_Click(object sender, EventArgs e)
  62. {
  63. if (appname.Text.Trim() == "")
  64. {
  65. base.RegisterStartupScript("PAGE", "alert('ÕûºÏ³ÌÐòÃû³Æ²»ÄÜΪ¿Õ!');");
  66. return;
  67. }
  68. if (applicationtype.SelectedValue != "2")
  69. {
  70. if (appurl.Text.Trim() == "")
  71. {
  72. base.RegisterStartupScript("PAGE", "alert('ÕûºÏ³ÌÐò Url µØÖ·²»ÄÜΪ¿Õ!');");
  73. return;
  74. }
  75. if (applicationtype.SelectedValue == "1" && callbackurl.Text.Trim() == "")
  76. {
  77. base.RegisterStartupScript("PAGE", "alert('µÇ¼Íê³Éºó·µ»ØµØÖ·²»ÄÜΪ¿Õ!');");
  78. return;
  79. }
  80. }
  81. if (ipaddresses.Text.Trim() != "")
  82. {
  83. foreach (string ip in ipaddresses.Text.Replace("\r\n", "").Replace(" ", "").Split(','))
  84. {
  85. if (!Utils.IsIP(ip))
  86. {
  87. base.RegisterStartupScript("PAGE", "alert('IPµØÖ·¸ñʽ´íÎó!');");
  88. return;
  89. }
  90. }
  91. }
  92. if (apikeyhidd.Value == "") //Ôö¼Ó
  93. {
  94. ApplicationInfo ai = new ApplicationInfo();
  95. ai.AppName = appname.Text;
  96. ai.AppUrl = appurl.Text;
  97. ai.APIKey = Utils.MD5(System.Guid.NewGuid().ToString());
  98. ai.Secret = Utils.MD5(System.Guid.NewGuid().ToString());
  99. ai.ApplicationType = Convert.ToInt32(applicationtype.SelectedValue);
  100. if (ai.ApplicationType == 1)
  101. ai.CallbackUrl = callbackurl.Text;
  102. else
  103. ai.CallbackUrl = "";
  104. ai.CallbackUrl = callbackurl.Text;
  105. ai.IPAddresses = ipaddresses.Text.Replace("\r\n", "").Replace(" ", "");
  106. ai.SyncMode = Convert.ToInt32(asyncmode.SelectedValue);
  107. ai.SyncUrl = asyncurl.Text;
  108. ai.SyncList = asynclist.Text;
  109. APIConfigInfo aci = APIConfigs.GetConfig();
  110. if (aci.AppCollection == null)
  111. aci.AppCollection = new ApplicationInfoCollection();
  112. aci.AppCollection.Add(ai);
  113. APIConfigs.SaveConfig(aci);
  114. }
  115. else //ÐÞ¸Ä
  116. {
  117. APIConfigInfo aci = APIConfigs.GetConfig();
  118. foreach (ApplicationInfo ai in aci.AppCollection)
  119. {
  120. if (ai.APIKey == apikeyhidd.Value)
  121. {
  122. ai.AppName = appname.Text;
  123. ai.AppUrl = appurl.Text;
  124. ai.ApplicationType = Convert.ToInt32(applicationtype.SelectedValue);
  125. if (ai.ApplicationType == 1)
  126. ai.CallbackUrl = callbackurl.Text;
  127. else
  128. ai.CallbackUrl = "";
  129. ai.CallbackUrl = callbackurl.Text;
  130. ai.IPAddresses = ipaddresses.Text.Replace("\r\n", "").Replace(" ", "");
  131. ai.SyncMode = Convert.ToInt32(asyncmode.SelectedValue);
  132. ai.SyncUrl = asyncurl.Text;
  133. ai.SyncList = asynclist.Text;
  134. break;
  135. }
  136. }
  137. APIConfigs.SaveConfig(aci);
  138. }
  139. Response.Redirect("global_passportmanage.aspx");
  140. }
  141. }
  142. }