From 4d7ac557c74d76f976bbc311aebfda10ecccce3c Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 10 Jun 2017 04:17:54 -0300 Subject: [PATCH] Ivan - Add SMTP improvements WIP --- client/src/actions/config-actions.js | 7 +++ client/src/app/Routes.js | 10 ++-- client/src/app/install/install-layout.js | 1 + .../app/install/install-step-1-language.js | 2 +- .../install/install-step-2-requirements.js | 2 +- .../app/install/install-step-3-database.js | 2 +- .../app/install/install-step-4-user-system.js | 28 ++++------ .../app/install/install-step-5-settings.js | 53 ++++++++++++++---- .../app/install/install-step-5-settings.scss | 15 ++++++ .../src/app/install/install-step-6-admin.js | 14 ++--- .../src/app/install/install-step-6-admin.scss | 2 +- .../app/install/install-step-7-completed.js | 8 +-- client/src/data/fixtures/system-fixtures.js | 10 ++++ client/src/data/languages/en.js | 5 +- client/src/reducers/config-reducer.js | 10 +++- server/controllers/system.php | 2 + server/controllers/system/test-smtp.php | 54 +++++++++++++++++++ server/data/ERRORS.php | 5 ++ server/libs/MailSender.php | 20 +++++-- 19 files changed, 195 insertions(+), 55 deletions(-) create mode 100644 server/controllers/system/test-smtp.php diff --git a/client/src/actions/config-actions.js b/client/src/actions/config-actions.js index 4ced1e74..13a3271a 100644 --- a/client/src/actions/config-actions.js +++ b/client/src/actions/config-actions.js @@ -46,5 +46,12 @@ export default { data: {} }) }; + }, + + updateUserSystemSettings(payload) { + return { + type: 'UPDATE_USER_SYSTEM_SETTINGS', + payload: payload + }; } }; \ No newline at end of file diff --git a/client/src/app/Routes.js b/client/src/app/Routes.js index 64327b73..ef547ce4 100644 --- a/client/src/app/Routes.js +++ b/client/src/app/Routes.js @@ -57,8 +57,9 @@ import InstallStep1Language from 'app/install/install-step-1-language'; import InstallStep2Requirements from 'app/install/install-step-2-requirements'; import InstallStep3Database from 'app/install/install-step-3-database'; import InstallStep4UserSystem from 'app/install/install-step-4-user-system'; -import InstallStep5Admin from 'app/install/install-step-5-admin'; -import InstallStep6Completed from 'app/install/install-step-6-completed'; +import InstallStep5Settings from 'app/install/install-step-5-user-system'; +import InstallStep6Admin from 'app/install/install-step-6-admin'; +import InstallStep7Completed from 'app/install/install-step-7-completed'; export default ( @@ -93,8 +94,9 @@ export default ( - - + + + diff --git a/client/src/app/install/install-layout.js b/client/src/app/install/install-layout.js index ab96285e..f16a2a6b 100644 --- a/client/src/app/install/install-layout.js +++ b/client/src/app/install/install-layout.js @@ -14,6 +14,7 @@ const steps = [ 'SERVER_REQUIREMENTS', 'DATABASE_CONFIGURATION', 'USER_SYSTEM', + 'SYSTEM_SETTINGS', 'ADMIN_SETUP', 'COMPLETED' ]; diff --git a/client/src/app/install/install-step-1-language.js b/client/src/app/install/install-step-1-language.js index 7c8d1fdd..240b3d1b 100644 --- a/client/src/app/install/install-step-1-language.js +++ b/client/src/app/install/install-step-1-language.js @@ -14,7 +14,7 @@ class InstallStep1Language extends React.Component { render() { return (
-
+
+ {this.renderMessageSMTP()}
{i18n('NEXT')} @@ -61,6 +64,28 @@ class InstallStep5Settings extends React.Component { return message; } + renderMessageSMTP() { + let message = null; + + if(this.state.smtpConnection !== null) { + if(this.state.smtpConnection) { + message = ( + + {i18n('SMTP_CONNECTION_SUCCESS')} + + ); + } else { + message = ( + + {i18n('ERROR_SMTP_CONNECTION')} + + ); + } + } + + return message; + } + onTestSMTPClick(event) { event.preventDefault(); @@ -82,7 +107,11 @@ class InstallStep5Settings extends React.Component { }, () => { API.call({ path: '/system/init-settings', - data: form // add step 4 to form + data: _.extend({}, form, { + 'language': this.props.language, + 'user-system-enabled': this.props['user-system-enabled'], + 'registration': this.props['registration'] + }) }) .then(() => history.push('/install/step-6')) .catch(({message}) => this.setState({ @@ -94,4 +123,10 @@ class InstallStep5Settings extends React.Component { } } -export default InstallStep5Settings; \ No newline at end of file +export default connect((store) => { + return { + 'user-system-enabled': store.config['user-system-enabled'], + 'registration': store.config['registration'], + language: store.config.language + }; +})(InstallStep5Settings); \ No newline at end of file diff --git a/client/src/app/install/install-step-5-settings.scss b/client/src/app/install/install-step-5-settings.scss index e69de29b..d29665a4 100644 --- a/client/src/app/install/install-step-5-settings.scss +++ b/client/src/app/install/install-step-5-settings.scss @@ -0,0 +1,15 @@ +@import "../../scss/vars"; + +.install-step-5 { + + &__previous { + margin-right: 20px; + } + + &__next { + float: left; + position: absolute; + margin-left: 230px; + min-width: 70px; + } +} \ No newline at end of file diff --git a/client/src/app/install/install-step-6-admin.js b/client/src/app/install/install-step-6-admin.js index 4c3114c4..6bdd4be0 100644 --- a/client/src/app/install/install-step-6-admin.js +++ b/client/src/app/install/install-step-6-admin.js @@ -10,7 +10,7 @@ import FormField from 'core-components/form-field'; import SubmitButton from 'core-components/submit-button'; import Message from 'core-components/message'; -class InstallStep5Admin extends React.Component { +class InstallStep6Admin extends React.Component { state = { loading: false, @@ -20,14 +20,14 @@ class InstallStep5Admin extends React.Component { render() { return ( -
-
+
+
{this.renderMessage()} -
+
{i18n('NEXT')}
@@ -40,7 +40,7 @@ class InstallStep5Admin extends React.Component { if(this.state.error) { message = ( - + {i18n('ERROR_UPDATING_SETTINGS')}: {this.state.errorMessage} ); @@ -57,7 +57,7 @@ class InstallStep5Admin extends React.Component { path: '/system/init-admin', data: form }) - .then(() => history.push('/install/step-6')) + .then(() => history.push('/install/step-7')) .catch(({message}) => this.setState({ loading: false, error: true, @@ -67,4 +67,4 @@ class InstallStep5Admin extends React.Component { } } -export default InstallStep5Admin; \ No newline at end of file +export default InstallStep6Admin; \ No newline at end of file diff --git a/client/src/app/install/install-step-6-admin.scss b/client/src/app/install/install-step-6-admin.scss index 668d5326..4efe7335 100644 --- a/client/src/app/install/install-step-6-admin.scss +++ b/client/src/app/install/install-step-6-admin.scss @@ -1,6 +1,6 @@ @import "../../scss/vars"; -.install-step-5 { +.install-step-6 { &__message { margin-bottom: 20px; diff --git a/client/src/app/install/install-step-7-completed.js b/client/src/app/install/install-step-7-completed.js index 151fdbaf..c0a49475 100644 --- a/client/src/app/install/install-step-7-completed.js +++ b/client/src/app/install/install-step-7-completed.js @@ -7,7 +7,7 @@ import i18n from 'lib-app/i18n'; import Header from 'core-components/header'; import Message from 'core-components/message'; -class InstallStep6Completed extends React.Component { +class InstallStep7Completed extends React.Component { componentDidMount() { store.dispatch(ConfigActions.init()); @@ -19,8 +19,8 @@ class InstallStep6Completed extends React.Component { render() { return ( -
-
+
+
{i18n('INSTALLATION_COMPLETED_DESCRIPTION')} @@ -29,4 +29,4 @@ class InstallStep6Completed extends React.Component { } } -export default InstallStep6Completed; \ No newline at end of file +export default InstallStep7Completed; \ No newline at end of file diff --git a/client/src/data/fixtures/system-fixtures.js b/client/src/data/fixtures/system-fixtures.js index 45739ad3..58b95da4 100644 --- a/client/src/data/fixtures/system-fixtures.js +++ b/client/src/data/fixtures/system-fixtures.js @@ -224,6 +224,16 @@ module.exports = [ }; } }, + { + path: '/system/test-smtp', + time: 100, + response: function () { + return { + status: 'success', + data: {} + }; + } + }, { path: '/system/get-mail-templates', time: 100, diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index a7423b0c..8e305408 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -239,8 +239,9 @@ export default { 'STEP_2_DESCRIPTION': 'Here are listed the requirements for running OpenSupports. Please make sure that all requirements are satisfied.', 'STEP_3_DESCRIPTION': 'Please fill the MySQL database configuration.', 'STEP_4_DESCRIPTION': 'Please select your user system preferences.', - 'STEP_5_DESCRIPTION': 'Please configure the administrator account.', - 'STEP_6_DESCRIPTION': 'Installation is completed.', + 'STEP_5_DESCRIPTION': 'Please select your system preferences.', + 'STEP_6_DESCRIPTION': 'Please configure the administrator account.', + 'STEP_7_DESCRIPTION': 'Installation is completed.', //VIEW DESCRIPTIONS 'CREATE_TICKET_DESCRIPTION': 'This is a form for creating tickets. Fill the form and send us your issues/doubts/suggestions. Our support system will answer it as soon as possible.', diff --git a/client/src/reducers/config-reducer.js b/client/src/reducers/config-reducer.js index 7f76c3e5..742dbef7 100644 --- a/client/src/reducers/config-reducer.js +++ b/client/src/reducers/config-reducer.js @@ -19,7 +19,8 @@ class ConfigReducer extends Reducer { 'CHANGE_LANGUAGE': this.onLanguageChange, 'INIT_CONFIGS_FULFILLED': this.onInitConfigs, 'CHECK_INSTALLATION_FULFILLED': this.onInstallationChecked, - 'UPDATE_DATA_FULFILLED': this.onInitConfigs + 'UPDATE_DATA_FULFILLED': this.onInitConfigs, + 'UPDATE_USER_SYSTEM_SETTINGS': this.onUserSystemSettingsChange }; } @@ -48,6 +49,13 @@ class ConfigReducer extends Reducer { }); } + onUserSystemSettingsChange(state, payload) { + return _.extend({}, state, { + 'user-system-enabled': !!(payload['user-system-enabled'] * 1), + 'allow-attachments': !!(payload['allow-attachments'] * 1) + }); + } + onInstallationChecked(state, payload) { return _.extend({}, state, { installedDone: true, diff --git a/server/controllers/system.php b/server/controllers/system.php index f79c7e9f..458dd036 100755 --- a/server/controllers/system.php +++ b/server/controllers/system.php @@ -25,6 +25,7 @@ require_once 'system/delete-all-users.php'; require_once 'system/csv-import.php'; require_once 'system/backup-database.php'; require_once 'system/download.php'; +require_once 'system/test-smtp.php'; $systemControllerGroup = new ControllerGroup(); $systemControllerGroup->setGroupPath('/system'); @@ -55,5 +56,6 @@ $systemControllerGroup->addController(new DownloadController); $systemControllerGroup->addController(new CSVImportController); $systemControllerGroup->addController(new DisableUserSystemController); $systemControllerGroup->addController(new EnableUserSystemController); +$systemControllerGroup->addController(new TestSMTPController); $systemControllerGroup->finalize(); diff --git a/server/controllers/system/test-smtp.php b/server/controllers/system/test-smtp.php new file mode 100644 index 00000000..1bbdf663 --- /dev/null +++ b/server/controllers/system/test-smtp.php @@ -0,0 +1,54 @@ + 'any', + 'requestData' => [] + ]; + } + + public function handler() { + $mailSender = MailSender::getInstance(); + $mailSender->setConnectionSettings( + Controller::request('smtp-host'), + Controller::request('smtp-port'), + Controller::request('smtp-user'), + Controller::request('smtp-pass'), + Controller::request('no-reply-email') + ); + + if($mailSender->isConnected()) { + Response::respondSuccess(); + } else { + throw new Exception(ERRORS::SMTP_CONNECTION); + } + } +} \ No newline at end of file diff --git a/server/data/ERRORS.php b/server/data/ERRORS.php index 435cc66a..032fd3e4 100755 --- a/server/data/ERRORS.php +++ b/server/data/ERRORS.php @@ -171,6 +171,10 @@ * @apiDefine DATABASE_CREATION * @apiError {String} DATABASE_CREATION It's a database creation error. */ +/** + * @apiDefine SMTP_CONNECTION + * @apiError {String} SMTP_CONNECTION Could not connect with SMTP server. + */ class ERRORS { const INVALID_CREDENTIALS = 'INVALID_CREDENTIALS'; @@ -216,4 +220,5 @@ class ERRORS { const INVALID_FILE = 'INVALID_FILE'; const DATABASE_CONNECTION = 'DATABASE_CONNECTION'; const DATABASE_CREATION = 'DATABASE_CREATION'; + const SMTP_CONNECTION = 'SMTP_CONNECTION'; } diff --git a/server/libs/MailSender.php b/server/libs/MailSender.php index 7eb70cd6..a0edd583 100755 --- a/server/libs/MailSender.php +++ b/server/libs/MailSender.php @@ -14,13 +14,23 @@ class MailSender { } private function __construct() { - $this->mailOptions['from'] = Setting::getSetting('no-reply-email')->value; + $this->setConnectionSettings( + Setting::getSetting('smtp-host')->getValue(), + Setting::getSetting('smtp-port')->getValue(), + Setting::getSetting('smtp-user')->getValue(), + Setting::getSetting('smtp-pass')->getValue(), + Setting::getSetting('no-reply-email')->getValue() + ); + } + + public function setConnectionSettings($host, $port, $user, $pass, $noReplyEmail) { + $this->mailOptions['from'] = $noReplyEmail; $this->mailOptions['fromName'] = 'OpenSupports'; - $this->mailOptions['smtp-host'] = Setting::getSetting('smtp-host')->value; - $this->mailOptions['smtp-port'] = Setting::getSetting('smtp-port')->value; - $this->mailOptions['smtp-user'] = Setting::getSetting('smtp-user')->value; - $this->mailOptions['smtp-pass'] = Setting::getSetting('smtp-pass')->value; + $this->mailOptions['smtp-host'] = $host; + $this->mailOptions['smtp-port'] = $port; + $this->mailOptions['smtp-user'] = $user; + $this->mailOptions['smtp-pass'] = $pass; } public function setTemplate($type, $config) {