index.php 16 KB

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