@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | if (!$input->getArgument('username')) { |
| 104 | 104 | $question = new Question('Please choose a username:'); |
| 105 | - $question->setValidator(function ($username) { |
|
| 105 | + $question->setValidator(function($username) { |
|
| 106 | 106 | if (empty($username)) { |
| 107 | 107 | throw new \Exception('Username can not be empty'); |
| 108 | 108 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | if (!$input->getArgument('email')) { |
| 116 | 116 | $question = new Question('Please choose an email:'); |
| 117 | - $question->setValidator(function ($email) { |
|
| 117 | + $question->setValidator(function($email) { |
|
| 118 | 118 | if (empty($email)) { |
| 119 | 119 | throw new \Exception('Email can not be empty'); |
| 120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | if (!$input->getArgument('password')) { |
| 128 | 128 | $question = new Question('Please choose a password:'); |
| 129 | - $question->setValidator(function ($password) { |
|
| 129 | + $question->setValidator(function($password) { |
|
| 130 | 130 | if (empty($password)) { |
| 131 | 131 | throw new \Exception('Password can not be empty'); |
| 132 | 132 | } |
@@ -17,7 +17,6 @@ |
||
| 17 | 17 | namespace SWP\Bundle\CoreBundle\EventListener; |
| 18 | 18 | |
| 19 | 19 | use Doctrine\Common\Persistence\ObjectManager; |
| 20 | -use FOS\ElasticaBundle\Persister\ObjectPersisterInterface; |
|
| 21 | 20 | use FOS\ElasticaBundle\Persister\PersisterRegistry; |
| 22 | 21 | use SWP\Bundle\ContentBundle\ArticleEvents; |
| 23 | 22 | use SWP\Bundle\ContentBundle\Doctrine\ArticleRepositoryInterface; |
@@ -160,9 +160,9 @@ |
||
| 160 | 160 | $resetToken = $this->resetPasswordHelper->generateResetToken($user); |
| 161 | 161 | } catch (ResetPasswordExceptionInterface $e) { |
| 162 | 162 | $this->addFlash('reset_password_error', sprintf( |
| 163 | - 'There was a problem handling your password reset request - %s', |
|
| 164 | - $e->getReason() |
|
| 165 | - )); |
|
| 163 | + 'There was a problem handling your password reset request - %s', |
|
| 164 | + $e->getReason() |
|
| 165 | + )); |
|
| 166 | 166 | |
| 167 | 167 | return $this->redirectToRoute('swp_user_check_email'); |
| 168 | 168 | } |
@@ -133,87 +133,3 @@ |
||
| 133 | 133 | return new SingleResourceResponse([ |
| 134 | 134 | 'status' => 401, |
| 135 | 135 | 'message' => <<<'MESSAGE' |
| 136 | -Unauthorized (user not found in Superdesk). |
|
| 137 | -Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
|
| 138 | -MESSAGE, |
|
| 139 | - ], new ResponseContext(401)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 143 | - if (null === $publisherUser) { |
|
| 144 | - try { |
|
| 145 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 146 | - } catch (UsernameNotFoundException $e) { |
|
| 147 | - $publisherUser = null; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (null === $publisherUser) { |
|
| 152 | - /** @var UserInterface $publisherUser */ |
|
| 153 | - $publisherUser = $userManager->createUser(); |
|
| 154 | - $publisherUser->setUsername($superdeskUser['username']); |
|
| 155 | - $publisherUser->setEmail($superdeskUser['email']); |
|
| 156 | - $publisherUser->setRoles(['ROLE_INTERNAL_API']); |
|
| 157 | - $publisherUser->setFirstName(\array_key_exists('first_name', $superdeskUser) ? $superdeskUser['first_name'] : 'Anon.'); |
|
| 158 | - $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
|
| 159 | - $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
|
| 160 | - $userManager->updateUser($publisherUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (null !== $publisherUser) { |
|
| 164 | - return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return new SingleResourceResponse([ |
|
| 169 | - 'status' => 401, |
|
| 170 | - 'message' => 'Unauthorized', |
|
| 171 | - ], new ResponseContext(401)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface |
|
| 175 | - { |
|
| 176 | - /** @var ApiKeyInterface $apiKey */ |
|
| 177 | - $apiKey = $this->generateOrGetApiKey($user, $token); |
|
| 178 | - |
|
| 179 | - return new SingleResourceResponse([ |
|
| 180 | - 'token' => [ |
|
| 181 | - 'api_key' => $apiKey->getApiKey(), |
|
| 182 | - 'valid_to' => $apiKey->getValidTo(), |
|
| 183 | - ], |
|
| 184 | - 'user' => $user, |
|
| 185 | - ]); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface |
|
| 189 | - { |
|
| 190 | - $apiKey = null; |
|
| 191 | - if (null !== $token) { |
|
| 192 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 193 | - } else { |
|
| 194 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 195 | - if (count($validKeys) > 0) { |
|
| 196 | - $apiKey = reset($validKeys); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (null === $apiKey) { |
|
| 201 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
|
| 205 | - if (!$lock->acquire()) { |
|
| 206 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 207 | - } |
|
| 208 | - $this->apiKeyRepository->add($apiKey); |
|
| 209 | - $lock->release(); |
|
| 210 | - } catch (RuntimeException $e) { |
|
| 211 | - sleep(2); |
|
| 212 | - |
|
| 213 | - return $this->generateOrGetApiKey($user, $token); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $apiKey; |
|
| 218 | - } |
|
| 219 | -} |
|
@@ -133,87 +133,3 @@ |
||
| 133 | 133 | return new SingleResourceResponse([ |
| 134 | 134 | 'status' => 401, |
| 135 | 135 | 'message' => <<<'MESSAGE' |
| 136 | -Unauthorized (user not found in Superdesk). |
|
| 137 | -Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
|
| 138 | -MESSAGE, |
|
| 139 | - ], new ResponseContext(401)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 143 | - if (null === $publisherUser) { |
|
| 144 | - try { |
|
| 145 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 146 | - } catch (UsernameNotFoundException $e) { |
|
| 147 | - $publisherUser = null; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (null === $publisherUser) { |
|
| 152 | - /** @var UserInterface $publisherUser */ |
|
| 153 | - $publisherUser = $userManager->createUser(); |
|
| 154 | - $publisherUser->setUsername($superdeskUser['username']); |
|
| 155 | - $publisherUser->setEmail($superdeskUser['email']); |
|
| 156 | - $publisherUser->setRoles(['ROLE_INTERNAL_API']); |
|
| 157 | - $publisherUser->setFirstName(\array_key_exists('first_name', $superdeskUser) ? $superdeskUser['first_name'] : 'Anon.'); |
|
| 158 | - $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
|
| 159 | - $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
|
| 160 | - $userManager->updateUser($publisherUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (null !== $publisherUser) { |
|
| 164 | - return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return new SingleResourceResponse([ |
|
| 169 | - 'status' => 401, |
|
| 170 | - 'message' => 'Unauthorized', |
|
| 171 | - ], new ResponseContext(401)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface |
|
| 175 | - { |
|
| 176 | - /** @var ApiKeyInterface $apiKey */ |
|
| 177 | - $apiKey = $this->generateOrGetApiKey($user, $token); |
|
| 178 | - |
|
| 179 | - return new SingleResourceResponse([ |
|
| 180 | - 'token' => [ |
|
| 181 | - 'api_key' => $apiKey->getApiKey(), |
|
| 182 | - 'valid_to' => $apiKey->getValidTo(), |
|
| 183 | - ], |
|
| 184 | - 'user' => $user, |
|
| 185 | - ]); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface |
|
| 189 | - { |
|
| 190 | - $apiKey = null; |
|
| 191 | - if (null !== $token) { |
|
| 192 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 193 | - } else { |
|
| 194 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 195 | - if (count($validKeys) > 0) { |
|
| 196 | - $apiKey = reset($validKeys); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (null === $apiKey) { |
|
| 201 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
|
| 205 | - if (!$lock->acquire()) { |
|
| 206 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 207 | - } |
|
| 208 | - $this->apiKeyRepository->add($apiKey); |
|
| 209 | - $lock->release(); |
|
| 210 | - } catch (RuntimeException $e) { |
|
| 211 | - sleep(2); |
|
| 212 | - |
|
| 213 | - return $this->generateOrGetApiKey($user, $token); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $apiKey; |
|
| 218 | - } |
|
| 219 | -} |
|
@@ -133,87 +133,3 @@ |
||
| 133 | 133 | return new SingleResourceResponse([ |
| 134 | 134 | 'status' => 401, |
| 135 | 135 | 'message' => <<<'MESSAGE' |
| 136 | -Unauthorized (user not found in Superdesk). |
|
| 137 | -Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
|
| 138 | -MESSAGE, |
|
| 139 | - ], new ResponseContext(401)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 143 | - if (null === $publisherUser) { |
|
| 144 | - try { |
|
| 145 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 146 | - } catch (UsernameNotFoundException $e) { |
|
| 147 | - $publisherUser = null; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (null === $publisherUser) { |
|
| 152 | - /** @var UserInterface $publisherUser */ |
|
| 153 | - $publisherUser = $userManager->createUser(); |
|
| 154 | - $publisherUser->setUsername($superdeskUser['username']); |
|
| 155 | - $publisherUser->setEmail($superdeskUser['email']); |
|
| 156 | - $publisherUser->setRoles(['ROLE_INTERNAL_API']); |
|
| 157 | - $publisherUser->setFirstName(\array_key_exists('first_name', $superdeskUser) ? $superdeskUser['first_name'] : 'Anon.'); |
|
| 158 | - $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
|
| 159 | - $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
|
| 160 | - $userManager->updateUser($publisherUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (null !== $publisherUser) { |
|
| 164 | - return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return new SingleResourceResponse([ |
|
| 169 | - 'status' => 401, |
|
| 170 | - 'message' => 'Unauthorized', |
|
| 171 | - ], new ResponseContext(401)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface |
|
| 175 | - { |
|
| 176 | - /** @var ApiKeyInterface $apiKey */ |
|
| 177 | - $apiKey = $this->generateOrGetApiKey($user, $token); |
|
| 178 | - |
|
| 179 | - return new SingleResourceResponse([ |
|
| 180 | - 'token' => [ |
|
| 181 | - 'api_key' => $apiKey->getApiKey(), |
|
| 182 | - 'valid_to' => $apiKey->getValidTo(), |
|
| 183 | - ], |
|
| 184 | - 'user' => $user, |
|
| 185 | - ]); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface |
|
| 189 | - { |
|
| 190 | - $apiKey = null; |
|
| 191 | - if (null !== $token) { |
|
| 192 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 193 | - } else { |
|
| 194 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 195 | - if (count($validKeys) > 0) { |
|
| 196 | - $apiKey = reset($validKeys); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (null === $apiKey) { |
|
| 201 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
|
| 205 | - if (!$lock->acquire()) { |
|
| 206 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 207 | - } |
|
| 208 | - $this->apiKeyRepository->add($apiKey); |
|
| 209 | - $lock->release(); |
|
| 210 | - } catch (RuntimeException $e) { |
|
| 211 | - sleep(2); |
|
| 212 | - |
|
| 213 | - return $this->generateOrGetApiKey($user, $token); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $apiKey; |
|
| 218 | - } |
|
| 219 | -} |
|
@@ -133,87 +133,3 @@ |
||
| 133 | 133 | return new SingleResourceResponse([ |
| 134 | 134 | 'status' => 401, |
| 135 | 135 | 'message' => <<<'MESSAGE' |
| 136 | -Unauthorized (user not found in Superdesk). |
|
| 137 | -Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
|
| 138 | -MESSAGE, |
|
| 139 | - ], new ResponseContext(401)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 143 | - if (null === $publisherUser) { |
|
| 144 | - try { |
|
| 145 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 146 | - } catch (UsernameNotFoundException $e) { |
|
| 147 | - $publisherUser = null; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (null === $publisherUser) { |
|
| 152 | - /** @var UserInterface $publisherUser */ |
|
| 153 | - $publisherUser = $userManager->createUser(); |
|
| 154 | - $publisherUser->setUsername($superdeskUser['username']); |
|
| 155 | - $publisherUser->setEmail($superdeskUser['email']); |
|
| 156 | - $publisherUser->setRoles(['ROLE_INTERNAL_API']); |
|
| 157 | - $publisherUser->setFirstName(\array_key_exists('first_name', $superdeskUser) ? $superdeskUser['first_name'] : 'Anon.'); |
|
| 158 | - $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
|
| 159 | - $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
|
| 160 | - $userManager->updateUser($publisherUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (null !== $publisherUser) { |
|
| 164 | - return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return new SingleResourceResponse([ |
|
| 169 | - 'status' => 401, |
|
| 170 | - 'message' => 'Unauthorized', |
|
| 171 | - ], new ResponseContext(401)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface |
|
| 175 | - { |
|
| 176 | - /** @var ApiKeyInterface $apiKey */ |
|
| 177 | - $apiKey = $this->generateOrGetApiKey($user, $token); |
|
| 178 | - |
|
| 179 | - return new SingleResourceResponse([ |
|
| 180 | - 'token' => [ |
|
| 181 | - 'api_key' => $apiKey->getApiKey(), |
|
| 182 | - 'valid_to' => $apiKey->getValidTo(), |
|
| 183 | - ], |
|
| 184 | - 'user' => $user, |
|
| 185 | - ]); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface |
|
| 189 | - { |
|
| 190 | - $apiKey = null; |
|
| 191 | - if (null !== $token) { |
|
| 192 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 193 | - } else { |
|
| 194 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 195 | - if (count($validKeys) > 0) { |
|
| 196 | - $apiKey = reset($validKeys); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (null === $apiKey) { |
|
| 201 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
|
| 205 | - if (!$lock->acquire()) { |
|
| 206 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 207 | - } |
|
| 208 | - $this->apiKeyRepository->add($apiKey); |
|
| 209 | - $lock->release(); |
|
| 210 | - } catch (RuntimeException $e) { |
|
| 211 | - sleep(2); |
|
| 212 | - |
|
| 213 | - return $this->generateOrGetApiKey($user, $token); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $apiKey; |
|
| 218 | - } |
|
| 219 | -} |
|
@@ -133,87 +133,3 @@ |
||
| 133 | 133 | return new SingleResourceResponse([ |
| 134 | 134 | 'status' => 401, |
| 135 | 135 | 'message' => <<<'MESSAGE' |
| 136 | -Unauthorized (user not found in Superdesk). |
|
| 137 | -Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
|
| 138 | -MESSAGE, |
|
| 139 | - ], new ResponseContext(401)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 143 | - if (null === $publisherUser) { |
|
| 144 | - try { |
|
| 145 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 146 | - } catch (UsernameNotFoundException $e) { |
|
| 147 | - $publisherUser = null; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (null === $publisherUser) { |
|
| 152 | - /** @var UserInterface $publisherUser */ |
|
| 153 | - $publisherUser = $userManager->createUser(); |
|
| 154 | - $publisherUser->setUsername($superdeskUser['username']); |
|
| 155 | - $publisherUser->setEmail($superdeskUser['email']); |
|
| 156 | - $publisherUser->setRoles(['ROLE_INTERNAL_API']); |
|
| 157 | - $publisherUser->setFirstName(\array_key_exists('first_name', $superdeskUser) ? $superdeskUser['first_name'] : 'Anon.'); |
|
| 158 | - $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
|
| 159 | - $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
|
| 160 | - $userManager->updateUser($publisherUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (null !== $publisherUser) { |
|
| 164 | - return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return new SingleResourceResponse([ |
|
| 169 | - 'status' => 401, |
|
| 170 | - 'message' => 'Unauthorized', |
|
| 171 | - ], new ResponseContext(401)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface |
|
| 175 | - { |
|
| 176 | - /** @var ApiKeyInterface $apiKey */ |
|
| 177 | - $apiKey = $this->generateOrGetApiKey($user, $token); |
|
| 178 | - |
|
| 179 | - return new SingleResourceResponse([ |
|
| 180 | - 'token' => [ |
|
| 181 | - 'api_key' => $apiKey->getApiKey(), |
|
| 182 | - 'valid_to' => $apiKey->getValidTo(), |
|
| 183 | - ], |
|
| 184 | - 'user' => $user, |
|
| 185 | - ]); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface |
|
| 189 | - { |
|
| 190 | - $apiKey = null; |
|
| 191 | - if (null !== $token) { |
|
| 192 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 193 | - } else { |
|
| 194 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 195 | - if (count($validKeys) > 0) { |
|
| 196 | - $apiKey = reset($validKeys); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (null === $apiKey) { |
|
| 201 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
|
| 205 | - if (!$lock->acquire()) { |
|
| 206 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 207 | - } |
|
| 208 | - $this->apiKeyRepository->add($apiKey); |
|
| 209 | - $lock->release(); |
|
| 210 | - } catch (RuntimeException $e) { |
|
| 211 | - sleep(2); |
|
| 212 | - |
|
| 213 | - return $this->generateOrGetApiKey($user, $token); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $apiKey; |
|
| 218 | - } |
|
| 219 | -} |
|
@@ -133,87 +133,3 @@ |
||
| 133 | 133 | return new SingleResourceResponse([ |
| 134 | 134 | 'status' => 401, |
| 135 | 135 | 'message' => <<<'MESSAGE' |
| 136 | -Unauthorized (user not found in Superdesk). |
|
| 137 | -Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
|
| 138 | -MESSAGE, |
|
| 139 | - ], new ResponseContext(401)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 143 | - if (null === $publisherUser) { |
|
| 144 | - try { |
|
| 145 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 146 | - } catch (UsernameNotFoundException $e) { |
|
| 147 | - $publisherUser = null; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (null === $publisherUser) { |
|
| 152 | - /** @var UserInterface $publisherUser */ |
|
| 153 | - $publisherUser = $userManager->createUser(); |
|
| 154 | - $publisherUser->setUsername($superdeskUser['username']); |
|
| 155 | - $publisherUser->setEmail($superdeskUser['email']); |
|
| 156 | - $publisherUser->setRoles(['ROLE_INTERNAL_API']); |
|
| 157 | - $publisherUser->setFirstName(\array_key_exists('first_name', $superdeskUser) ? $superdeskUser['first_name'] : 'Anon.'); |
|
| 158 | - $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
|
| 159 | - $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
|
| 160 | - $userManager->updateUser($publisherUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (null !== $publisherUser) { |
|
| 164 | - return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return new SingleResourceResponse([ |
|
| 169 | - 'status' => 401, |
|
| 170 | - 'message' => 'Unauthorized', |
|
| 171 | - ], new ResponseContext(401)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface |
|
| 175 | - { |
|
| 176 | - /** @var ApiKeyInterface $apiKey */ |
|
| 177 | - $apiKey = $this->generateOrGetApiKey($user, $token); |
|
| 178 | - |
|
| 179 | - return new SingleResourceResponse([ |
|
| 180 | - 'token' => [ |
|
| 181 | - 'api_key' => $apiKey->getApiKey(), |
|
| 182 | - 'valid_to' => $apiKey->getValidTo(), |
|
| 183 | - ], |
|
| 184 | - 'user' => $user, |
|
| 185 | - ]); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface |
|
| 189 | - { |
|
| 190 | - $apiKey = null; |
|
| 191 | - if (null !== $token) { |
|
| 192 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 193 | - } else { |
|
| 194 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 195 | - if (count($validKeys) > 0) { |
|
| 196 | - $apiKey = reset($validKeys); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (null === $apiKey) { |
|
| 201 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
|
| 205 | - if (!$lock->acquire()) { |
|
| 206 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 207 | - } |
|
| 208 | - $this->apiKeyRepository->add($apiKey); |
|
| 209 | - $lock->release(); |
|
| 210 | - } catch (RuntimeException $e) { |
|
| 211 | - sleep(2); |
|
| 212 | - |
|
| 213 | - return $this->generateOrGetApiKey($user, $token); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $apiKey; |
|
| 218 | - } |
|
| 219 | -} |
|
@@ -133,87 +133,3 @@ |
||
| 133 | 133 | return new SingleResourceResponse([ |
| 134 | 134 | 'status' => 401, |
| 135 | 135 | 'message' => <<<'MESSAGE' |
| 136 | -Unauthorized (user not found in Superdesk). |
|
| 137 | -Make sure that Publisher can talk to Superdesk instance. Set it's address in "SUPERDESK_SERVERS" environment variable. |
|
| 138 | -MESSAGE, |
|
| 139 | - ], new ResponseContext(401)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $publisherUser = $userProvider->findOneByEmail($superdeskUser['email']); |
|
| 143 | - if (null === $publisherUser) { |
|
| 144 | - try { |
|
| 145 | - $publisherUser = $userProvider->loadUserByUsername($superdeskUser['username']); |
|
| 146 | - } catch (UsernameNotFoundException $e) { |
|
| 147 | - $publisherUser = null; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (null === $publisherUser) { |
|
| 152 | - /** @var UserInterface $publisherUser */ |
|
| 153 | - $publisherUser = $userManager->createUser(); |
|
| 154 | - $publisherUser->setUsername($superdeskUser['username']); |
|
| 155 | - $publisherUser->setEmail($superdeskUser['email']); |
|
| 156 | - $publisherUser->setRoles(['ROLE_INTERNAL_API']); |
|
| 157 | - $publisherUser->setFirstName(\array_key_exists('first_name', $superdeskUser) ? $superdeskUser['first_name'] : 'Anon.'); |
|
| 158 | - $publisherUser->setLastName(\array_key_exists('last_name', $superdeskUser) ? $superdeskUser['last_name'] : ''); |
|
| 159 | - $publisherUser->setPassword(password_hash(random_bytes(36), PASSWORD_BCRYPT)); |
|
| 160 | - $userManager->updateUser($publisherUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (null !== $publisherUser) { |
|
| 164 | - return $this->returnApiTokenResponse($publisherUser, str_replace('Basic ', '', $formData['token'])); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return new SingleResourceResponse([ |
|
| 169 | - 'status' => 401, |
|
| 170 | - 'message' => 'Unauthorized', |
|
| 171 | - ], new ResponseContext(401)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function returnApiTokenResponse(UserInterface $user, string $token = null): SingleResourceResponseInterface |
|
| 175 | - { |
|
| 176 | - /** @var ApiKeyInterface $apiKey */ |
|
| 177 | - $apiKey = $this->generateOrGetApiKey($user, $token); |
|
| 178 | - |
|
| 179 | - return new SingleResourceResponse([ |
|
| 180 | - 'token' => [ |
|
| 181 | - 'api_key' => $apiKey->getApiKey(), |
|
| 182 | - 'valid_to' => $apiKey->getValidTo(), |
|
| 183 | - ], |
|
| 184 | - 'user' => $user, |
|
| 185 | - ]); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - private function generateOrGetApiKey(UserInterface $user, $token): ?ApiKeyInterface |
|
| 189 | - { |
|
| 190 | - $apiKey = null; |
|
| 191 | - if (null !== $token) { |
|
| 192 | - $apiKey = $this->apiKeyRepository->getValidToken($token)->getQuery()->getOneOrNullResult(); |
|
| 193 | - } else { |
|
| 194 | - $validKeys = $this->apiKeyRepository->getValidTokenForUser($user)->getQuery()->getResult(); |
|
| 195 | - if (count($validKeys) > 0) { |
|
| 196 | - $apiKey = reset($validKeys); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (null === $apiKey) { |
|
| 201 | - $apiKey = $this->apiKeyFactory->create($user, $token); |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - $lock = $this->lockFactory->createLock(md5(json_encode(['type' => 'user_api_key', 'user' => $user->getId()])), 2); |
|
| 205 | - if (!$lock->acquire()) { |
|
| 206 | - throw new RuntimeException('Other api key is created right now for this user'); |
|
| 207 | - } |
|
| 208 | - $this->apiKeyRepository->add($apiKey); |
|
| 209 | - $lock->release(); |
|
| 210 | - } catch (RuntimeException $e) { |
|
| 211 | - sleep(2); |
|
| 212 | - |
|
| 213 | - return $this->generateOrGetApiKey($user, $token); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $apiKey; |
|
| 218 | - } |
|
| 219 | -} |
|
@@ -20,6 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | /** |
| 22 | 22 | * @param string $name |
| 23 | + * @return void |
|
| 23 | 24 | */ |
| 24 | 25 | public function setName($name); |
| 25 | 26 | |
@@ -50,6 +51,7 @@ discard block |
||
| 50 | 51 | |
| 51 | 52 | /** |
| 52 | 53 | * @param array $settings |
| 54 | + * @return void |
|
| 53 | 55 | */ |
| 54 | 56 | public function setSettings(array $settings): void; |
| 55 | 57 | |
@@ -60,6 +62,7 @@ discard block |
||
| 60 | 62 | |
| 61 | 63 | /** |
| 62 | 64 | * @param \SplFileInfo|null $file |
| 65 | + * @return void |
|
| 63 | 66 | */ |
| 64 | 67 | public function setLogo(?\SplFileInfo $file): void; |
| 65 | 68 | |
@@ -75,8 +78,12 @@ discard block |
||
| 75 | 78 | |
| 76 | 79 | /** |
| 77 | 80 | * @param string|null $path |
| 81 | + * @return void |
|
| 78 | 82 | */ |
| 79 | 83 | public function setLogoPath(?string $path): void; |
| 80 | 84 | |
| 85 | + /** |
|
| 86 | + * @return void |
|
| 87 | + */ |
|
| 81 | 88 | public function setGeneratedData(array $data): void; |
| 82 | 89 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | AssetsInstaller::class |
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - if($newDefinition = $this->getDefinitionIfExists($container, AssetsInstallerInterface::class)) { |
|
| 36 | + if ($newDefinition = $this->getDefinitionIfExists($container, AssetsInstallerInterface::class)) { |
|
| 37 | 37 | $newDefinition->setArgument(4, new Reference(ThemeHierarchyProviderInterface::class)); |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | $themes[$themeName] = $theme; |
| 144 | 144 | |
| 145 | - if(isset($configuration['generatedData'])) { |
|
| 145 | + if (isset($configuration['generatedData'])) { |
|
| 146 | 146 | $theme->setGeneratedData($configuration['generatedData']); |
| 147 | 147 | } |
| 148 | 148 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | { |
| 176 | 176 | $tenantCode = substr($themeName, strpos($themeName, '@') + 1); |
| 177 | 177 | |
| 178 | - return array_map(function ($parentName) use ($themeName, $existingThemes, $tenantCode) { |
|
| 178 | + return array_map(function($parentName) use ($themeName, $existingThemes, $tenantCode) { |
|
| 179 | 179 | $parentName .= '@'.$tenantCode; |
| 180 | 180 | if (!isset($existingThemes[$parentName])) { |
| 181 | 181 | throw new ThemeLoadingFailedException(sprintf( |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | private function convertAuthorsArraysToAuthorsObjects(array $authorsArrays) |
| 198 | 198 | { |
| 199 | - return array_map(function (array $authorArray) { |
|
| 199 | + return array_map(function(array $authorArray) { |
|
| 200 | 200 | return $this->themeAuthorFactory->createFromArray($authorArray); |
| 201 | 201 | }, $authorsArrays); |
| 202 | 202 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | private function convertScreenshotsArraysToScreenshotsObjects(array $screenshotsArrays) |
| 210 | 210 | { |
| 211 | - return array_map(function (array $screenshotArray) { |
|
| 211 | + return array_map(function(array $screenshotArray) { |
|
| 212 | 212 | return $this->themeScreenshotFactory->createFromArray($screenshotArray); |
| 213 | 213 | }, $screenshotsArrays); |
| 214 | 214 | } |