index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. require_once '../path.php';
  3. require_once "../public/load_lang.php";
  4. require_once "../public/_pdo.php";
  5. require_once "../public/function.php";
  6. if (isset($_GET["op"])) {
  7. $op = $_GET["op"];
  8. } else {
  9. $op = "login";
  10. }
  11. switch ($op) {
  12. case "login":
  13. {
  14. if (isset($_GET["url"])) {
  15. $goto_url = $_GET["url"];
  16. }
  17. break;
  18. }
  19. case "logout":
  20. {
  21. if (isset($_COOKIE["nickname"])) {
  22. $message_comm = $_local->gui->user . " " . $_COOKIE["nickname"] . " " . $_local->gui->loged_out;
  23. }
  24. setcookie("uid", "", time() - 60, "/");
  25. setcookie("username", "", time() - 60, "/");
  26. setcookie("userid", "", time() - 60, "/");
  27. setcookie("nickname", "", time() - 60, "/");
  28. setcookie("email", "", time() - 60, "/");
  29. break;
  30. }
  31. case "new":
  32. {
  33. $host = $_SERVER['HTTP_HOST'];
  34. if (strpos($host, "wikipali.org") !== false) {
  35. echo "网站正处于开发阶段。目前不支持注册。";
  36. exit;
  37. }
  38. break;
  39. }
  40. }
  41. $post_nickname = "";
  42. $post_username = "";
  43. $post_password = "";
  44. $post_email = "";
  45. if (isset($_POST["op"]) && $_POST["op"] == "new") {
  46. $op = "new";
  47. $post_username = $_POST["username"];
  48. $post_password = $_POST["password"];
  49. $post_nickname = $_POST["nickname"];
  50. $post_email = $_POST["email"];
  51. if (empty($post_username)) {
  52. $error_username = $_local->gui->account . $_local->gui->cannot_empty;
  53. }
  54. if (empty($post_password)) {
  55. $error_password = $_local->gui->password . $_local->gui->cannot_empty;
  56. }
  57. if (empty($post_nickname)) {
  58. $error_nickname = $_local->gui->nick_name . $_local->gui->cannot_empty;
  59. }
  60. if (!empty($post_username) && !empty($post_password) && !empty($post_nickname)) {
  61. $md5_password = md5($post_password);
  62. $new_userid = UUID::v4();
  63. PDO_Connect("" . _FILE_DB_USERINFO_);
  64. $query = "select * from user where \"username\"=" . $PDO->quote($post_username);
  65. $Fetch = PDO_FetchAll($query);
  66. $iFetch = count($Fetch);
  67. if ($iFetch > 0) { //username is existed
  68. $error_username = $_local->gui->account_existed;
  69. } else {
  70. $query = "INSERT INTO user ('id','userid','username','password','nickname','email') VALUES (NULL," . $PDO->quote($new_userid) . "," . $PDO->quote($post_username) . "," . $PDO->quote($md5_password) . "," . $PDO->quote($post_nickname) . "," . $PDO->quote($post_email) . ")";
  71. $stmt = @PDO_Execute($query);
  72. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  73. $error = PDO_ErrorInfo();
  74. $error_comm = $error[2] . "抱歉!请再试一次";
  75. } else {
  76. //created user recorder
  77. $newUserPath = _DIR_USER_DOC_ . '/' . $new_userid;
  78. $userDirMyDocument = $newUserPath . _DIR_MYDOCUMENT_;
  79. if (!file_exists($newUserPath)) {
  80. if (mkdir($newUserPath)) {
  81. mkdir($userDirMyDocument);
  82. } else {
  83. $error_comm = "建立用户目录失败,请联络网站管理员。";
  84. }
  85. }
  86. $message_comm = "新账户建立成功";
  87. $op = "login";
  88. unset($_POST["username"]);
  89. }
  90. }
  91. } else {
  92. }
  93. } else {
  94. if (isset($_POST["username"])) {
  95. $_username_ok = true;
  96. if ($_POST["username"] == "") {
  97. $_username_ok = false;
  98. $_post_error = $_local->gui->account . $_local->gui->account_existed;
  99. } else if (isset($_POST["password"])) {
  100. $md5_password = md5($_POST["password"]);
  101. PDO_Connect("" . _FILE_DB_USERINFO_);
  102. $query = "select * from user where (\"username\"=" . $PDO->quote($_POST["username"]) . " or \"email\"=" . $PDO->quote($_POST["username"]) . " ) and \"password\"=" . $PDO->quote($md5_password);
  103. $Fetch = PDO_FetchAll($query);
  104. $iFetch = count($Fetch);
  105. if ($iFetch > 0) { //username is exite
  106. $uid = $Fetch[0]["id"];
  107. $username = $Fetch[0]["username"];
  108. $userid = $Fetch[0]["userid"];
  109. $nickname = $Fetch[0]["nickname"];
  110. $email = $Fetch[0]["email"];
  111. setcookie("uid", $uid, time() + 60 * 60 * 24 * 365, "/");
  112. setcookie("username", $username, time() + 60 * 60 * 24 * 365, "/");
  113. setcookie("userid", $userid, time() + 60 * 60 * 24 * 365, "/");
  114. setcookie("nickname", $nickname, time() + 60 * 60 * 24 * 365, "/");
  115. setcookie("email", $email, time() + 60 * 60 * 24 * 365, "/");
  116. if (isset($_POST["url"])) {
  117. $goto_url = $_POST["url"];
  118. }
  119. if (isset($_COOKIE["url"])) {
  120. setcookie("pwd_set", "on", time() + 60, "/");
  121. }
  122. $newUserPath = _DIR_USER_DOC_ . '/' . $userid . '/';
  123. if (!file_exists($newUserPath)) {
  124. echo "error:cannot find user dir:$newUserPath<br/>";
  125. }
  126. ?>
  127. <!DOCTYPE html>
  128. <html>
  129. <head>
  130. <title>wikipali starting</title>
  131. <?php
  132. if (isset($goto_url)) {
  133. $goto = $goto_url;
  134. } else {
  135. $goto = "../studio/index.php";
  136. }
  137. ?>
  138. <meta http-equiv="refresh" content="0,<?php echo $goto; ?>"/>
  139. </head>
  140. <body>
  141. <br>
  142. <br>
  143. <p align="center"><a href="../studio/index.php">Auto Redirecting to Homepage! IF NOT WORKING, CLICK HERE</a></p>
  144. </body>
  145. </html>
  146. <?php
  147. exit;
  148. } else {
  149. $_post_error = $_local->gui->incorrect_ID_PASS;
  150. }
  151. }
  152. }
  153. }
  154. ?>
  155. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  156. <html>
  157. <head>
  158. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  159. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  160. <link type="text/css" rel="stylesheet" href="../studio/css/font.css"/>
  161. <link type="text/css" rel="stylesheet" href="../studio/css/style.css"/>
  162. <link type="text/css" rel="stylesheet" href="../studio/css/color_day.css" id="colorchange" />
  163. <title>wikipali login</title>
  164. <script src="../public/js/comm.js"></script>
  165. <script src="../studio/js/jquery-3.3.1.min.js"></script>
  166. <script src="../studio/js/fixedsticky.js"></script>
  167. <style>
  168. #login_body{
  169. display: flex;
  170. padding: 2em;
  171. margin: auto;
  172. }
  173. #login_left {
  174. padding-right: 12em;
  175. padding-top: 5em;
  176. }
  177. .title{
  178. font-size: 150%;
  179. margin-top: 1em;
  180. margin-bottom: 0.5em;
  181. }
  182. #login_form{
  183. padding: 2em 0 1em 0;
  184. }
  185. #tool_bar {
  186. padding: 1em;
  187. display: flex;
  188. justify-content: space-between;
  189. }
  190. #login_shortcut {
  191. display: flex;
  192. flex-direction: column;
  193. padding: 2em 0;
  194. }
  195. #login_shortcut button{
  196. height:3em;
  197. }
  198. #button_area{
  199. text-align: right;
  200. padding: 1em 0;
  201. }
  202. .form_help{
  203. font-weight: 400;
  204. color: var(--bookx);
  205. }
  206. .login_form input{
  207. margin-top:2em;
  208. padding:0.5em 0.5em;
  209. }
  210. .login_form select{
  211. margin-top:2em;
  212. padding:0.5em 0.5em;
  213. }
  214. .login_form input[type="submit"]{
  215. margin-top:2em;
  216. padding:0.1em 0.5em;
  217. }
  218. .form_error{
  219. color:var(--error-text);
  220. }
  221. #login_form_div{
  222. width:30em;
  223. }
  224. #ucenter_body {
  225. display: flex;
  226. flex-direction: column;
  227. margin: 0;
  228. padding: 0;
  229. background-color: var(--tool-bg-color3);
  230. color: var(--btn-color);
  231. }
  232. .icon_big {
  233. height: 2em;
  234. width: 2em;
  235. fill: var(--btn-color);
  236. transition: all 0.2s ease;
  237. }
  238. .form_field_name{
  239. position: absolute;
  240. margin-left: 7px;
  241. margin-top: 2em;
  242. color: var(--btn-border-line-color);
  243. -webkit-transition-duration: 0.4s;
  244. -moz-transition-duration: 0.4s;
  245. transition-duration: 0.4s;
  246. transform: translateY(0.5em);
  247. }
  248. .viewswitch_on {
  249. position: absolute;
  250. margin-left: 7px;
  251. margin-top: 1.5em;
  252. color: var(--bookx);
  253. -webkit-transition-duration: 0.4s;
  254. -moz-transition-duration: 0.4s;
  255. transition-duration: 0.4s;
  256. transform: translateY(-15px);
  257. }
  258. </style>
  259. <script>
  260. function login_init(){
  261. $("input").focus(function(){
  262. let name = $(this).attr("name");
  263. var objNave = document.getElementById("tip_"+name);
  264. objNave.className = "viewswitch_on";
  265. });
  266. $(".form_field_name").click(function(){
  267. let id = $(this).attr("id");
  268. var objNave = document.getElementById(id);
  269. objNave.className = "viewswitch_on";
  270. let arrId=id.split("_");
  271. document.getElementById('input_'+arrId[1]).focus();
  272. });
  273. }
  274. </script>
  275. <link type="text/css" rel="stylesheet" href="mobile.css" media="screen and (max-width:800px)">
  276. </head>
  277. <body id="ucenter_body" onload="login_init()">
  278. <div id="tool_bar">
  279. <div>
  280. </div>
  281. <div>
  282. <?php
  283. require_once '../lang/lang.php';
  284. ?>
  285. </div>
  286. </div>
  287. <div id="login_body" >
  288. <div id="login_left">
  289. <div >
  290. <svg style="height: 8em;width: 25em;">
  291. <use xlink:href="../public/images/svg/wikipali_login_page.svg#logo_login"></use>
  292. </svg>
  293. </div>
  294. <div style=" padding: 1em 0 0 3.5em;font-weight: 400;">
  295. <?php echo $_local->gui->pali_literature_platform; ?>
  296. <ul style="padding-left: 1.2em;">
  297. <li><?php echo $_local->gui->online_dict_db; ?></li>
  298. <li><?php echo $_local->gui->user_data_share; ?></li>
  299. <li><?php echo $_local->gui->cooperate_edit; ?></li>
  300. </ul>
  301. </div>
  302. </div>
  303. <div id="login_right">
  304. <div id = "login_form_div" class="fun_block" >
  305. <?php
  306. $host = $_SERVER['HTTP_HOST'];
  307. if (strpos($host, "wikipali.org") !== false) {
  308. echo "网站正处于开发阶段。目前不支持注册。";
  309. }
  310. if (isset($error_comm)) {
  311. echo '<div class="form_error">';
  312. echo $error_comm;
  313. echo '</div>';
  314. }
  315. if (isset($message_comm)) {
  316. echo '<div class="form_help">';
  317. echo $message_comm;
  318. echo '</div>';
  319. }
  320. if ($op == "new") {
  321. ?>
  322. <div class="title">
  323. <?php echo $_local->gui->join_wikipali; ?>
  324. </div>
  325. <div class="login_new">
  326. <span class="form_help"><?php echo $_local->gui->have_account; ?> ?</span><a href="index.php?language=<?php echo $currLanguage; ?>">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_local->gui->login; //登入账户 ?></a>
  327. </div>
  328. <div class="login_form" style=" padding: 3em 0 3em 0;">
  329. <form action="index.php" method="post">
  330. <div>
  331. <div>
  332. <span id='tip_nickname' class='form_field_name'><?php echo $_local->gui->nick_name; ?></span>
  333. <input type="input" name="nickname" value="<?php echo $nickname; ?>" />
  334. </div>
  335. <div class="form_help">
  336. <?php echo $_local->gui->name_for_show; ?>
  337. </div>
  338. <div id="error_nickname" class="form_error">
  339. <?php
  340. if (isset($error_nickname)) {echo $error_nickname;}
  341. ?>
  342. </div>
  343. <div>
  344. <select name="language" style="width: 100%;">
  345. <option><?php echo $_local->language->en; ?></option>
  346. <option><?php echo $_local->language->zh_cn; ?></option>
  347. <option><?php echo $_local->language->zh_tw; ?></option>
  348. <option><?php echo $_local->language->my; ?></option>
  349. <option><?php echo $_local->language->si; ?></option>
  350. </select>
  351. </div>
  352. <div>
  353. <span id='tip_email' class='form_field_name'><?php echo $_local->gui->email_address; ?></span>
  354. <input type="input" name="email" value="<?php echo $post_email; ?>" />
  355. </div>
  356. <div>
  357. <span id='tip_username' class='form_field_name'><?php echo $_local->gui->account; ?></span>
  358. <input type="input" name="username" value="<?php echo $post_username; ?>" />
  359. </div>
  360. <div id="error_username" class="form_error">
  361. <?php
  362. if (isset($error_username)) {echo $error_username;}
  363. ?>
  364. </div>
  365. <div class="form_help">
  366. <?php echo $_local->gui->account_demond; ?>
  367. </div>
  368. <div>
  369. <span id='tip_password' class='form_field_name'><?php echo $_local->gui->password; ?></span>
  370. <input type="password" name="password" value="<?php echo $post_password; ?>" />
  371. <input type="password" name="repassword" value="<?php echo $post_password; ?>" />
  372. </div>
  373. <div class="form_help">
  374. <?php echo $_local->gui->password_demond; ?>
  375. </div>
  376. <div id="error_password" class="form_error">
  377. <?php
  378. if (isset($error_password)) {echo $error_password;}
  379. ?>
  380. </div>
  381. <input type="hidden" name="op" value="new" />
  382. </div>
  383. <div id="button_area">
  384. <input type="submit" value="<?php echo $_local->gui->continue; ?>" style="background-color: var(--link-hover-color);border-color: var(--link-hover-color);" />
  385. </div>
  386. </form>
  387. </div>
  388. <?php
  389. } else {
  390. ?>
  391. <div class="title">
  392. <?php
  393. if (isset($_POST["username"]) && $_username_ok == true) {
  394. echo $_POST["username"];
  395. } else {
  396. echo $_local->gui->login;
  397. }
  398. ?>
  399. </div>
  400. <div class="login_new">
  401. <?php
  402. if (isset($_POST["username"]) && $_username_ok == true) {
  403. echo '<a href="index.php?language=' . $currLanguage . '">切换账户</a>';
  404. } else {
  405. echo '<span class="form_help">' . $_local->gui->new_to_wikipali . ' ?</span><a href="index.php?language=' . $currLanguage . '&op=new">&nbsp;&nbsp;&nbsp;&nbsp;' . $_local->gui->create_account . '</a>';
  406. }
  407. ?>
  408. <div class="login_form" style="padding: 3em 0 3em 0;">
  409. <form action="index.php" method="post">
  410. <div>
  411. <?php
  412. if (isset($goto_url)) {
  413. echo "<input type=\"hidden\" name=\"url\" value=\"{$goto_url}\" />";
  414. } else if (isset($_POST["url"])) {
  415. echo "<input type=\"hidden\" name=\"url\" value=\"{$_POST["url"]}\" />";
  416. }
  417. if (isset($_POST["username"]) && $_username_ok == true) {
  418. echo "<span id='tip_password' class='form_field_name'>" . $_local->gui->password . "</span>";
  419. echo '<input type="password" name="password" />';
  420. echo "<input type=\"hidden\" name=\"username\" value=\"{$_POST["username"]}\" />";
  421. if (isset($_post_error)) {
  422. echo '<div id="error_nikename" class="form_error">';
  423. echo $_post_error;
  424. echo '</div>';
  425. }
  426. } else {
  427. echo "<span id='tip_username' class='form_field_name'>" . $_local->gui->account . "/" . $_local->gui->e_mail . "</span>";
  428. echo '<input type="input" name="username" id="input_username" />';
  429. if (isset($_post_error)) {
  430. echo '<div id="error_nikename" class="form_error">';
  431. echo $_post_error;
  432. echo '</div>';
  433. }
  434. }
  435. ?>
  436. </div>
  437. <div id="button_area">
  438. <input type="submit" value="<?php echo $_local->gui->continue; ?>" style="background-color: var(--link-hover-color);border-color: var(--link-hover-color);" />
  439. </div>
  440. </form>
  441. </div>
  442. <div id="login_shortcut">
  443. <button class="form_help"><?php echo $_local->gui->login_with_google; ?>&nbsp;
  444. <svg class="icon">
  445. <use xlink:href="../studio/svg/icon.svg#google_logo"></use>
  446. </svg>
  447. </button>
  448. <button class="form_help"><?php echo $_local->gui->login_with_facebook; ?>&nbsp;
  449. <svg class="icon">
  450. <use xlink:href="../studio/svg/icon.svg#facebook_logo"></use>
  451. </svg>
  452. </button>
  453. <button class="form_help"><?php echo $_local->gui->login_with_wechat; ?>&nbsp;
  454. <svg class="icon">
  455. <use xlink:href="../studio/svg/icon.svg#wechat_logo"></use>
  456. </svg>
  457. </button>
  458. </div>
  459. <?php
  460. }
  461. ?>
  462. </div>
  463. </div>
  464. </div>
  465. <script>
  466. login_init();
  467. </script>
  468. </body>
  469. </html>