daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import axios from 'axios';
  3. import { BrowserRouter as Router ,Redirect } from 'react-router-dom';
  4. import { withRouter } from "react-router-dom";
  5. import Route from 'react-router-dom/Route';
  6. import Product from '../Dashboard/Product';
  7.  
  8. class Login extends Component {
  9.  
  10.     constructor() {
  11.         super();
  12.         this.state = {
  13.             email: '',
  14.             password: '',
  15.             token: null
  16.         }
  17.     }
  18.  
  19.     handleEmailChange = (e) => {
  20.         this.setState({
  21.             email: e.target.value
  22.         });
  23.     }
  24.  
  25.     handlePasswordChange = (e) => {
  26.         this.setState({
  27.             password: e.target.value
  28.         });
  29.     }
  30.    
  31.     handleSubmit = (e) => {
  32.         e.preventDefault();
  33.         var data = {
  34.             email: this.state.email,
  35.             password: this.state.password
  36.         };
  37.  
  38.         axios.post('http://127.0.0.1:8000/api/login', data).then(response => {
  39.             console.log(response.data.success.token);
  40.             this.setState({
  41.                 token: response.data.success.token
  42.             });
  43.             this.props.history.push("/dashboard/products");
  44.         }).catch(error => console.log(error));
  45.     }
  46.  
  47.     render() {
  48.  
  49.         return (
  50.             <div>
  51.                 <form onSubmit={this.handleSubmit}>
  52.                     <br/>
  53.                     <br/>
  54.                     <hr/>
  55.                     <label>Email</label>
  56.                     <br/>
  57.                     <input type="text" name="email" value={this.state.email} onChange={this.handleEmailChange.bind(this)}/>
  58.                     <br/>
  59.                     <label>Password</label>
  60.                     <br/>
  61.                     <input type="password" name="password" value={this.state.password} onChange={this.handlePasswordChange.bind(this)} />
  62.                     <hr/>
  63.                     <button type="submit">Login</button>
  64.                 </form>
  65.             </div>
  66.         )
  67.     }
  68. }
  69.  
  70. export default Login;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top