Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 18, 2022 21:56
Show Gist options
  • Save codecademydev/b6193e4ef54c65c34edbf364b1c9feb8 to your computer and use it in GitHub Desktop.
Save codecademydev/b6193e4ef54c65c34edbf364b1c9feb8 to your computer and use it in GitHub Desktop.
Codecademy export
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() {
const login = (
<form action="#"
onSubmit={this.authorize}>
<input type="password" placeholder="Password" />
<input type="submit" />
</form>
);
const contactInfo = (
<ul>
<li>
client@example.com
</li>
<li>
555.555.5555
</li>
</ul>
);
return (
<div id="authorization">
<h1>{ this.state.authorized ? 'Contact' : 'Enter the Password' }</h1>
{ this.state.authorized ? contactInfo : login }
</div>
);
}
}
ReactDOM.render(
<Contact />,
document.getElementById('app')
);
@SOliv1
Copy link

SOliv1 commented Aug 18, 2022

An authorization form to be used on a client website who wishes to hide personal details behind a password. form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment