2
0

index.php 16 KB

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