This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[S&C] Add a page to manager security access
- Issue #49
- Loading branch information
Showing
6 changed files
with
169 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { translate } from 'react-i18next'; | ||
import { get, post } from '../../api'; | ||
import { promisifyData, cancelPromises } from '../../utils'; | ||
import Security from './Security'; | ||
|
||
class SecurityContainer extends Component { | ||
static propTypes = { | ||
t: PropTypes.func.isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
loaded: false, | ||
saving: false, | ||
stickyContent: null, | ||
stickyStyle: 'danger', | ||
authConfig: {}, | ||
}; | ||
} | ||
|
||
async componentWillMount() { | ||
const state = await promisifyData(get('authConfig')); | ||
state.loaded = true; | ||
|
||
this.setState(state); | ||
} | ||
|
||
componentWillUnmount() { | ||
cancelPromises(); | ||
} | ||
|
||
onSubmit = (values) => { | ||
const { t } = this.props; | ||
|
||
this.setState({ saving: true }); | ||
|
||
post('security', values).then(() => ( | ||
this.setState({ | ||
saving: false, | ||
stickyContent: t('La configuration a bien été sauvegardée.'), | ||
stickyStyle: 'success', | ||
}, () => { | ||
// Clear cookies | ||
document.cookie.split(";").forEach(c => | ||
document.cookie = c.replace(/^ +/, "") | ||
.replace(/=.*/, "=;expires=" + new Date() | ||
.toUTCString() + ";path=/") | ||
); | ||
}) | ||
), () => ( | ||
this.setState({ | ||
saving: false, | ||
stickyContent: t('Une erreur est survenue lors de la sauvegarde de la configuration.'), | ||
stickyStyle: 'danger', | ||
}) | ||
)); | ||
}; | ||
|
||
render() { | ||
const { authConfig, ...rest } = this.state; | ||
|
||
return ( | ||
<Security | ||
{...rest} onSubmit={this.onSubmit} defaultValues={{ ...authConfig }} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default translate()(SecurityContainer); |
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,35 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { translate } from 'react-i18next'; | ||
import Loader from 'react-loader'; | ||
import StickyAlert from '../utils/StickyAlert'; | ||
import SecurityForm from '../forms/Security'; | ||
|
||
let stickyContainer; | ||
|
||
const Security = ({ t, loaded, stickyStyle, stickyContent, ...rest }) => ( | ||
<div ref={el => stickyContainer = el}> | ||
<div className="page-header"><h1>{t('Sécurité')}</h1></div> | ||
|
||
<p className="important"> | ||
{t("Cette page permet de sécuriser l'accès à Recalbox Manager grâce à un identifiant et un mot de passe.")} | ||
</p> | ||
|
||
<StickyAlert bsStyle={stickyStyle} container={stickyContainer}> | ||
{stickyContent} | ||
</StickyAlert> | ||
|
||
<Loader loaded={loaded}> | ||
<SecurityForm {...rest} /> | ||
</Loader> | ||
</div> | ||
); | ||
|
||
Security.propTypes = { | ||
t: PropTypes.func.isRequired, | ||
loaded: PropTypes.bool.isRequired, | ||
stickyStyle: PropTypes.string, | ||
stickyContent: PropTypes.string, | ||
}; | ||
|
||
export default translate()(Security); |
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