-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File-system backend fixes and support JWT
- Loading branch information
Igor Kuznetsov
committed
Jan 20, 2018
1 parent
70640c8
commit 5929454
Showing
6 changed files
with
184 additions
and
66 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 |
---|---|---|
@@ -1,31 +1,46 @@ | ||
.fs-auth-page-root { | ||
.nc-filesystemAuthenticationPage-root { | ||
display: flex; | ||
flex-flow: column nowrap; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
} | ||
|
||
.fs-auth-page-card { | ||
.nc-filesystemAuthenticationPage-form { | ||
width: 350px; | ||
padding: 10px; | ||
} | ||
margin-top: -80px; | ||
z-index: 1; | ||
& input { | ||
background-color: #fff; | ||
border-radius: var(--borderRadius); | ||
|
||
.fs-auth-page-card img { | ||
display: block; | ||
margin: auto; | ||
padding: 20px; | ||
} | ||
font-size: 14px; | ||
padding: 10px 10px; | ||
margin-bottom: 15px; | ||
margin-top: 6px; | ||
width: 100%; | ||
position: relative; | ||
z-index: 1; | ||
|
||
.fs-auth-page-errorMsg { | ||
color: #dd0000; | ||
&:focus { | ||
outline: none; | ||
box-shadow: inset 0 0 0 2px var(--colorBlue); | ||
} | ||
} | ||
} | ||
|
||
.fs-auth-page-message { | ||
font-size: 1.1em; | ||
margin: 20px 10px; | ||
.nc-filesystemAuthenticationPage-button { | ||
@apply(--button); | ||
@apply(--dropShadowDeep); | ||
@apply(--buttonDefault); | ||
@apply(--buttonGray); | ||
|
||
padding: 0 30px; | ||
display: block; | ||
margin-top: 20px; | ||
margin: auto; | ||
} | ||
|
||
.fs-auth-page-button { | ||
padding: .25em 1em; | ||
height: auto; | ||
.nc-filesystemAuthenticationPage-errorMsg { | ||
color: var(--colorErrorText); | ||
} |
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 |
---|---|---|
@@ -1,40 +1,108 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { partial } from 'lodash'; | ||
import { Icon } from "UI"; | ||
import logo from "./netlify_logo.svg"; | ||
import styles from "./AuthenticationPage.css"; | ||
|
||
let component = null; | ||
|
||
const localHosts = { | ||
localhost: true, | ||
"127.0.0.1": true, | ||
"0.0.0.0": true | ||
}; | ||
|
||
export default class AuthenticationPage extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
component = this; | ||
} | ||
|
||
componentDidMount() { | ||
} | ||
|
||
componentWillUnmount() { | ||
component = null; | ||
} | ||
|
||
static propTypes = { | ||
onLogin: PropTypes.func.isRequired, | ||
inProgress: PropTypes.bool, | ||
}; | ||
|
||
state = { email: '' }; | ||
state = { email: "", password: "", errors: {} }; | ||
|
||
handleChange = (name, e) => { | ||
this.setState({ ...this.state, [name]: e.target.value }); | ||
}; | ||
|
||
handleLogin = (e) => { | ||
e.preventDefault(); | ||
this.props.onLogin(this.state); | ||
}; | ||
|
||
handleEmailChange = (value) => { | ||
this.setState({ email: value }); | ||
const { email, password } = this.state; | ||
const errors = {}; | ||
|
||
if (localHosts[document.location.host.split(":").shift()]) { | ||
this.props.onLogin(this.state); | ||
} else { | ||
if (!email) { | ||
errors.email = 'Make sure to enter your email.'; | ||
} | ||
if (!password) { | ||
errors.password = 'Please enter your password.'; | ||
} | ||
if (Object.keys(errors).length > 0) { | ||
this.setState({ errors }); | ||
return; | ||
} | ||
AuthenticationPage.authClient.login(this.state.email, this.state.password, true) | ||
.then((user) => { | ||
this.props.onLogin(user); | ||
}) | ||
.catch((error) => { | ||
this.setState({ errors: { server: error.description || error.msg || error }, loggingIn: false }); | ||
}); | ||
} | ||
}; | ||
|
||
render() { | ||
const { inProgress } = this.props; | ||
|
||
return (<section className="fs-auth-page-root"> | ||
<section className="fs-auth-page-card"> | ||
<Icon className="nc-githubAuthenticationPage-logo" size="500px" type="netlify-cms"/> | ||
<button | ||
className="nc-githubAuthenticationPage-button" | ||
disabled={inProgress} | ||
onClick={this.handleLogin} | ||
> | ||
{inProgress ? "Logging in..." : "Login Local"} | ||
</button> | ||
const { errors } = this.state; | ||
const { error, inProgress } = this.props; | ||
|
||
return ( | ||
<section className="nc-filesystemAuthenticationPage-root"> | ||
<Icon className="nc-filesystemAuthenticationPage-logo" size="500px" type="netlify-cms"/> | ||
<form className="nc-filesystemAuthenticationPage-form" onSubmit={this.handleLogin}> | ||
{!error && <p> | ||
<span className="nc-filesystemAuthenticationPage-errorMsg">{error}</span> | ||
</p>} | ||
{!errors.server && <p> | ||
<span className="nc-filesystemAuthenticationPage-errorMsg">{errors.server}</span> | ||
</p>} | ||
<div className="nc-filesystemAuthenticationPage-errorMsg">{ errors.email || null }</div> | ||
<input | ||
type="text" | ||
name="email" | ||
placeholder="Email" | ||
value={this.state.email} | ||
onChange={partial(this.handleChange, 'email')} | ||
/> | ||
<div className="nc-filesystemAuthenticationPage-errorMsg">{ errors.password || null }</div> | ||
<input | ||
type="password" | ||
name="password" | ||
placeholder="Password" | ||
value={this.state.password} | ||
onChange={partial(this.handleChange, 'password')} | ||
/> | ||
<button | ||
className="nc-filesystemAuthenticationPage-button" | ||
disabled={inProgress} | ||
onClick={this.handleLogin} | ||
> | ||
{inProgress ? "Logging in..." : "Login"} | ||
</button> | ||
</form> | ||
</section> | ||
</section>); | ||
); | ||
} | ||
} |
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 was deleted.
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