Created
November 18, 2015 15:33
-
-
Save anomaly44/10832e00a4e3217c3d48 to your computer and use it in GitHub Desktop.
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
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