2016-06-05 01:52:18 -07:00
|
|
|
import React from 'react';
|
2018-07-17 18:09:59 -04:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import styled from 'react-emotion';
|
2018-07-17 19:13:52 -04:00
|
|
|
import { NetlifyAuthenticator } from 'netlify-cms-lib-auth';
|
|
|
|
import { Icon, buttons, shadows } from 'netlify-cms-ui-default';
|
2018-07-17 18:09:59 -04:00
|
|
|
|
|
|
|
const StyledAuthenticationPage = styled.section`
|
|
|
|
display: flex;
|
|
|
|
flex-flow: column nowrap;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
height: 100vh;
|
|
|
|
`
|
|
|
|
|
2018-07-23 10:25:29 -04:00
|
|
|
const PageLogoIcon = styled(Icon)`
|
2018-07-17 18:09:59 -04:00
|
|
|
color: #c4c6d2;
|
|
|
|
margin-top: -300px;
|
|
|
|
`
|
|
|
|
|
|
|
|
const LoginButton = styled.button`
|
|
|
|
${buttons.button};
|
|
|
|
${shadows.dropDeep};
|
|
|
|
${buttons.default};
|
|
|
|
${buttons.gray};
|
|
|
|
|
2018-07-23 10:25:29 -04:00
|
|
|
padding: 0 12px;
|
|
|
|
margin-top: -40px;
|
2018-07-17 18:09:59 -04:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
${Icon} {
|
|
|
|
margin-right: 18px;
|
|
|
|
}
|
|
|
|
`
|
2016-06-05 01:52:18 -07:00
|
|
|
|
|
|
|
export default class AuthenticationPage extends React.Component {
|
|
|
|
static propTypes = {
|
2017-09-09 19:39:10 -06:00
|
|
|
onLogin: PropTypes.func.isRequired,
|
2017-12-07 15:37:42 -05:00
|
|
|
inProgress: PropTypes.bool,
|
2018-04-24 21:35:56 -04:00
|
|
|
base_url: PropTypes.string,
|
|
|
|
siteId: PropTypes.string,
|
|
|
|
authEndpoint: PropTypes.string,
|
2016-06-05 01:52:18 -07:00
|
|
|
};
|
|
|
|
|
2016-10-03 14:25:27 +02:00
|
|
|
state = {};
|
2016-06-05 01:52:18 -07:00
|
|
|
|
2016-11-01 14:35:20 +01:00
|
|
|
handleLogin = (e) => {
|
2016-06-05 01:52:18 -07:00
|
|
|
e.preventDefault();
|
2017-05-07 06:38:33 +02:00
|
|
|
const cfg = {
|
|
|
|
base_url: this.props.base_url,
|
2018-04-24 21:35:56 -04:00
|
|
|
site_id: (document.location.host.split(':')[0] === 'localhost') ? 'cms.netlify.com' : this.props.siteId,
|
|
|
|
auth_endpoint: this.props.authEndpoint,
|
2017-08-01 20:28:03 -07:00
|
|
|
};
|
2018-07-17 19:13:52 -04:00
|
|
|
const auth = new NetlifyAuthenticator(cfg);
|
2016-06-05 01:52:18 -07:00
|
|
|
|
2016-09-13 15:30:58 +02:00
|
|
|
auth.authenticate({ provider: 'github', scope: 'repo' }, (err, data) => {
|
2016-06-05 01:52:18 -07:00
|
|
|
if (err) {
|
2016-09-13 15:30:58 +02:00
|
|
|
this.setState({ loginError: err.toString() });
|
2016-06-05 01:52:18 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.props.onLogin(data);
|
|
|
|
});
|
2016-10-03 14:25:27 +02:00
|
|
|
};
|
2016-06-05 01:52:18 -07:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { loginError } = this.state;
|
2017-08-31 13:46:02 -06:00
|
|
|
const { inProgress } = this.props;
|
2016-06-05 01:52:18 -07:00
|
|
|
|
2016-11-01 14:35:20 +01:00
|
|
|
return (
|
2018-07-17 18:09:59 -04:00
|
|
|
<StyledAuthenticationPage>
|
2018-07-23 10:25:29 -04:00
|
|
|
<PageLogoIcon size="300px" type="netlify-cms"/>
|
2018-07-17 18:09:59 -04:00
|
|
|
{loginError ? <p>{loginError}</p> : null}
|
|
|
|
<LoginButton disabled={inProgress} onClick={this.handleLogin}>
|
2017-08-31 13:46:02 -06:00
|
|
|
<Icon type="github" /> {inProgress ? "Logging in..." : "Login with GitHub"}
|
2018-07-17 18:09:59 -04:00
|
|
|
</LoginButton>
|
|
|
|
</StyledAuthenticationPage>
|
2016-11-01 14:35:20 +01:00
|
|
|
);
|
2016-06-05 01:52:18 -07:00
|
|
|
}
|
|
|
|
}
|