index.php 13 KB

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