SHARE
TWEET

Untitled

a guest Nov 17th, 2019 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Login component
  2.  
  3. import React, { useState } from "react";
  4. import axios from "axios";
  5. import { Form, Button, Card } from "react-bootstrap";
  6. import { withRouter } from "react-router-dom";
  7.  
  8. const Login = () => {
  9.   const [username, setUsername] = useState("");
  10.   const [password, setPassword] = useState("");
  11.   const [token, setToken] = useState("");
  12.  
  13.   // onChange = event => {
  14.   //   this.setState({ [event.target.name]: event.target.value });
  15.   // };
  16.  
  17.   const logIn = props => {
  18.     axios
  19.       .post("https://localhost:44396/user/authenticate", {
  20.         username: username,
  21.         password: password
  22.       })
  23.       .then(response => {
  24.         props.onTokenChange(response.data.token);
  25.       });
  26.   };
  27.  
  28.   return (
  29.     <div className="p-3">
  30.       <h1>Zaloguj</h1>
  31.       <h2>{token}</h2>
  32.  
  33.       <div className="row">
  34.         <div className="col-6 offset-2">
  35.           <input
  36.             name="email"
  37.             onChange={e => setUsername(e.target.value)}
  38.             placeholder="email"
  39.             className="form-control"
  40.           />
  41.           <input
  42.             name="password"
  43.             onChange={e => setPassword(e.target.value)}
  44.             placeholder="password"
  45.             className="form-control"
  46.           />
  47.         </div>
  48.         <div className="col-2">
  49.           <button onClick={logIn} className="btn btn-success">
  50.             Add Board
  51.           </button>
  52.         </div>
  53.       </div>
  54.       <Form>
  55.         <Form.Group controlId="formBasicEmail">
  56.           <Form.Label>Email address</Form.Label>
  57.           <Form.Control
  58.             type="text"
  59.             placeholder="Enter email"
  60.             onChange={e => setUsername(e.target.value)}
  61.           />
  62.           <Form.Text className="text-muted">
  63.             We'll never share your email with anyone else.
  64.           </Form.Text>
  65.         </Form.Group>
  66.         <Form.Group controlId="formBasicPassword">
  67.           <Form.Label>Password</Form.Label>
  68.           <Form.Control
  69.             type="password"
  70.             placeholder="Password"
  71.             onChange={e => setPassword(e.target.value)}
  72.           />
  73.         </Form.Group>
  74.       </Form>
  75.       <Button variant="primary" type="submit" onClick={logIn}>
  76.         Zaloguj
  77.       </Button>
  78.     </div>
  79.   );
  80. };
  81.  
  82. export default Login;
  83.  
  84.  
  85. //App component
  86.  
  87. import React, { useState } from "react";
  88. import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
  89. import Login from "./Components/Login";
  90. import "./App.css";
  91. import DataList from "./Components/DataList";
  92. import Register from "./Components/Register";
  93.  
  94. const App = () => {
  95.   const [token, setToken] = useState("Test");
  96.   const handleChange = value => {
  97.     setToken(value);
  98.   };
  99.   return (
  100.     <div>
  101.       {token}
  102.       <Router>
  103.         <Switch>
  104.           <Route path="/login">
  105.             <Login onTokenChange={handleChange} />
  106.           </Route>
  107.           <Route path="/visits">
  108.             <DataList />
  109.           </Route>
  110.           <Route path="/register">
  111.             <Register />
  112.           </Route>
  113.         </Switch>
  114.       </Router>
  115.     </div>
  116.   );
  117. };
  118.  
  119. export default App;
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