From 568fd153ade1cb83753c0b48baf1f4f3c849b4d2 Mon Sep 17 00:00:00 2001 From: F4NNIU Date: Wed, 13 May 2020 08:57:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=96=84=E5=89=8D=E5=8F=B0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AE=BE=E7=BD=AE=E9=98=B2=E6=AD=A2=E6=98=B5=E7=A7=B0?= =?UTF-8?q?=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/User.php | 8 +++++++- application/api/controller/Validate.php | 17 +++++++++++++++++ application/api/lang/zh-cn/user.php | 1 + application/index/view/user/profile.html | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/application/api/controller/User.php b/application/api/controller/User.php index b3155214a..5d4e2b354 100644 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -158,7 +158,13 @@ class User extends Api } $user->username = $username; } - $user->nickname = $nickname; + if ($nickname) { + $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find(); + if ($exists) { + $this->error(__('Nickname already exists')); + } + $user->nickname = $nickname; + } $user->bio = $bio; $user->avatar = $avatar; $user->save(); diff --git a/application/api/controller/Validate.php b/application/api/controller/Validate.php index 87d153b86..f2d6b5c7f 100644 --- a/application/api/controller/Validate.php +++ b/application/api/controller/Validate.php @@ -53,6 +53,23 @@ class Validate extends Api $this->success(); } + /** + * 检测昵称 + * + * @param string $nickname 昵称 + * @param string $id 排除会员ID + */ + public function check_nickname_available() + { + $email = $this->request->request('nickname'); + $id = (int)$this->request->request('id'); + $count = User::where('nickname', '=', $email)->where('id', '<>', $id)->count(); + if ($count > 0) { + $this->error(__('昵称已经被占用')); + } + $this->success(); + } + /** * 检测手机 * diff --git a/application/api/lang/zh-cn/user.php b/application/api/lang/zh-cn/user.php index 111ccf542..5bb6345d0 100644 --- a/application/api/lang/zh-cn/user.php +++ b/application/api/lang/zh-cn/user.php @@ -11,6 +11,7 @@ return [ 'Password must be 6 to 30 characters' => '密码必须6-30个字符', 'Mobile is incorrect' => '手机格式不正确', 'Username already exist' => '用户名已经存在', + 'Nickname already exist' => '昵称已经存在', 'Email already exist' => '邮箱已经存在', 'Mobile already exist' => '手机号已经存在', 'Username is incorrect' => '用户名不正确', diff --git a/application/index/view/user/profile.html b/application/index/view/user/profile.html index 01da10ec1..864d2589c 100644 --- a/application/index/view/user/profile.html +++ b/application/index/view/user/profile.html @@ -59,7 +59,7 @@
- +
-- Gitee