diff --git a/application/api/controller/User.php b/application/api/controller/User.php index b3155214a810cec4650b5d65267348fd5752e838..5d4e2b3542da620bfcfa21486f1a96bcffabfc40 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 87d153b86e40a428d8785714eb330040ad5993ff..f2d6b5c7f1546ca1569827b936d247a497b74840 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 111ccf542b9c0ddc8c4248779f6e9160545d652c..5bb6345d027e88856de17561327f2c502e2d4b43 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 01da10ec102c05d190a56fd2f8e9377586a50962..864d2589c94de2627414038269c01b1e3ab171f6 100644 --- a/application/index/view/user/profile.html +++ b/application/index/view/user/profile.html @@ -59,7 +59,7 @@
- +