From 8b3e463eff0e8a2a380138a0a88cfbbb75478d53 Mon Sep 17 00:00:00 2001
From: Avinash Gusain
Date: Wed, 5 Oct 2022 16:08:37 +0530
Subject: [PATCH 01/23] api created
---
appinfo/routes.php | 1 +
lib/Controller/ShopAccountController.php | 25 +++++++++++++++++++++++-
lib/Service/ShopAccountService.php | 12 ++++++------
lib/Settings/Personal.php | 8 +++-----
4 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 9999debd..a51eb60b 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -7,6 +7,7 @@ return ['routes' => [
['name' => 'shop_account#set_shop_email_post_delete', 'url' => '/shop-accounts/set_shop_email_post_delete', 'verb' => 'POST' ],
['name' => 'shop_account#set_shop_delete_preference', 'url' => '/shop-accounts/set_shop_delete_preference', 'verb' => 'POST' ],
['name' => 'shop_account#get_order_info', 'url' => '/shop-accounts/order_info', 'verb' => 'GET'],
+ ['name' => 'shop_account#get_shop_user', 'url' => '/shop-accounts/shop_user', 'verb' => 'GET'],
[
'name' => 'user#preflighted_cors', 'url' => '/api/{path}',
'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')
diff --git a/lib/Controller/ShopAccountController.php b/lib/Controller/ShopAccountController.php
index 7a4c7c09..06ad7dff 100644
--- a/lib/Controller/ShopAccountController.php
+++ b/lib/Controller/ShopAccountController.php
@@ -62,7 +62,7 @@ class ShopAccountController extends Controller {
$this->shopAccountService->setShopEmailPostDeletePreference($userId, $shopEmailPostDelete);
}
-
+
/**
* @NoAdminRequired
*/
@@ -99,4 +99,27 @@ class ShopAccountController extends Controller {
$response->setData($data);
return $response;
}
+
+ /**
+ * @NoAdminRequired
+ */
+ public function getShopUser() {
+ $response = new DataResponse();
+ $user = $this->userSession->getUser();
+ $email = $user->getEMailAddress();
+
+ $shopUser = $this->shopAccountService->getUser($email);
+
+ $data = ['count' => 0];
+ $data = ['isuseroidc' => false];
+ if(!$shopUser) {
+ $response->setData($data);
+ return $response;
+ }
+ $isUserOIDC=$this->shopAccountService->isUserOIDC($shopUser);
+ $data['count'] = count($shopUser);
+ $data['isuseroidc'] = $isUserOIDC;
+ $response->setData($data);
+ return $response;
+ }
}
\ No newline at end of file
diff --git a/lib/Service/ShopAccountService.php b/lib/Service/ShopAccountService.php
index 97288422..630e2ca1 100644
--- a/lib/Service/ShopAccountService.php
+++ b/lib/Service/ShopAccountService.php
@@ -52,7 +52,7 @@ class ShopAccountService {
public function getShopEmailPostDeletePreference($userId) {
$recoveryEmail = $this->config->getUserValue($userId, 'email-recovery', 'recovery-email');
- return $this->config->getUserValue($userId, $this->appName, 'shop_email_post_delete', $recoveryEmail);
+ return $this->config->getUserValue($userId, $this->appName, 'shop_email_post_delete', $recoveryEmail);
}
public function getOrders(int $userId): ?array {
@@ -86,7 +86,7 @@ class ShopAccountService {
return $users[0];
}
- public function deleteUser(int $userId) : void {
+ public function deleteUser(int $userId) : void {
$params = [
'force' => true,
'reassign' => $this->shopReassignUserId
@@ -104,8 +104,8 @@ class ShopAccountService {
$this->logger->error('Error deleting user at WP with ID ' . $userId);
$this->logger->logException($e, ['app' => Application::APP_ID]);
}
-
- }
+
+ }
public function updateUserEmail(int $userId, string $email) : void {
$updateUrl = $this->shopUserUrl . '/' . strval($userId);
@@ -116,7 +116,7 @@ class ShopAccountService {
try {
$answer = $this->callShopAPI($updateUrl, 'POST', $params);
-
+
if($answer['email'] !== $email) {
throw new Exception('Unknown error while updating!');
}
@@ -128,7 +128,7 @@ class ShopAccountService {
}
private function callShopAPI(string $url, string $method, array $data = []) {
-
+
$headers = [
"cache-control: no-cache",
"content-type: application/json",
diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php
index 9faa8a19..e3a026e9 100644
--- a/lib/Settings/Personal.php
+++ b/lib/Settings/Personal.php
@@ -68,7 +68,7 @@ class Personal implements ISettings {
* @since 9.1
*/
public function getForm(): TemplateResponse {
-
+
$user = $this->userSession->getUser();
if ($user) {
$onlyUser = $this->userManager->countUsers() < 2;
@@ -85,7 +85,7 @@ class Personal implements ISettings {
$this->initialState->provideInitialState('only_user', $onlyUser);
$this->initialState->provideInitialState('only_admin', $onlyAdmin);
}
-
+
return new TemplateResponse($this->appName, 'personal');
}
@@ -96,10 +96,8 @@ class Personal implements ISettings {
*/
public function getSection(): ?string {
$user = $this->userSession->getUser();
- $shopUser = $this->shopAccountService->getUser($user->getEMailAddress());
$dropAccountEnabled = $this->appManager->isEnabledForUser(self::DROP_ACCOUNT_APP_ID);
-
- if($dropAccountEnabled && $shopUser && $this->shopAccountService->isUserOIDC($shopUser)) {
+ if($dropAccountEnabled) {
return self::DROP_ACCOUNT_APP_ID;
}
return null;
--
GitLab
From 94542bc7fdf1a969cc2970562585a9f30401e7d7 Mon Sep 17 00:00:00 2001
From: Avinash Gusain
Date: Wed, 5 Oct 2022 17:01:43 +0530
Subject: [PATCH 02/23] api in frontend
---
src/PersonalSettings.vue | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/PersonalSettings.vue b/src/PersonalSettings.vue
index 9f2a1067..b84157c1 100644
--- a/src/PersonalSettings.vue
+++ b/src/PersonalSettings.vue
@@ -7,7 +7,7 @@