Skip to content

Instantly share code, notes, and snippets.

@suresh-kumara-gist
Created November 13, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suresh-kumara-gist/eed7f3d5a16defd6c45a6a9f45097685 to your computer and use it in GitHub Desktop.
Save suresh-kumara-gist/eed7f3d5a16defd6c45a6a9f45097685 to your computer and use it in GitHub Desktop.
Authorization form
import React from 'react';
import ReactDOM from 'react-dom';
class Contact extends React.Component {
constructor(props) {
super(props);
this.state = {
password: 'swordfish',
authorized: false
};
this.authorize = this.authorize.bind(this);
}
authorize(e) {
const password = e.target.querySelector(
'input[type="password"]').value;
const auth = password == this.state.password;
this.setState({
authorized: auth
});
}
render() {
let Login = (
<div>
<h1>Enter the Password</h1>
<form action="#" onSubmit={this.authorize}>
<input type="password" />
<input type="submit" />
</form>
</div>
);
const contactInfo = (
<ul>
<li>
client@example.com
</li>
<li>
555.555.5555
</li>
</ul>
);
return (
<div id="authorization">
{ !this.state.authorized ? Login : contactInfo }
</div>
);
}
}
ReactDOM.render(
<Contact />,
document.getElementById('app')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment