Skip to content

Commit 2e93753

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'api/MAGETWO-51753-Setup-Credentials-Validation' into MAGETWO-53121-502-Bad-Gateway
2 parents 3074d50 + 237b3bb commit 2e93753

File tree

9 files changed

+336
-120
lines changed

9 files changed

+336
-120
lines changed

setup/config/di.config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'Magento\Setup\Controller\Environment',
2222
'Magento\Setup\Controller\DependencyCheck',
2323
'Magento\Setup\Controller\DatabaseCheck',
24+
'Magento\Setup\Controller\ValidateAdminCredentials',
2425
'Magento\Setup\Controller\AddDatabase',
2526
'Magento\Setup\Controller\WebConfiguration',
2627
'Magento\Setup\Controller\CustomizeYourStore',

setup/pub/magento/setup/create-admin-account.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
'use strict';
77
angular.module('create-admin-account', ['ngStorage'])
8-
.controller('createAdminAccountController', ['$scope', '$state', '$localStorage', function ($scope, $state, $localStorage) {
8+
.controller('createAdminAccountController', ['$scope', '$state', '$localStorage', '$http', function ($scope, $state, $localStorage, $http) {
99
$scope.admin = {
1010
'passwordStatus': {
1111
class: 'none',
1212
label: 'None'
1313
}
1414
};
15-
15+
1616
$scope.passwordStatusChange = function () {
1717
if (angular.isUndefined($scope.admin.password)) {
1818
return;
@@ -41,6 +41,25 @@ angular.module('create-admin-account', ['ngStorage'])
4141
$scope.admin = $localStorage.admin;
4242
}
4343

44+
$scope.validateCredentials = function () {
45+
var data = {
46+
'db': $localStorage.db,
47+
'admin': $localStorage.admin,
48+
'store': $localStorage.store,
49+
'config': $localStorage.config
50+
};
51+
$http.post('index.php/validate-admin-credentials', data)
52+
.success(function (data) {
53+
$scope.validateCredentials.result = data;
54+
if ($scope.validateCredentials.result.success) {
55+
$scope.nextState();
56+
}
57+
})
58+
.error(function (data) {
59+
$scope.validateCredentials.failed = data;
60+
});
61+
};
62+
4463
$scope.$on('nextState', function () {
4564
$localStorage.admin = $scope.admin;
4665
});

setup/src/Magento/Setup/Controller/Install.php

Lines changed: 15 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,18 @@
66

77
namespace Magento\Setup\Controller;
88

9-
use Magento\Setup\Model\AdminAccount;
9+
use Magento\Framework\App\DeploymentConfig;
1010
use Magento\Framework\Config\ConfigOptionsListConstants as SetupConfigOptionsList;
11-
use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList;
11+
use Magento\SampleData;
1212
use Magento\Setup\Model\Installer;
1313
use Magento\Setup\Model\Installer\ProgressFactory;
1414
use Magento\Setup\Model\InstallerFactory;
15-
use Magento\Setup\Model\StoreConfigurationDataMapper as UserConfig;
15+
use Magento\Setup\Model\RequestDataConverter;
1616
use Magento\Setup\Model\WebLogger;
1717
use Zend\Json\Json;
1818
use Zend\Mvc\Controller\AbstractActionController;
1919
use Zend\View\Model\JsonModel;
2020
use Zend\View\Model\ViewModel;
21-
use Magento\Setup\Console\Command\InstallCommand;
22-
use Magento\SampleData;
23-
use Magento\Framework\App\DeploymentConfig;
2421

2522
/**
2623
* Install controller
@@ -54,6 +51,11 @@ class Install extends AbstractActionController
5451
*/
5552
private $deploymentConfig;
5653

54+
/**
55+
* @var RequestDataConverter
56+
*/
57+
private $requestDataConverter;
58+
5759
/**
5860
* Default Constructor
5961
*
@@ -62,19 +64,22 @@ class Install extends AbstractActionController
6264
* @param ProgressFactory $progressFactory
6365
* @param \Magento\Framework\Setup\SampleData\State $sampleDataState
6466
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
67+
* @param RequestDataConverter $requestDataConverter
6568
*/
6669
public function __construct(
6770
WebLogger $logger,
6871
InstallerFactory $installerFactory,
6972
ProgressFactory $progressFactory,
7073
\Magento\Framework\Setup\SampleData\State $sampleDataState,
71-
DeploymentConfig $deploymentConfig
74+
DeploymentConfig $deploymentConfig,
75+
RequestDataConverter $requestDataConverter
7276
) {
7377
$this->log = $logger;
7478
$this->installer = $installerFactory->create($logger);
7579
$this->progressFactory = $progressFactory;
7680
$this->sampleDataState = $sampleDataState;
7781
$this->deploymentConfig = $deploymentConfig;
82+
$this->requestDataConverter = $requestDataConverter;
7883
}
7984

8085
/**
@@ -91,19 +96,16 @@ public function indexAction()
9196
* Index Action
9297
*
9398
* @return JsonModel
94-
* @SuppressWarnings(PHPMD.NPathComplexity)
9599
*/
96100
public function startAction()
97101
{
98102
$this->log->clear();
99103
$json = new JsonModel;
100104
try {
101105
$this->checkForPriorInstall();
102-
$data = array_merge(
103-
$this->importDeploymentConfigForm(),
104-
$this->importUserConfigForm(),
105-
$this->importAdminUserForm()
106-
);
106+
$content = $this->getRequest()->getContent();
107+
$source = $content ? $source = Json::decode($content, Json::TYPE_ARRAY) : [];
108+
$data = $this->requestDataConverter->convert($source);
107109
$this->installer->install($data);
108110
$json->setVariable(
109111
'key',
@@ -168,102 +170,4 @@ private function checkForPriorInstall()
168170
throw new \Magento\Setup\Exception('Magento application is already installed.');
169171
}
170172
}
171-
172-
/**
173-
* Maps data from request to format of deployment config model
174-
*
175-
* @return array
176-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
177-
* @SuppressWarnings(PHPMD.NPathComplexity)
178-
*/
179-
private function importDeploymentConfigForm()
180-
{
181-
$content = $this->getRequest()->getContent();
182-
$source = [];
183-
if ($content) {
184-
$source = Json::decode($content, Json::TYPE_ARRAY);
185-
}
186-
187-
$result = [];
188-
$result[SetupConfigOptionsList::INPUT_KEY_DB_HOST] = isset($source['db']['host']) ? $source['db']['host'] : '';
189-
$result[SetupConfigOptionsList::INPUT_KEY_DB_NAME] = isset($source['db']['name']) ? $source['db']['name'] : '';
190-
$result[SetupConfigOptionsList::INPUT_KEY_DB_USER] = isset($source['db']['user']) ? $source['db']['user'] :'';
191-
$result[SetupConfigOptionsList::INPUT_KEY_DB_PASSWORD] =
192-
isset($source['db']['password']) ? $source['db']['password'] : '';
193-
$result[SetupConfigOptionsList::INPUT_KEY_DB_PREFIX] =
194-
isset($source['db']['tablePrefix']) ? $source['db']['tablePrefix'] : '';
195-
$result[BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME] = isset($source['config']['address']['admin'])
196-
? $source['config']['address']['admin'] : '';
197-
$result[SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY] = isset($source['config']['encrypt']['key'])
198-
? $source['config']['encrypt']['key'] : null;
199-
$result[SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE] = isset($source['config']['sessionSave']['type'])
200-
? $source['config']['sessionSave']['type'] : SetupConfigOptionsList::SESSION_SAVE_FILES;
201-
$result[Installer::ENABLE_MODULES] = isset($source['store']['selectedModules'])
202-
? implode(',', $source['store']['selectedModules']) : '';
203-
$result[Installer::DISABLE_MODULES] = isset($source['store']['allModules'])
204-
? implode(',', array_diff($source['store']['allModules'], $source['store']['selectedModules'])) : '';
205-
return $result;
206-
}
207-
208-
/**
209-
* Maps data from request to format of user config model
210-
*
211-
* @return array
212-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
213-
* @SuppressWarnings(PHPMD.NPathComplexity)
214-
*/
215-
private function importUserConfigForm()
216-
{
217-
$result = [];
218-
$source = [];
219-
$content = $this->getRequest()->getContent();
220-
if ($content) {
221-
$source = Json::decode($content, Json::TYPE_ARRAY);
222-
}
223-
if (isset($source['config']['address']['base_url']) && !empty($source['config']['address']['base_url'])) {
224-
$result[UserConfig::KEY_BASE_URL] = $source['config']['address']['base_url'];
225-
}
226-
$result[UserConfig::KEY_USE_SEF_URL] = isset($source['config']['rewrites']['allowed'])
227-
? $source['config']['rewrites']['allowed'] : '';
228-
$result[UserConfig::KEY_IS_SECURE] = isset($source['config']['https']['front'])
229-
? $source['config']['https']['front'] : '';
230-
$result[UserConfig::KEY_IS_SECURE_ADMIN] = isset($source['config']['https']['admin'])
231-
? $source['config']['https']['admin'] : '';
232-
$result[UserConfig::KEY_BASE_URL_SECURE] = (isset($source['config']['https']['front'])
233-
|| isset($source['config']['https']['admin']))
234-
? $source['config']['https']['text'] : '';
235-
$result[UserConfig::KEY_LANGUAGE] = isset($source['store']['language'])
236-
? $source['store']['language'] : '';
237-
$result[UserConfig::KEY_TIMEZONE] = isset($source['store']['timezone'])
238-
? $source['store']['timezone'] : '';
239-
$result[UserConfig::KEY_CURRENCY] = isset($source['store']['currency'])
240-
? $source['store']['currency'] : '';
241-
$result[InstallCommand::INPUT_KEY_USE_SAMPLE_DATA] = isset($source['store']['useSampleData'])
242-
? $source['store']['useSampleData'] : '';
243-
$result[InstallCommand::INPUT_KEY_CLEANUP_DB] = isset($source['store']['cleanUpDatabase'])
244-
? $source['store']['cleanUpDatabase'] : '';
245-
return $result;
246-
}
247-
248-
/**
249-
* Maps data from request to format of admin account model
250-
*
251-
* @return array
252-
* @SuppressWarnings(PHPMD.NPathComplexity)
253-
*/
254-
private function importAdminUserForm()
255-
{
256-
$result = [];
257-
$source = [];
258-
$content = $this->getRequest()->getContent();
259-
if ($content) {
260-
$source = Json::decode($content, Json::TYPE_ARRAY);
261-
}
262-
$result[AdminAccount::KEY_USER] = isset($source['admin']['username']) ? $source['admin']['username'] : '';
263-
$result[AdminAccount::KEY_PASSWORD] = isset($source['admin']['password']) ? $source['admin']['password'] : '';
264-
$result[AdminAccount::KEY_EMAIL] = isset($source['admin']['email']) ? $source['admin']['email'] : '';
265-
$result[AdminAccount::KEY_FIRST_NAME] = $result[AdminAccount::KEY_USER];
266-
$result[AdminAccount::KEY_LAST_NAME] = $result[AdminAccount::KEY_USER];
267-
return $result;
268-
}
269173
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Setup\Controller;
7+
8+
use Magento\Setup\Model\Installer;
9+
use Magento\Setup\Model\RequestDataConverter;
10+
use Magento\Setup\Validator\AdminCredentialsValidator;
11+
use Zend\Json\Json;
12+
use Zend\Mvc\Controller\AbstractActionController;
13+
use Zend\View\Model\JsonModel;
14+
15+
/**
16+
* Controller for admin credentials validation
17+
*/
18+
class ValidateAdminCredentials extends AbstractActionController
19+
{
20+
/**
21+
* @var AdminCredentialsValidator
22+
*/
23+
private $adminCredentialsValidator;
24+
25+
/**
26+
* @var RequestDataConverter
27+
*/
28+
private $requestDataConverter;
29+
30+
/**
31+
* Initialize dependencies.
32+
*
33+
* @param AdminCredentialsValidator $adminCredentialsValidator
34+
* @param RequestDataConverter $requestDataConverter
35+
*/
36+
public function __construct(
37+
AdminCredentialsValidator $adminCredentialsValidator,
38+
RequestDataConverter $requestDataConverter
39+
) {
40+
$this->adminCredentialsValidator = $adminCredentialsValidator;
41+
$this->requestDataConverter = $requestDataConverter;
42+
}
43+
44+
/**
45+
* Validate admin credentials.
46+
*
47+
* @return JsonModel
48+
*/
49+
public function indexAction()
50+
{
51+
try {
52+
$content = $this->getRequest()->getContent();
53+
$source = $content ? $source = Json::decode($content, Json::TYPE_ARRAY) : [];
54+
$data = $this->requestDataConverter->convert($source);
55+
$this->adminCredentialsValidator->validate($data);
56+
return new JsonModel(['success' => true]);
57+
} catch (\Exception $e) {
58+
return new JsonModel(['success' => false, 'error' => $e->getMessage()]);
59+
}
60+
}
61+
}

setup/src/Magento/Setup/Model/AdminAccount.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,22 @@ private function saveAdminUser()
137137
* @return void
138138
* @throws \Exception If the username and email do not both match data provided to install
139139
*/
140-
private function validateUserMatches($username, $email)
140+
public function validateUserMatches($username, $email)
141141
{
142142
if ((strcasecmp($email, $this->data[self::KEY_EMAIL]) == 0) &&
143143
(strcasecmp($username, $this->data[self::KEY_USER]) != 0)) {
144144
// email matched but username did not
145145
throw new \Exception(
146-
'An existing user has the given email but different username. ' . self::KEY_USER .
147-
' and ' . self::KEY_EMAIL . ' both need to match an existing user or both be new.'
146+
'An existing user has the given email but different username. '
147+
. 'Username and email both need to match an existing user or both be new.'
148148
);
149149
}
150150
if ((strcasecmp($username, $this->data[self::KEY_USER]) == 0) &&
151151
(strcasecmp($email, $this->data[self::KEY_EMAIL]) != 0)) {
152152
// username matched but email did not
153153
throw new \Exception(
154-
'An existing user has the given username but different email. ' . self::KEY_USER .
155-
' and ' . self::KEY_EMAIL . ' both need to match an existing user or both be new.'
154+
'An existing user has the given username but different email. '
155+
. 'Username and email both need to match an existing user or both be new.'
156156
);
157157
}
158158
}

0 commit comments

Comments
 (0)