From cf7dbffbf3dcc8df39f4fefbc9dceb42c5f5161e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Jan 2017 23:51:22 -0300 Subject: [PATCH] Max Red - WIP [skip ci] --- client/src/app-components/are-you-sure.js | 12 +- .../settings/admin-panel-advanced-settings.js | 120 ++++++++++++++++-- client/src/data/fixtures/system-fixtures.js | 60 ++++++++- 3 files changed, 179 insertions(+), 13 deletions(-) diff --git a/client/src/app-components/are-you-sure.js b/client/src/app-components/are-you-sure.js index 71c8cdd8..f2bb55d5 100644 --- a/client/src/app-components/are-you-sure.js +++ b/client/src/app-components/are-you-sure.js @@ -9,7 +9,11 @@ class AreYouSure extends React.Component { static propTypes = { description: React.PropTypes.node, onYes: React.PropTypes.func, - type: React.PropTypes.string + type: React.PropTypes.oneOf(['default', 'secure']) + }; + + static defaultProps = { + type: 'default' }; static contextTypes = { @@ -39,7 +43,7 @@ class AreYouSure extends React.Component {
{this.props.description}
- {this.props.type === 'secure' ? this.renderPassword() : null} + {(this.props.type === 'secure') ? this.renderPassword() : null}
+
{i18n('DELETE_ALL_USERS')}
- +
@@ -86,6 +92,12 @@ class AdminPanelAdvancedSettings extends React.Component { ); } + renderMessage() { + return ( + {this.state.messageContent} + ); + } + getListingProps() { return { title: i18n('REGISTRATION_API_KEYS'), @@ -114,10 +126,102 @@ class AdminPanelAdvancedSettings extends React.Component { }); } - onToggleButtonChange() { - AreYouSure.openModal(
{i18n('PLEASE_CONFIRM_PASSWORD')}
, (a) => a, 'secure'); + onToggleButtonUserSystemChange() { + AreYouSure.openModal(
{i18n('PLEASE_CONFIRM_PASSWORD')}
, this.onAreYouSureUserSystemOk.bind(this), 'secure'); } + onToggleButtonRegistrationChange() { + AreYouSure.openModal(
{i18n('PLEASE_CONFIRM_PASSWORD')}
, this.onAreYouSureRegistrationOk.bind(this), 'secure'); + } + + onAreYouSureUserSystemOk(password) { + API.call({ + path: this.props.config['user-system-enabled'] ? '/system/disable-user-system' : '/system/enable-user-system', + data: { + password: password + } + }).then(() => { + this.setState({ + messageType: 'success', + messageContent: this.props.config['user-system-enabled'] ? i18n('USER_SYSTEM_DISABLE_DESCRIPTION') : i18n('USER_SYSTEM_ENABLE_DESCRIPTION') + }); + this.props.dispatch(ConfigActions.updateData()); + }).catch(() => this.setState({messageType: 'fail', messageContent: i18n('ERROR_UPDATING_SETTINGS')})); + } + + onAreYouSureRegistrationOk(password) { + API.call({ + path: this.props.config['user-system-enabled'] ? '/system/disable-registration' : '/system/enable-registration', + data: { + password: password + } + }).then(() => { + this.setState({ + messageType: 'success', + messageContent: this.props.config['user-system-enabled'] ? i18n('REGISTRATION_DISABLE_DESCRIPTION') : i18n('REGISTRATION_ENABLE_DESCRIPTION') + }); + this.props.dispatch(ConfigActions.updateData()); + }).catch(() => this.setState({messageType: 'fail', messageContent: i18n('ERROR_UPDATING_SETTINGS')})); + } + + onImportCSV(event) { + AreYouSure.openModal(
{i18n('PLEASE_CONFIRM_PASSWORD')}
, this.onAreYouSureCSVOk.bind(this, event.target.value), 'secure'); + } + + onImportSQL(event) { + AreYouSure.openModal(
{i18n('PLEASE_CONFIRM_PASSWORD')}
, this.onAreYouSureSQLOk.bind(this, event.target.value), 'secure'); + } + + onAreYouSureCSVOk(file, password) { + API.call({ + path: '/system/import-csv', + data: { + file: file, + password: password + } + }).then(() => this.setState({messageType: 'success', messageContent: i18n('SUCCESS_IMPORTING_CSV_DESCRIPTION')} + )).catch(() => this.setState({messageType: 'fail', messageContent: i18n('ERROR_IMPORTING_CSV_DESCRIPTION')})); + } + + onAreYouSureSQLOk(file, password) { + API.call({ + path: '/system/import-sql', + data: { + file: file, + password: password + } + }).then(() => this.setState({messageType: 'success', messageContent: i18n('SUCCESS_IMPORTING_SQL_DESCRIPTION')} + )).catch(() => this.setState({messageType: 'fail', messageContent: i18n('ERROR_IMPORTING_SQL_DESCRIPTION')})); + } + + onBackupDatabase() { + API.call({ + path: '/system/backup-database', + plain: true, + data: {} + }).then((result) => { + let contentType = 'application/octet-stream'; + let link = document.createElement('a'); + let blob = new Blob([result], {'type': contentType}); + link.href = window.URL.createObjectURL(blob); + link.download = 'backup.sql'; + link.click(); + }); + } + + onDeleteAllUsers() { + AreYouSure.openModal(
{i18n('PLEASE_CONFIRM_PASSWORD')}
, this.onAreYouSureDeleteAllUsersOk.bind(this), 'secure'); + } + + onAreYouSureDeleteAllUsersOk(password) { + API.call({ + path: '/system/delete-all-users', + data: { + password: password + } + }).then(() => this.setState({messageType: 'success', messageContent: i18n('SUCCESS_DELETING_ALL_USERS')} + )).catch(() => this.setState({messageType: 'fail', messageContent: i18n('ERROR_DELETING_ALL_USERS')})); + } } diff --git a/client/src/data/fixtures/system-fixtures.js b/client/src/data/fixtures/system-fixtures.js index 3e98c9a8..f84766b7 100644 --- a/client/src/data/fixtures/system-fixtures.js +++ b/client/src/data/fixtures/system-fixtures.js @@ -122,6 +122,24 @@ module.exports = [ return 'text content'; } }, + { + path: '/system/delete-all-users', + time: 100, + response: function () { + return { + status: 'success', + data: {} + }; + } + }, + { + path: '/system/backup-database', + time: 100, + contentType: 'application/octet-stream', + response: function () { + return 'text content'; + } + }, { path: '/system/get-mail-templates', time: 100, @@ -169,12 +187,52 @@ module.exports = [ }; } }, + { + path: '/system/enable-user-system', + time: 100, + response: function () { + return { + status: 'success', + data: {} + } + } + }, + { + path: '/system/disable-user-system', + time: 100, + response: function () { + return { + status: 'success', + data: {} + } + } + }, + { + path: '/system/enable-registration', + time: 100, + response: function () { + return { + status: 'success', + data: {} + } + } + }, + { + path: '/system/disable-registration', + time: 100, + response: function () { + return { + status: 'success', + data: {} + } + } + }, { path: '/system/get-all-keys', time: 300, response: function () { return { - status: "success", + status: 'success', data: [ { name: 'Game System Registration',