|
@@ -6,6 +6,7 @@ use App\MicroApi\Facades\HttpClient;
|
|
|
use App\MicroApi\Items\TokenItem;
|
|
|
use App\MicroApi\Items\UserItem;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
+use App\MicroApi\Items\PasswordResetItem;
|
|
|
|
|
|
class UserService
|
|
|
{
|
|
@@ -123,4 +124,98 @@ class UserService
|
|
|
$result = $this->decode($response->getBody()->getContents());
|
|
|
return isset($result->user) ? $result->user : null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建密码重置记录
|
|
|
+ *
|
|
|
+ * @param $data
|
|
|
+ * @return PasswordResetItem|null
|
|
|
+ * @throws RpcException
|
|
|
+ */
|
|
|
+ public function createPasswordReset($data)
|
|
|
+ {
|
|
|
+ $path = $this->servicePrefix . '/createPasswordReset';
|
|
|
+ $item = new PasswordResetItem();
|
|
|
+ if (!empty($data['email'])) {
|
|
|
+ $item->email = $data['email'];
|
|
|
+ }
|
|
|
+ if (!empty($data['token'])) {
|
|
|
+ $item->token = $data['token'];
|
|
|
+ }
|
|
|
+ $options = ['json' => $item];
|
|
|
+ try {
|
|
|
+ $response = HttpClient::post($path, $options);
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ Log::error("MicroApi.UserService.createPasswordReset Call Failed: " . $exception->getMessage());
|
|
|
+ throw new RpcException("调用远程服务失败");
|
|
|
+ }
|
|
|
+ $result = $this->decode($response->getBody()->getContents());
|
|
|
+ return !empty($result->passwordReset) ? $result->passwordReset : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除密码重置记录
|
|
|
+ *
|
|
|
+ * @param $email
|
|
|
+ * @return bool
|
|
|
+ * @throws RpcException
|
|
|
+ */
|
|
|
+ public function deletePasswordReset($email)
|
|
|
+ {
|
|
|
+ $path = $this->servicePrefix . '/deletePasswordReset';
|
|
|
+ $item = new PasswordResetItem();
|
|
|
+ $item->email = $email;
|
|
|
+ $options = ['json' => $item];
|
|
|
+ try {
|
|
|
+ HttpClient::post($path, $options);
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ Log::error("MicroApi.UserService.deletePasswordReset Call Failed: " . $exception->getMessage());
|
|
|
+ throw new RpcException("调用远程服务失败");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证密码重置令牌
|
|
|
+ *
|
|
|
+ * @param $token
|
|
|
+ * @return bool
|
|
|
+ * @throws RpcException
|
|
|
+ */
|
|
|
+ public function validatePasswordResetToken($token)
|
|
|
+ {
|
|
|
+ $path = $this->servicePrefix . '/validatePasswordResetToken';
|
|
|
+ $item = new TokenItem();
|
|
|
+ $item->token = $token;
|
|
|
+ $options = ['json' => $item];
|
|
|
+ try {
|
|
|
+ $response = HttpClient::post($path, $options);
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ Log::error("MicroApi.UserService.validatePasswordResetToken Call Failed: " . $exception->getMessage());
|
|
|
+ throw new RpcException("调用远程服务失败");
|
|
|
+ }
|
|
|
+ $result = $this->decode($response->getBody()->getContents());
|
|
|
+ return $result->valid;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新用户信息接口
|
|
|
+ *
|
|
|
+ * @param UserItem $item
|
|
|
+ * @return UserItem
|
|
|
+ * @throws RpcException
|
|
|
+ */
|
|
|
+ public function update(UserItem $item)
|
|
|
+ {
|
|
|
+ $path = $this->servicePrefix . '/update';
|
|
|
+ $options = ['json' => $item];
|
|
|
+ try {
|
|
|
+ $response = HttpClient::post($path, $options);
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ Log::error("MicroApi.UserService.update Call Failed: " . $exception->getMessage());
|
|
|
+ throw new RpcException("调用远程服务失败");
|
|
|
+ }
|
|
|
+ $result = $this->decode($response->getBody()->getContents());
|
|
|
+ return $result->user;
|
|
|
+ }
|
|
|
}
|