Skip to content

Instantly share code, notes, and snippets.

@anomaly44
Created November 18, 2015 15:33
Show Gist options
  • Save anomaly44/10832e00a4e3217c3d48 to your computer and use it in GitHub Desktop.
Save anomaly44/10832e00a4e3217c3d48 to your computer and use it in GitHub Desktop.
handleSubmit = (event) => {
event.preventDefault();
const input = this.refs.username;
this.props.login(input.value);
input.value = '';
}
render() {
const {user, logout} = this.props;
const styles = require('./Login.scss');
return (
<div className={styles.loginPage + ' container'}>
<DocumentMeta title="React Redux Example: Login"/>
<h1>Login</h1>
{!user &&
<div>
<form className="login-form" onSubmit={this.handleSubmit}>
<input type="text" ref="username" placeholder="Enter a username"/>
<button className="btn btn-success" onClick={this.handleSubmit}><i className="fa fa-sign-in"/>{' '}Log In
</button>
</form>
<p>This will "log you in" as this user, storing the username in the session of the API server.</p>
</div>
}
{user &&
<div>
<p>You are currently logged in as {user.name}.</p>
<div>
<button className="btn btn-danger" onClick={logout}><i className="fa fa-sign-out"/>{' '}Log Out</button>
</div>
</div>
}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment