|
|
@@ -101,10 +101,17 @@ class User extends Table
|
|
|
return;
|
|
|
}
|
|
|
//验证用户名有效性
|
|
|
+ $data["username"] = trim($data["username"]);
|
|
|
if(!$this->isValidUsername($data["username"])){
|
|
|
echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
|
|
|
return;
|
|
|
}
|
|
|
+ //验证昵称有效性
|
|
|
+ $data["nickname"] = trim($data["nickname"]);
|
|
|
+ if(!$this->isValidNickName($data["nickname"])){
|
|
|
+ echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
$isExist = $this->medoo->has($this->table,["username"=>$data["username"]]);
|
|
|
if(!$isExist){
|
|
|
if(!$this->isValidEmail($data["email"])){
|
|
|
@@ -313,6 +320,19 @@ class User extends Table
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+ private function isValidNickName($nickname){
|
|
|
+ if(mb_strlen($username,"UTF-8")>32){
|
|
|
+ $this->result["ok"]=false;
|
|
|
+ $this->result["message"]="::nickname_too_long";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(mb_strlen($username,"UTF-8")<1){
|
|
|
+ $this->result["ok"]=false;
|
|
|
+ $this->result["message"]="::nicknamename_too_short";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
private function isValidEmail($email){
|
|
|
$isValid = filter_var($email, FILTER_VALIDATE_EMAIL);
|
|
|
if($isValid===false){
|