mobile); }else if($verify_type == 'email'){ captcha_verfiy('email', 'verify', $user->email); }else{ return $this->error(__('Invalid verify type')); } return $this->success(__('Security verify successfully')); } /** * 绑定手机号 * @Apidoc\Method("POST") * @Apidoc\Param("region", type="string", require=true, desc="区域代码") * @Apidoc\Param("mobile", type="string", require=true, desc="手机号") * @Apidoc\Param("code", type="string", require=true, desc="验证码,event=bind_mobile") */ public function bind_mobile() { $user = \support\Jwt::getUser(); $mobile = input('mobile'); $region = input('region'); // 验证手机号格式 if (!$mobile || !Validate::regex($mobile, "^1\d{10}$")) { return $this->error(__('Incorrect mobile number format')); } // 验证手机号唯一性 if (UserModel::where('mobile', $mobile)->where('region',$region)->where('id', '<>', $user->id)->find()) { return $this->error(__('Mobile number already exists')); } // 验证验证码 captcha_verfiy('mobile', 'bind_mobile', $mobile); // 更新用户信息 $user->mobile = $mobile; $user->region = $region; //$user->mobile_verify = 1; $user->save(); return $this->success(__('Mobile number bound successfully')); } /** * 绑定邮箱 * @Apidoc\Method("POST") * @Apidoc\Param("email", type="string", require=true, desc="邮箱") * @Apidoc\Param("code", type="string", require=true, desc="验证码,event=bind_email") */ public function bind_email() { $user = \support\Jwt::getUser(); $email = input('email'); // 验证邮箱格式 if (!$email || !Validate::email($email)) { return $this->error(__('Incorrect email format')); } // 验证邮箱唯一性 if (UserModel::where('email', $email)->where('id', '<>', $user->id)->find()) { return $this->error(__('Email already exists')); } captcha_verfiy('email', 'bind_email', $email); // 更新用户信息 $user->email = $email; //$user->email_verify = 1; $user->save(); return $this->success(__('Email bound successfully')); } /** * 绑定用户名 * @Apidoc\Method("POST") * @Apidoc\Param("username", type="string", require=true, desc="用户名") * @Apidoc\Param("verify_type", type="string", require=true, desc="验证类型,email或mobile") * @Apidoc\Param("code", type="string", require=true, desc="验证码,event=bind_username") */ public function bind_username() { $user = \support\Jwt::getUser(); $username = input('username'); $verify_type = input('verify_type'); // 验证用户名格式 if (!$username || strlen($username) < 3 || strlen($username) > 20) { return $this->error(__('Username length must be between 3 and 20 characters')); } // 验证用户名唯一性 if (UserModel::where('username', $username)->where('id', '<>', $user->id)->find()) { return $this->error(__('Username already exists')); } if($verify_type == 'mobile'){ captcha_verfiy('mobile', 'bind_username', $user->mobile); }else if($verify_type == 'email'){ captcha_verfiy('email', 'bind_username', $user->email); } // 更新用户信息 $user->username = $username; $user->save(); return $this->success(__('Username bound successfully')); } /** * 解绑手机号 * @Apidoc\Method("POST") * @Apidoc\Param("code", type="string", require=true, desc="验证码,event=unbind_mobile") */ public function unbind_mobile() { $user = \support\Jwt::getUser(); if (!$user->mobile) { return $this->error(__('Mobile number not bound')); } // 验证验证码 captcha_verfiy('mobile', 'unbind_mobile', $user->mobile); // 更新用户信息 $user->mobile = ''; $user->mobile_verify = 0; $user->save(); return $this->success(__('Mobile number unbound successfully')); } /** * 解绑邮箱 * @Apidoc\Method("POST") * @Apidoc\Param("code", type="string", require=true, desc="验证码,event=unbind_email") */ public function unbind_email() { $user = \support\Jwt::getUser(); if (!$user->email) { return $this->error(__('Email not bound')); } // 验证验证码 captcha_verfiy('email', 'unbind_email', $user->email); // 更新用户信息 $user->email = ''; $user->email_verify = 0; $user->save(); return $this->success(__('Email unbound successfully')); } }