-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db4002f
commit 6313c22
Showing
12 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
client/src/components/SudoModePasswordField/SudoModePasswordField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import backend from 'lib/Backend'; | ||
import classNames from 'classnames'; | ||
import Config from 'lib/Config'; | ||
import qs from 'qs'; | ||
// import i18n from 'i18n'; | ||
// import PropTypes from 'prop-types'; | ||
import React, { createRef, useState } from 'react'; | ||
// import url from 'url'; | ||
import Button from 'components/Button/Button'; | ||
|
||
function SudoModePasswordField(props) { | ||
const { | ||
className | ||
} = props; | ||
|
||
const passwordFieldRef = createRef(); | ||
const [responseMessage, setResponseMessage] = useState(''); | ||
|
||
function reloadPage() { | ||
// Add a ?reload=1 query parameter to the URL to force the browser to reload the page | ||
// window.location.reload() does not work as expected | ||
const query = qs.parse(window.location.search, { ignoreQueryPrefix: true }); | ||
const reload = query.reload ? parseInt(query.reload, 10) + 1 : 1; | ||
const hrefNoQuery = window.location.href.split('?')[0]; | ||
window.location.href = hrefNoQuery + qs.stringify({ ...query, reload }, { addQueryPrefix: true }); | ||
} | ||
|
||
async function handleClick() { | ||
const fetcher = backend.createEndpointFetcher({ | ||
url: `/${Config.getSection('SilverStripe\\Admin\\SudoModeController').url}/activate`, | ||
method: 'post', | ||
payloadFormat: 'urlencoded', | ||
responseFormat: 'json', | ||
}); | ||
const data = { | ||
Password: passwordFieldRef.current.value, | ||
}; | ||
const headers = { | ||
'X-SecurityID': Config.get('SecurityID'), | ||
}; | ||
const responseJson = await fetcher(data, headers); | ||
if (responseJson.result) { | ||
reloadPage(); | ||
} else { | ||
setResponseMessage(responseJson.message); | ||
} | ||
} | ||
|
||
function handleKeyDown(evt) { | ||
if (evt.key === 'Enter') { | ||
handleClick(); | ||
} | ||
} | ||
|
||
// todo i18n _t(), etc | ||
const message = 'This section is protected and is currently in read only mode. Please enter your password to make changes.'; | ||
|
||
return <div className="panel panel--padded flexbox-area-grow"> | ||
<div | ||
className={classNames([ | ||
'sudo-mode-password-field', | ||
'alert', | ||
'alert-info', | ||
className, | ||
])} | ||
> | ||
<p>{message}</p> | ||
<div className="sudo-mode-password-field__container"> | ||
<div className="sudo-mode-password-field__input-container"> | ||
<input | ||
className="form-control no-change-track" | ||
type="password" | ||
ref={passwordFieldRef} | ||
/* todo i18n */ | ||
placeholder="Your password" | ||
onKeyDown={(evt) => handleKeyDown(evt)} | ||
/> | ||
</div> | ||
<div> | ||
<Button | ||
className="form-control" | ||
color="info" | ||
onClick={() => handleClick()} | ||
> | ||
Submit | ||
</Button> | ||
</div> | ||
</div> | ||
{{ responseMessage } && | ||
<p className="sudo-mode-password-field__message">{responseMessage}</p> | ||
} | ||
</div> | ||
</div>; | ||
} | ||
|
||
// SearchableDropdownField.propTypes = { | ||
// disabled: PropTypes.bool.isRequired, | ||
// name: PropTypes.string.isRequired, | ||
// }; | ||
|
||
// SearchableDropdownField.defaultProps = { | ||
// disabled: false, | ||
// SelectComponent: Select, | ||
// }; | ||
|
||
export { SudoModePasswordField as Component }; | ||
|
||
// export default fieldHolder(SudoModePasswordField); | ||
export default SudoModePasswordField; |
16 changes: 16 additions & 0 deletions
16
client/src/components/SudoModePasswordField/SudoModePasswordField.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.sudo-mode-password-field { | ||
|
||
&__container { | ||
display: flex; | ||
} | ||
|
||
&__input-container { | ||
padding-right: 10px; | ||
width: 100%; | ||
max-width: 350px; | ||
} | ||
|
||
&__message { | ||
margin-top: 10px; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
client/src/legacy/SudoModePasswordField/SudoModePasswordFieldEntwine.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* global window */ | ||
import jQuery from 'jquery'; | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
// import { schemaMerge } from 'lib/schemaFieldValues'; | ||
import { loadComponent } from 'lib/Injector'; | ||
|
||
jQuery.entwine('ss', ($) => { | ||
$('.js-injector-boot .SudoModePasswordField').entwine({ | ||
Value: null, | ||
Timer: null, | ||
Component: null, | ||
ReactRoot: null, | ||
|
||
onmatch() { | ||
this._super(); | ||
|
||
const cmsContent = this.closest('.cms-content').attr('id'); | ||
const context = (cmsContent) | ||
? { context: cmsContent } | ||
: {}; | ||
|
||
const SudoModePasswordField = loadComponent('SudoModePasswordField', context); | ||
this.setComponent(SudoModePasswordField); | ||
|
||
// const state = this.data('state') || {}; | ||
// // const schema = this.data('schema') || {}; | ||
|
||
// this.setValue(state.value ? Number(state.value) : ''); | ||
|
||
this.refresh(); | ||
}, | ||
|
||
onunmatch() { | ||
this._super(); | ||
const root = this.getReactRoot(); | ||
if (root) { | ||
root.unmount(); | ||
this.setReactRoot(null); | ||
} | ||
}, | ||
|
||
refresh() { | ||
// const props = this.getAttributes(); | ||
const props = {}; | ||
const SudoModePasswordField = this.getComponent(); | ||
|
||
let root = this.getReactRoot(); | ||
if (!root) { | ||
root = createRoot(this[0]); | ||
} | ||
root.render( | ||
<SudoModePasswordField | ||
{...props} | ||
// onChange={onChange} | ||
// value={this.getValue()} | ||
// noHolder | ||
/> | ||
); | ||
this.setReactRoot(root); | ||
}, | ||
|
||
// getAttributes() { | ||
// const state = this.data('state'); | ||
// const schema = this.data('schema'); | ||
// return schemaMerge(schema, state); | ||
// }, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters