index.php 13 KB

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