index.php 14 KB

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