Просмотр исходного кода

Merge pull request #506 from visuddhinanda/master

支持邀请码注册
visuddhinanda 4 лет назад
Родитель
Сommit
985607eca4

+ 4 - 0
app/api/user.php

@@ -34,6 +34,10 @@ switch ($_REQUEST["_method"]) {
 		# get
 		$model->reset_password_send_email();
 		break;	
+	case 'reset_pwd':
+		# get
+		$model->reset_password();
+		break;	
 	default:
 		# code...
 		break;

+ 5 - 0
app/article/index.php

@@ -133,6 +133,11 @@ span.fancytree-node{
     width: max-content;
 }
 
+#content_toc>ul>li>span.fancytree-node{
+	font-size: 120%;
+    font-weight: 900;
+}
+
 </style>
 
 <?php

+ 88 - 0
app/db/channel.php

@@ -0,0 +1,88 @@
+<?php
+require_once "../path.php";
+require_once "../db/table.php";
+require_once "../public/function.php";
+/*
+CREATE TABLE likes (
+    id            INTEGER      PRIMARY KEY AUTOINCREMENT,
+    like_type     VARCHAR (16) NOT NULL,
+    resource_type VARCHAR (32) NOT NULL,
+    resource_id   CHAR (36)    NOT NULL,
+    user_id       INTEGER      NOT NULL,
+    created_at    TIMESTAMP DEFAULT CURRENT_TIMESTAMP     NOT NULL //只做初始化,更新时不自动更新
+);
+*/
+class Channel extends Table
+{
+    function __construct($redis=false) {
+		parent::__construct(_FILE_DB_CHANNAL_, "channal", "", "",$redis);
+    }
+
+	public function  index(){
+		switch ($_GET["view"]) {
+			case 'studio':
+				# code...
+				break;
+			case 'user':
+				# code...
+				break;
+			default:
+				# code...
+				break;
+		}
+		$where["like_type"] = "like";
+		$where["resource_type"] = $_GET["type"];
+		$where["resource_id"] = explode($_GET["id"],",");
+		echo json_encode($this->_index(["id","name","lang","status"],$where), JSON_UNESCAPED_UNICODE);
+	}
+
+	public function create($data=null){
+		if($data===null){
+			if(!isset($_COOKIE["userid"])){
+				return;
+			}
+			$json = file_get_contents('php://input');
+			$data = json_decode($json,true);
+			$data["owner"] = $_COOKIE["userid"];			
+		}
+
+		$isExist = $this->medoo->has($this->table,["owner"=>$data["owner"],"name"=>$data["name"]]);
+		if(!$isExist){
+			$data["id"] = UUID::v4();
+			$data["create_time"] = mTime();
+			$data["modify_time"] = mTime();
+			$result =  $this->_create($data,["id","owner","lang","name","summary","status","create_time","modify_time"]);
+		}
+		else{
+			$this->result["ok"]=false;
+			$this->result["message"]="is exist";
+			$result = $this->result;
+		}
+		if($data===null){
+			echo json_encode($result, JSON_UNESCAPED_UNICODE);
+		}else{
+			return $result;
+		}
+		
+	}
+	
+	public function  delete(){
+		if(!isset($_COOKIE["userid"])){
+			return;
+		}
+		$where["like_type"] = $_GET["like_type"];
+		$where["resource_type"] = $_GET["resource_type"];
+		$where["resource_id"] = $_GET["resource_id"];
+		$where["user_id"] = $_COOKIE["userid"];
+		$row = $this->_delete($where);
+		if($row["data"]>0){
+			$this->result["data"] = $where;
+		}else{
+			$this->result["ok"]=false;
+			$this->result["message"]="no delete";			
+		}
+		echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
+	}
+}
+
+?>

+ 8 - 4
app/db/table.php

@@ -60,10 +60,14 @@ class Table
 		$this->result["data"] = $updateDate;
 		return $this->result;
 	}
-	public function _update($data,$columns,$where=null){
-		foreach ($columns as $value) {
-			# code...
-			$updateDate[$value] = $data[$value];
+	public function _update($data,$columns=null,$where=null){
+		if($columns==null){
+			$updateDate = $data;
+		}else{
+			foreach ($columns as $value) {
+				# code...
+				$updateDate[$value] = $data[$value];
+			}			
 		}
 
 		if($where==null){

+ 138 - 32
app/db/user.php

@@ -1,6 +1,7 @@
 <?php
 require_once "../path.php";
 require_once "../db/table.php";
+require_once "../db/channel.php";
 require_once "../public/function.php";
 // Require Composer's autoloader.
 require_once '../../vendor/autoload.php';
@@ -74,40 +75,91 @@ class User extends Table
 
 
 	public function  create(){
-		if(!isset($_COOKIE["userid"])){
-			return;
-		}
 		$json = file_get_contents('php://input');
 		$data = json_decode($json,true);
-		$data["user_id"] = $_COOKIE["userid"];
-		$isExist = $this->medoo->has("likes",$data);
+		//验证邀请码
+		if(isset($data["invite"])){
+			if ($this->redis == false) {
+				$this->result["ok"]=false;
+				$this->result["message"]="no_redis_connect";
+				echo json_encode($this->result, JSON_UNESCAPED_UNICODE);	
+				return;	
+			}
+			$redisKey = "invitecode://".$data["invite"];
+			$code = $this->redis->exists($redisKey);
+			if(!$code){
+				$this->result["ok"]=false;
+				$this->result["message"]="invite_code_invalid";
+				echo json_encode($this->result, JSON_UNESCAPED_UNICODE);	
+				return;	
+			}
+			$data["email"] = $this->redis->get($redisKey);				
+		}else{
+			$this->result["ok"]=false;
+			$this->result["message"]="no_invite_code";
+			echo json_encode($this->result, JSON_UNESCAPED_UNICODE);	
+			return;	
+		}
+		//验证用户名有效性
+		if(!$this->isValidUsername($data["username"])){
+			echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
+			return;
+		}
+		$isExist = $this->medoo->has($this->table,["username"=>$data["username"]]);
 		if(!$isExist){
-			echo json_encode($this->_create($data,["like_type","resource_type","resource_id","user_id"]), JSON_UNESCAPED_UNICODE);
+			if(!$this->isValidEmail($data["email"])){
+				echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
+				return;
+			}
+			$isExist = $this->medoo->has($this->table,["email"=>$data["email"]]);
+			if(!$isExist){
+				if(!$this->isValidPassword($data["password"])){
+					echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
+					return;
+				}
+				$data["userid"] = UUID::v4();
+				$data["password"] = md5($data["password"]);
+				$data["create_time"] = mTime();
+				$data["modify_time"] = mTime();
+				$data["setting"] = "{}";
+				$result = $this->_create($data,["userid","username","email","password","nickname","setting","create_time","modify_time"]);
+				if($result["ok"]){
+					$channel = new Channel($this->redis);
+					$newChannel1 = $channel->create(["owner"=>$data["userid"],
+													"lang"=>$data["lang"],
+													"name"=>$data["username"],
+													"lang"=>$data["lang"],
+													"status"=>30,
+													"summary"=>""
+													]);
+					$newChannel2 = $channel->create(["owner"=>$data["userid"],
+													"lang"=>$data["lang"],
+													"name"=>"draft",
+													"lang"=>$data["lang"],
+													"status"=>10,
+													"summary"=>""
+													]);
+					echo json_encode($newChannel1, JSON_UNESCAPED_UNICODE);
+					//删除
+					$this->redis->del($redisKey);
+				}else{
+					echo json_encode($result, JSON_UNESCAPED_UNICODE);
+				}
+				
+			}else{
+				$this->result["ok"]=false;
+				$this->result["message"]="email_is_exist";
+				echo json_encode($this->result, JSON_UNESCAPED_UNICODE);				
+			}
 		}
 		else{
 			$this->result["ok"]=false;
-			$this->result["message"]="is exist";
+			$this->result["message"]="account_is_exist";
 			echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
 		}
 	}
 	
-	public function  delete(){
-		if(!isset($_COOKIE["userid"])){
-			return;
-		}
-		$where["like_type"] = $_GET["like_type"];
-		$where["resource_type"] = $_GET["resource_type"];
-		$where["resource_id"] = $_GET["resource_id"];
-		$where["user_id"] = $_COOKIE["userid"];
-		$row = $this->_delete($where);
-		if($row["data"]>0){
-			$this->result["data"] = $where;
-		}else{
-			$this->result["ok"]=false;
-			$this->result["message"]="no delete";			
-		}
-		echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
-	}
+
 
 	#发送密码重置邮件
 	public function reset_password_send_email(){
@@ -199,23 +251,77 @@ class User extends Table
 	}
 
 	#重置密码
-	public function reset_password($username,$password,$token){
-		$isExist = $this->medoo->has($this->table,["user_name"=>$username,"token"=>$token]);
+	public function reset_password(){
+		$json = file_get_contents('php://input');
+		$data = json_decode($json,true);
+		$isExist = $this->medoo->has($this->table,["username"=>$data["username"],"reset_password_token"=>$data["reset_password_token"]]);
 		if($isExist){
 			#reset password
-			$ok = $this->_update(["password"=>$password],"password",["user_name"=>$username]);
-			if($ok){
-				echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
-				
-			}else{
+			if(!$this->isValidPassword($data["password"])){
 				echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
+				return;
 			}
+			$ok = $this->_update(["password"=>md5($data["password"])],["password"],["username"=>$data["username"]]);
+			if($ok){
+				#成功后删除reset_password_token
+				$ok = $this->_update(["reset_password_token"=>null,
+									  "reset_password_sent_at"=>null],
+									  null,
+									  ["username"=>$data["username"]]);	
+			}
+			echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
 		}else{
 			$this->result["ok"]=false;
-			$this->result["message"]="invalid token";
+			$this->result["message"]="invalid_token";
 			echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
 		}
 	}
+
+	private function isValidPassword($password){
+		if(mb_strlen($password,"UTF-8")<6){
+			$this->result["ok"]=false;
+			$this->result["message"]="password_too_short";
+			return false;
+		}
+		if(mb_strlen($password,"UTF-8")>32){
+			$this->result["ok"]=false;
+			$this->result["message"]="password_too_long";
+			return false;
+		}
+		if(strpos($password," ")!==false){
+			$this->result["ok"]=false;
+			$this->result["message"]="can_not_space";
+			return false;
+		}
+		return true;
+	}
+	private function isValidUsername($username){
+		if(mb_strlen($username,"UTF-8")>32){
+			$this->result["ok"]=false;
+			$this->result["message"]="username_too_long";
+			return false;
+		}
+		if(mb_strlen($username,"UTF-8")<4){
+			$this->result["ok"]=false;
+			$this->result["message"]="username_too_short";
+			return false;
+		}
+		if(preg_match("/@|\s|\//",$username)!==0){
+			$this->result["ok"]=false;
+			$this->result["message"]="char_error";
+			return false;
+		}
+		return true;
+	}
+	private function isValidEmail($email){	
+		$isValid = filter_var($email, FILTER_VALIDATE_EMAIL);
+		if($isValid===false){
+			$this->result["ok"]=false;
+			$this->result["message"]="email_format_error";
+		}
+		return $isValid;
+	}
+
 }
 
 ?>

+ 40 - 33
app/ucenter/forgot_pwd.php

@@ -135,8 +135,14 @@ require_once "../public/function.php";
 	<link type="text/css" rel="stylesheet" href="mobile.css" media="screen and (max-width:800px)">
 	</head>
 	<body id="ucenter_body" onload="login_init()">
-
 	<div id="tool_bar">
+		<div>
+		</div>
+		<div>
+			<?php
+			require_once '../lang/lang.php';
+			?>
+		</div>
 	</div>
 <div id="login_body" >
 
@@ -184,11 +190,11 @@ require_once "../public/function.php";
 
 
 				</form>
-					<div id="button_area">
-						<button  onclick="submit()" style="background-color: var(--link-hover-color);border-color: var(--link-hover-color);" >
-						<?php echo $_local->gui->continue; ?>
-						</button>
-					</div>				
+				<div id="button_area">
+					<button  onclick="submit()" style="background-color: var(--link-hover-color);border-color: var(--link-hover-color);" >
+					<?php echo $_local->gui->continue; ?>
+					</button>
+				</div>				
 			</div>
 		</div>
 	</div>
@@ -196,7 +202,8 @@ require_once "../public/function.php";
 
 	<script>
 	login_init();
-		function submit(){
+	
+	function submit(){
 			$.getJSON(
 		"../api/user.php",
 		{
@@ -210,33 +217,33 @@ require_once "../public/function.php";
 		}else{
 			$("#message").addClass("form_error");
 		}
-	}).fail(function(jqXHR, textStatus, errorThrown){
-		$("#message").removeClass("form_error");
-		$("#message").text(textStatus);				
-		switch (textStatus) {
-	
-			case "timeout":
-				break;
-			case "error":
-				switch (jqXHR.status) {
-					case 404:
-						break;
-					case 500:
-						break;				
-					default:
-						break;
-				}
-				break;
-			case "abort":
-				break;
-			case "parsererror":			
-				console.log("delete-parsererror",jqXHR.responseText);
-				break;
-			default:
-				break;
-		}
+		}).fail(function(jqXHR, textStatus, errorThrown){
+			$("#message").removeClass("form_error");
+			$("#message").text(textStatus);				
+			switch (textStatus) {
 		
-	});
+				case "timeout":
+					break;
+				case "error":
+					switch (jqXHR.status) {
+						case 404:
+							break;
+						case 500:
+							break;				
+						default:
+							break;
+					}
+					break;
+				case "abort":
+					break;
+				case "parsererror":			
+					console.log("delete-parsererror",jqXHR.responseText);
+					break;
+				default:
+					break;
+			}
+			
+		});
 		}
 	</script>
 

+ 4 - 4
app/ucenter/index.php

@@ -336,9 +336,9 @@ if (isset($_POST["op"]) && $_POST["op"] == "new") {
 		<div>
 		</div>
 		<div>
-		<?php
-require_once '../lang/lang.php';
-?>
+			<?php
+			require_once '../lang/lang.php';
+			?>
 		</div>
 	</div>
 	<div id="login_body" >
@@ -472,7 +472,7 @@ if ($op == "new") {
 				<div id="button_area">
 					<input type="submit" value="<?php echo $_local->gui->continue; ?>" style="background-color: var(--link-hover-color);border-color: var(--link-hover-color);" />
 				</div>
-				</form>
+			</form>
 			</div>
 
 		<?php

+ 4 - 7
app/ucenter/invite.php

@@ -23,8 +23,8 @@ if (PHP_SAPI == "cli") {
 		$invitecode = "invitecode://".$uuid;
 		$redis->set($invitecode,$email);
 		$redis->expire($invitecode,7*20*3600);
-		$SignUpLink="https://www.wikipali.org/ucenter/index.php?op=new&invite=".$uuid;
-		$SignUpString="https://www.wikipali.org/ucenter/index.php?op=new&invite=".$uuid;
+		$SignUpLink="https://www.wikipali.org/ucenter/sign_up.php?invite=".$uuid;
+		$SignUpString="www.wikipali.org/ucenter/sign_up.php";
 
 			// 打开文件并读取数据
 		$irow=0;
@@ -64,15 +64,12 @@ if (PHP_SAPI == "cli") {
 			$mail->Password   = Email["Password"];                               //SMTP password
 			$mail->SMTPSecure = Email["SMTPSecure"];            //Enable implicit TLS encryption
 			$mail->Port       = Email["Port"];                                    //TCP port to connect to 465; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
-
+			$mail->CharSet =  'UTF-8';
+			$mail->Encoding = 'base64';
 			//Recipients
 			$mail->setFrom(Email["From"], Email["Sender"]);
 			$mail->addAddress($email);     //Add a recipient Name is optional
 
-			//Attachments
-			//$mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
-			//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name
-
 			//Content
 			$mail->isHTML(true);                                  //Set email format to HTML
 			$mail->Subject = $strSubject;

+ 282 - 0
app/ucenter/reset.php

@@ -0,0 +1,282 @@
+<?php
+#重置密码
+require_once '../path.php';
+require_once "../public/load_lang.php";
+require_once "../public/function.php";
+
+
+if (!isset($_GET["token"])) {
+    
+}
+
+
+?>
+
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+		<meta name="viewport" content="width=device-width, initial-scale=1.0">
+		<link type="text/css" rel="stylesheet" href="../studio/css/font.css"/>
+		<link type="text/css" rel="stylesheet" href="../studio/css/style.css"/>
+		<link type="text/css" rel="stylesheet" href="../studio/css/color_day.css" id="colorchange" />
+		<title>wikipali reset password</title>
+		<script src="../public/js/comm.js"></script>
+		<script src="../studio/js/jquery-3.3.1.min.js"></script>
+		<script src="../studio/js/fixedsticky.js"></script>
+		<style>
+		#login_body{
+			display: flex;
+			padding: 2em;
+			margin: auto;
+		}
+		#login_left {
+			padding-right: 12em;
+			padding-top: 5em;
+		}
+		.title{
+			font-size: 150%;
+			margin-top: 1em;
+			margin-bottom: 0.5em;
+		}
+		#login_form{
+			padding: 2em 0 1em 0;
+		}
+		#tool_bar {
+			padding: 1em;
+			display: flex;
+			justify-content: space-between;
+		}
+		#login_shortcut {
+			display: flex;
+			flex-direction: column;
+			padding: 2em 0;
+		}
+		#login_shortcut button{
+			height:3em;
+		}
+		#button_area{
+			text-align: right;
+				padding: 1em 0;
+		}
+		.form_help{
+			font-weight: 400;
+			color: var(--bookx);
+		}
+		.login_form input{
+			margin-top:2em;
+			padding:0.5em 0.5em;
+		}
+		.login_form select{
+			margin-top:2em;
+			padding:0.5em 0.5em;
+		}
+		.login_form input[type="submit"]{
+			margin-top:2em;
+			padding:0.1em 0.5em;
+		}
+
+		.form_error{
+			color:var(--error-text);
+		}
+		#login_form_div{
+			width:30em;
+		}
+
+		#ucenter_body {
+			display: flex;
+			flex-direction: column;
+			margin: 0;
+			padding: 0;
+			background-color: var(--tool-bg-color3);
+			color: var(--btn-color);
+		}
+		.icon_big {
+			height: 2em;
+			width: 2em;
+			fill: var(--btn-color);
+			transition: all 0.2s ease;
+		}
+		.form_field_name{
+			position: absolute;
+			margin-left: 7px;
+			margin-top: 2em;
+			color: var(--btn-border-line-color);
+			-webkit-transition-duration: 0.4s;
+			-moz-transition-duration: 0.4s;
+			transition-duration: 0.4s;
+			transform: translateY(0.5em);
+		}
+		.viewswitch_on {
+			position: absolute;
+			margin-left: 7px;
+			margin-top: 1.5em;
+			color: var(--bookx);
+			-webkit-transition-duration: 0.4s;
+			-moz-transition-duration: 0.4s;
+			transition-duration: 0.4s;
+			transform: translateY(-15px);
+		}
+
+		</style>
+
+		<script>
+
+		function login_init(){
+			$("input").focus(function(){
+				let name = $(this).attr("name");
+				var objNave = document.getElementById("tip_"+name);
+				objNave.className = "viewswitch_on";
+			});
+			$(".form_field_name").click(function(){
+				let id = $(this).attr("id");
+				var objNave = document.getElementById(id);
+				objNave.className = "viewswitch_on";
+				let arrId=id.split("_");
+				document.getElementById('input_'+arrId[1]).focus();
+			});
+
+		}
+		</script>
+	<link type="text/css" rel="stylesheet" href="mobile.css" media="screen and (max-width:800px)">
+	</head>
+	<body id="ucenter_body" onload="login_init()">
+	<div id="tool_bar">
+		<div>
+		</div>
+		<div>
+			<?php
+			require_once '../lang/lang.php';
+			?>
+		</div>
+	</div>
+<div id="login_body" >
+
+	<div id="login_left">
+		<div  >
+			<svg  style="height: 8em;width: 25em;">
+				<use xlink:href="../public/images/svg/wikipali_login_page.svg#logo_login"></use>
+			</svg>
+		</div>
+		<div style="    padding: 1em 0 0 3.5em;font-weight: 400;">
+		<?php echo $_local->gui->pali_literature_platform; ?>
+		<ul style="padding-left: 1.2em;">
+			<li><?php echo $_local->gui->online_dict_db; ?></li>
+			<li><?php echo $_local->gui->user_data_share; ?></li>
+			<li><?php echo $_local->gui->cooperate_edit; ?></li>
+		</ul>
+		</div>
+	</div>
+	<div id="login_right">
+		<div id = "login_form_div" class="fun_block" >
+
+			<div class="title">
+			重置密码
+			</div>
+			<div class="login_new">
+				<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>
+			</div>
+			<?php
+			if (!isset($_GET["token"])) {
+				echo '<div class="form_error">';
+				echo "无效的密钥";
+				echo '</div>';
+			}else{
+				?>
+
+			<div class="login_form" style="    padding: 3em 0 3em 0;">
+			<div class="form_help" id="message"> </div>	
+				<div id="form_div">
+				<form action="index.php" method="post">
+					<div>
+						<div>
+							<span id='tip_username' class='form_field_name'><?php echo $_local->gui->account; ?></span>
+							<input type="input" id="username" name="username"  value="" />
+						</div>
+						<div id="error_username" class="form_error"> </div>
+						<div class="form_help"></div>
+					</div>
+
+					<div>
+						<div>
+							<span id='tip_password' class='form_field_name'><?php echo $_local->gui->password; ?></span>
+							<input type="password" id="password" name="password" placeholder="密码" value="" />
+							<input type="password" id="repassword" name="repassword" placeholder="再次输入密码" value="" />
+						</div>
+						<div class="form_help">至少6个字符</div>
+						<div id="error_password" class="form_error"></div>
+					</div>
+
+					<input type="hidden"  id="token" name="token" value="<?php echo $_REQUEST["token"]; ?>" />
+				</form>
+				<div id="button_area">
+					<button  onclick="submit()" style="background-color: var(--link-hover-color);border-color: var(--link-hover-color);" >
+					<?php echo $_local->gui->continue; ?>
+					</button>
+				</div>	
+				</div>
+			</div>
+			<?php
+			}
+			?>
+		</div>
+	</div>
+</div>
+
+	<script>
+	login_init();
+
+	function submit(){
+		$.ajax({
+			type: 'POST',
+			url:"../api/user.php?_method=reset_pwd",
+			contentType:"application/json; charset=utf-8",
+			data:JSON.stringify(
+			{
+				username:$("#username").val(),
+				password:$("#password").val(),
+				reset_password_token:$("#token").val()
+			}),
+			dataType:"json"
+			}).done(function (data) {
+				
+				if(data.ok){
+					$("#form_div").hide();
+					$("#message").removeClass("form_error");
+					$("#message").html("密码修改成功。<a href='index.php?op=login'>登录</a>");
+				}else{
+					$("#message").addClass("form_error");
+					$("#message").text(data.message);
+				}
+		}).fail(function(jqXHR, textStatus, errorThrown){
+			$("#message").removeClass("form_error");
+			$("#message").text(textStatus);				
+			switch (textStatus) {
+		
+				case "timeout":
+					break;
+				case "error":
+					switch (jqXHR.status) {
+						case 404:
+							break;
+						case 500:
+							break;				
+						default:
+							break;
+					}
+					break;
+				case "abort":
+					break;
+				case "parsererror":			
+					console.log("delete-parsererror",jqXHR.responseText);
+					break;
+				default:
+					break;
+			}
+			
+		});
+		}
+	</script>
+
+	</body>
+</html>

+ 1 - 1
app/ucenter/reset_pwd_letter.html

@@ -8,6 +8,6 @@ wikipali reset password
 <a href="%ResetLink%">%ResetString%</a>
 </p>
 <p>
-	此链接包含重置密码所需要的密钥。请勿发给他人。
+	此链接包含重置密码所需要的密钥。<b>请勿发给他人</b>
 	此邮件为系统自动发送,请勿回复。
 </p>

+ 68 - 0
app/ucenter/sign.js

@@ -0,0 +1,68 @@
+function submit(){
+	if($("#password").val()!==$("#repassword").val()){
+		$("#error_password").text("两次密码输入不一致");
+		return;
+	}
+	let nickname = $("#nickname").val();
+	if( nickname ==""){
+		nickname = $("#username").val();
+	}
+	let lang = $("#lang").val();
+	if(lang=="zh-cn"){
+		lang = "zh-hans";
+	}
+	if(lang == "zh-tw"){
+		lang = "zh-hant";
+	}
+	$.ajax({
+		type: 'POST',
+		url:"../api/user.php?_method=create",
+		contentType:"application/json; charset=utf-8",
+		data:JSON.stringify({
+			invite:$("#invite").val(),
+			username:$("#username").val(),
+			password:$("#password").val(),
+			email:$("#email").val(),
+			nickname:$("#nickname").val(),
+			lang:$("#lang").val()
+		}),
+		dataType:"json"
+		}).done(function (data) {
+			
+			if(data.ok){
+				$("#form_div").hide();
+				$("#message").removeClass("form_error");
+				$("#message").html("注册成功。<a href='index.php?op=login'>登录</a>");
+
+			}else{
+				$("#message").addClass("form_error");
+				$("#message").text(data.message);
+			}
+	}).fail(function(jqXHR, textStatus, errorThrown){
+		$("#message").removeClass("form_error");
+		$("#message").text(textStatus);				
+		switch (textStatus) {
+	
+			case "timeout":
+				break;
+			case "error":
+				switch (jqXHR.status) {
+					case 404:
+						break;
+					case 500:
+						break;				
+					default:
+						break;
+				}
+				break;
+			case "abort":
+				break;
+			case "parsererror":			
+				console.log("delete-parsererror",jqXHR.responseText);
+				break;
+			default:
+				break;
+		}
+		
+	});
+}

+ 296 - 0
app/ucenter/sign_up.php

@@ -0,0 +1,296 @@
+<?php
+#重置密码
+require_once '../path.php';
+require_once "../public/load_lang.php";
+require_once "../public/function.php";
+require_once "../redis/function.php";
+
+
+if (!isset($_GET["token"])) {
+    
+}
+
+
+?>
+
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+		<meta name="viewport" content="width=device-width, initial-scale=1.0">
+		<link type="text/css" rel="stylesheet" href="../studio/css/font.css"/>
+		<link type="text/css" rel="stylesheet" href="../studio/css/style.css"/>
+		<link type="text/css" rel="stylesheet" href="../studio/css/color_day.css" id="colorchange" />
+		<title>wikipali reset password</title>
+		<script src="../public/js/comm.js"></script>
+		<script src="../studio/js/jquery-3.3.1.min.js"></script>
+		<script src="../studio/js/fixedsticky.js"></script>
+		<script src="../ucenter/sign.js"></script>
+		<style>
+		#login_body{
+			display: flex;
+			padding: 2em;
+			margin: auto;
+		}
+		#login_left {
+			padding-right: 12em;
+			padding-top: 5em;
+		}
+		.title{
+			font-size: 150%;
+			margin-top: 1em;
+			margin-bottom: 0.5em;
+		}
+		#login_form{
+			padding: 2em 0 1em 0;
+		}
+		#tool_bar {
+			padding: 1em;
+			display: flex;
+			justify-content: space-between;
+		}
+		#login_shortcut {
+			display: flex;
+			flex-direction: column;
+			padding: 2em 0;
+		}
+		#login_shortcut button{
+			height:3em;
+		}
+		#button_area{
+			text-align: right;
+				padding: 1em 0;
+		}
+		.form_help{
+			font-weight: 400;
+			color: var(--bookx);
+		}
+		.login_form input{
+			margin-top:2em;
+			padding:0.5em 0.5em;
+		}
+		.login_form select{
+			margin-top:2em;
+			padding:0.5em 0.5em;
+		}
+		.login_form input[type="submit"]{
+			margin-top:2em;
+			padding:0.1em 0.5em;
+		}
+
+		.form_error{
+			color:var(--error-text);
+		}
+		#login_form_div{
+			width:30em;
+		}
+
+		#ucenter_body {
+			display: flex;
+			flex-direction: column;
+			margin: 0;
+			padding: 0;
+			background-color: var(--tool-bg-color3);
+			color: var(--btn-color);
+		}
+		.icon_big {
+			height: 2em;
+			width: 2em;
+			fill: var(--btn-color);
+			transition: all 0.2s ease;
+		}
+		.form_field_name{
+			position: absolute;
+			margin-left: 7px;
+			margin-top: 2em;
+			color: var(--btn-border-line-color);
+			-webkit-transition-duration: 0.4s;
+			-moz-transition-duration: 0.4s;
+			transition-duration: 0.4s;
+			transform: translateY(0.5em);
+		}
+		.viewswitch_on {
+			position: absolute;
+			margin-left: 7px;
+			margin-top: 1.5em;
+			color: var(--bookx);
+			-webkit-transition-duration: 0.4s;
+			-moz-transition-duration: 0.4s;
+			transition-duration: 0.4s;
+			transform: translateY(-15px);
+		}
+
+		</style>
+
+		<script>
+
+		function login_init(){
+			$("input").focus(function(){
+				let name = $(this).attr("name");
+				var objNave = document.getElementById("tip_"+name);
+				objNave.className = "viewswitch_on";
+			});
+			$(".form_field_name").click(function(){
+				let id = $(this).attr("id");
+				var objNave = document.getElementById(id);
+				objNave.className = "viewswitch_on";
+				let arrId=id.split("_");
+				document.getElementById('input_'+arrId[1]).focus();
+			});
+
+		}
+		</script>
+	<link type="text/css" rel="stylesheet" href="mobile.css" media="screen and (max-width:800px)">
+	</head>
+	<body id="ucenter_body" onload="login_init()">
+
+	<div id="tool_bar">
+		<div>
+		</div>
+		<div>
+			<?php
+			require_once '../lang/lang.php';
+			?>
+		</div>
+	</div>
+<div id="login_body" >
+
+	<div id="login_left">
+		<div  >
+			<svg  style="height: 8em;width: 25em;">
+				<use xlink:href="../public/images/svg/wikipali_login_page.svg#logo_login"></use>
+			</svg>
+		</div>
+		<div style="    padding: 1em 0 0 3.5em;font-weight: 400;">
+		<?php echo $_local->gui->pali_literature_platform; ?>
+		<ul style="padding-left: 1.2em;">
+			<li><?php echo $_local->gui->online_dict_db; ?></li>
+			<li><?php echo $_local->gui->user_data_share; ?></li>
+			<li><?php echo $_local->gui->cooperate_edit; ?></li>
+		</ul>
+		</div>
+	</div>
+	<div id="login_right">
+		<div id = "login_form_div" class="fun_block" >
+
+			<div class="title">
+			注册wikipali账号
+			</div>
+			<div class="login_new">
+				<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>
+			</div>
+			<div class="form_error">
+			<?php
+			if (!isset($_GET["invite"])) {
+				echo "目前只支持邀请码注册。";
+				exit;
+			}else{
+				$redis = redis_connect();
+				if ($redis == false) {
+					echo "服务器故障,请稍后重试。<br> 错误代码:no_redis_connect";
+					exit;
+				}
+				$code = $redis->exists("invitecode://".$_REQUEST["invite"]);
+				if(!$code){
+					echo "无效的邀请码,或邀请码已经过期。";
+					exit;
+				}
+				$invite_email = $redis->get("invitecode://".$_REQUEST["invite"]);				
+			?>
+			</div>
+		<div class="login_form" style="    padding: 3em 0 3em 0;">
+			<div class="form_help" id="message"> </div>	
+			<div id="form_div">
+				<form id="user_create_form" action="#" method="post">
+					<div>
+						<div>
+							<span id='tip_username' class='form_field_name'><?php echo $_local->gui->account; ?></span>
+							<input type="input" id="username" name="username" maxlength="32" value="" />
+						</div>
+						<div id="error_username" class="form_error"> </div>
+						<div class="form_help"> <?php echo $_local->gui->account_demond; ?> </div>
+					</div>
+
+					<div>
+						<span id='tip_email' class='viewswitch_on'><?php echo $_local->gui->email_address; ?></span>
+						<input type="input" id="email" name="email" disabled value="<?php echo $invite_email; ?>" />
+						<div id="error_email" class="form_error"> </div>
+					</div>
+
+					<div>
+						<div>
+							<span id='tip_password' class='form_field_name'><?php echo $_local->gui->password; ?></span>
+							<input type="password" id="password"  maxlength="32"  name="password"  value="" />
+							<input type="password" id="repassword" maxlength="32"  name="repassword" placeholder="再次输入密码" value="" />
+						</div>
+						<div class="form_help">
+						<?php echo $_local->gui->password_demond; ?>
+						</div>
+						<div id="error_password" class="form_error"> </div>
+					</div>
+
+						<div>
+							<span id='tip_language' class='viewswitch_on'><?php echo "惯常使用的语言"; ?></span>
+							<select id="lang" name="language" style="width: 100%;">
+							<?php
+							$currLang = $_COOKIE["language"];
+							$langList = [
+											"en"=>$_local->language->en,
+											"zh-cn"=>$_local->language->zh_cn,
+											"zh-tw"=>$_local->language->zh_tw,
+											"my"=>$_local->language->my,
+											"si"=>$_local->language->si,
+							];
+							foreach ($langList as $key => $value) {
+								# code...
+								if($currLang==$key){
+									$selected = " selected";
+								}else{
+									$selected = "";
+								}
+								echo "<option value='{$key}' {$selected}>{$value}</option>";
+							}
+							?>
+							</select>
+						</div>
+						
+						<div>
+							<div>
+								<span id='tip_nickname' class='form_field_name'><?php echo $_local->gui->nick_name; ?></span>
+								<input type="input" id="nickname"  maxlength="32"  name="nickname" placehoder="" value="" />
+							</div>
+							<div class="form_help">
+							<?php echo $_local->gui->name_for_show; ?>
+							</div>
+							<div id="error_password" class="form_error"> </div>
+						</div>
+
+						<input type="hidden" id="invite" name="invite" value="<?php echo $_REQUEST["invite"]; ?>" />
+				</form>
+				<div id="button_area">
+					<button  onclick="submit()" style="background-color: var(--link-hover-color);border-color: var(--link-hover-color);" >
+					<?php echo $_local->gui->continue; ?>
+					</button>
+				</div>	
+			</div>	
+		</div>
+			<?php
+			}
+			?>
+		</div>
+	</div>
+</div>
+
+<script>
+	login_init();
+
+	$("#username").on("change",function(){
+		$("#nickname").attr("placeholder",$("#username").val());
+	})
+	
+	
+	
+</script>
+
+	</body>
+</html>