Advertisement
kinginako

index.js

Jan 13th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. var LoginTimes = 0;
  2. var LoginErrorCode = 0;
  3.  
  4. $(document).ready(function() {
  5. var list = LoginError.split(":");
  6. if (list.length == 2)
  7. {
  8. LoginTimes = list[0];
  9. LoginErrorCode = list[1];
  10. }
  11.  
  12. SetErrInfo(0, "");
  13. $('#login_button').click(function() {
  14. SubmitForm(0);
  15. });
  16.  
  17. $('#login_cancel_button').click(function() {
  18. onCancel();
  19. });
  20.  
  21. $('#Language').change(function() {
  22. ChangeLanguage();
  23. });
  24.  
  25. LoadFrame();
  26. });
  27. var inittime = 0;
  28. var initcount = 0;
  29. var strCookie = document.cookie;
  30. var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  31. var base64DecodeChars = new Array(
  32. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  33. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  34. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
  35. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
  36. -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  37. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
  38. -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  39. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
  40.  
  41. function base64encode(str) {
  42. var out, i, len;
  43. var c1, c2, c3;
  44.  
  45. len = str.length;
  46. i = 0;
  47. out = "";
  48. while(i < len) {
  49. c1 = str.charCodeAt(i++) & 0xff;
  50. if(i == len)
  51. {
  52. out += base64EncodeChars.charAt(c1 >> 2);
  53. out += base64EncodeChars.charAt((c1 & 0x3) << 4);
  54. out += "==";
  55. break;
  56. }
  57. c2 = str.charCodeAt(i++);
  58. if(i == len)
  59. {
  60. out += base64EncodeChars.charAt(c1 >> 2);
  61. out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  62. out += base64EncodeChars.charAt((c2 & 0xF) << 2);
  63. out += "=";
  64. break;
  65. }
  66. c3 = str.charCodeAt(i++);
  67. out += base64EncodeChars.charAt(c1 >> 2);
  68. out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  69. out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
  70. out += base64EncodeChars.charAt(c3 & 0x3F);
  71. }
  72. return out;
  73. }
  74.  
  75. function base64decode(str) {
  76. var c1, c2, c3, c4;
  77. var i, len, out;
  78.  
  79. len = str.length;
  80. i = 0;
  81. out = "";
  82. while(i < len) {
  83. /* c1 */
  84. do {
  85. c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  86. } while(i < len && c1 == -1);
  87. if(c1 == -1)
  88. break;
  89.  
  90. /* c2 */
  91. do {
  92. c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  93. } while(i < len && c2 == -1);
  94. if(c2 == -1)
  95. break;
  96.  
  97. out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
  98.  
  99. /* c3 */
  100. do {
  101. c3 = str.charCodeAt(i++) & 0xff;
  102. if(c3 == 61)
  103. return out;
  104. c3 = base64DecodeChars[c3];
  105. } while(i < len && c3 == -1);
  106. if(c3 == -1)
  107. break;
  108.  
  109. out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
  110.  
  111. /* c4 */
  112. do {
  113. c4 = str.charCodeAt(i++) & 0xff;
  114. if(c4 == 61)
  115. return out;
  116. c4 = base64DecodeChars[c4];
  117. } while(i < len && c4 == -1);
  118. if(c4 == -1)
  119. break;
  120. out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
  121. }
  122. return out;
  123. }
  124.  
  125. function SubmitForm(type)
  126. {
  127. var username = $("#txt_Username").val();
  128.  
  129. var password = $("#txt_Password").val();
  130.  
  131. if ((username == null) || (password == null) ||
  132. (password.trim() == "") || (username.trim() == ""))
  133. {
  134. SetErrInfo(1, login_hint_err1);
  135. if (type)
  136. return false;
  137. else
  138. return;
  139. }
  140.  
  141. var date = new Date();
  142. date.setTime(date.getTime()+(365*24*60*60*1000));
  143. var expires = "; expires="+date.toGMTString();
  144. var lantype = getSelectVal('Language');
  145. var cookie = "Language="+lantype+ expires + "; path=/";
  146. document.cookie = cookie;
  147.  
  148. var form = new WebSubmitForm();
  149. form.setAction('/index/login.cgi');
  150. form.addParameter('Username', username);
  151. form.addParameter('Password', MyRSAEncryptB64(password));
  152. form.submit();
  153. $("#login_button").unbind("click");
  154. $("#login_cancel_button").unbind("click");
  155. disableAllButtons();
  156. if (type)
  157. return true;
  158. }
  159.  
  160. function LoadFrame()
  161. {
  162. $("#txt_Username").focus();
  163. if ((LoginErrorCode > 0)
  164. && (LoginErrorCode < gPubErrStrArray.length)
  165. && (LoginErrorCode != 3)
  166. && (LoginErrorCode != '0'))
  167. {
  168. SetErrInfo(1, gPubErrStrArray[LoginErrorCode]);
  169. }
  170. }
  171.  
  172. function onCancel()
  173. {
  174. $("#txt_Username").attr('value','');
  175. $("#txt_Password").attr('value','');
  176. $("#txt_Username").focus();
  177. }
  178.  
  179. function onHandleKeyDown(e)
  180. {
  181. var key = 0;
  182.  
  183. if (window.event)
  184. key = window.event.keyCode;
  185. else if (e)
  186. key = e.which ;
  187.  
  188. if (key == 13)
  189. {
  190. return SubmitForm(1);
  191. }
  192. return true;
  193. }
  194.  
  195. function ChangeLanguage()
  196. {
  197. var date = new Date();
  198. date.setTime(date.getTime()+(365*24*60*60*1000));
  199. var expires = "; expires="+date.toGMTString();
  200. var lantype = getSelectVal('Language');
  201. var cookie = "Language="+lantype + expires + "; path=/";
  202. document.cookie = cookie;
  203. window.location.reload();
  204. }
  205.  
  206. function SetErrInfo(type, str)
  207. {
  208. var extraStr = '';
  209. var innerHTML= '';
  210. var imgHtml = '';
  211. if (type > 0)
  212. {
  213. extraStr = str + ' ';
  214. if (0 == LoginTimes)
  215. {
  216. $("#erroinfoId").html(str);
  217. return;
  218. }
  219. }
  220.  
  221. if(Cookieflag == 1)
  222. {
  223. $("#erroinfoId").html(login_hint_err2);
  224. }
  225. else if (Cookieflag == 2)
  226. {
  227. $("#erroinfoId").html(login_hint_err3);
  228. }
  229. else if (LoginTimes == 0)
  230. {
  231. $("#erroinfoId").html(login_hint_err4);
  232. }
  233. else if (LoginTimes == 1)
  234. {
  235. $("#erroinfoId").html(extraStr+login_hint_err8);
  236. }
  237. else if (LoginTimes == 2)
  238. {
  239. $("#erroinfoId").html(extraStr+login_hint_err9);
  240. }
  241. else if (LoginTimes >= 3)
  242. {
  243. $("#erroinfoId").html(extraStr+login_hint_err10);
  244. }
  245. }
  246.  
  247. document.onkeypress = onHandleKeyDown;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement