Advertisement
Guest User

Untitled

a guest
Jul 27th, 2018
165
0
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.  
  4. export class Register extends Component {
  5.   constructor() {
  6.     super();
  7.     this.state = {
  8.       name: '',
  9.       email: '',
  10.       password: '',
  11.       password2: '',
  12.       errors: {}
  13.     };
  14.  
  15.     this.onChange = this.onChange.bind(this);
  16.     this.onSubmit = this.onSubmit.bind(this);
  17.   }
  18.  
  19.   onChange(e) {
  20.     this.setState({ [e.target.name]: e.target.value });
  21.   }
  22.  
  23.   onSubmit(e) {
  24.     e.preventDefault();
  25.  
  26.     const newUser = {
  27.       name: this.state.name,
  28.       email: this.state.email,
  29.       password: this.state.password,
  30.       password2: this.state.password2
  31.     };
  32.  
  33.     axios.post('/api/users/register', newUser)
  34.      .then(res => console.log(res.data))
  35.      .catch(err => console.log(err));
  36.   }
  37.  
  38.  
  39.  
  40.   render() {
  41.     return (
  42.       <div className="register">
  43.     <div className="container">
  44.       <div className="row">
  45.         <div className="col-md-8 m-auto">
  46.           <h1 className="display-4 text-center">Sign Up</h1>
  47.           <p className="lead text-center">Create your DevConnector account</p>
  48.           <form onSubmit={this.onSubmit}>
  49.             <div className="form-group">
  50.               <input type="text" className="form-control form-control-lg" placeholder="Name" name="name" value={this.state.name} onChange = {this.onChange}/>
  51.             </div>
  52.             <div className="form-group">
  53.               <input type="email" className="form-control form-control-lg" placeholder="Email Address" name="email" value={this.state.email} onChange = {this.onChange}/>
  54.               <small className="form-text text-muted">This site uses Gravatar so if you want a profile image, use a Gravatar email</small>
  55.             </div>
  56.             <div className="form-group">
  57.               <input type="password" className="form-control form-control-lg" placeholder="Password" name="password" value={this.state.password} onChange = {this.onChange}/>
  58.             </div>
  59.             <div className="form-group">
  60.               <input type="password" className="form-control form-control-lg" placeholder="Confirm Password" name="password2" value={this.state.password2} onChange = {this.onChange}/>
  61.             </div>
  62.             <input type="submit" className="btn btn-info btn-block mt-4" />
  63.           </form>
  64.         </div>
  65.       </div>
  66.     </div>
  67.   </div>
  68.     )
  69.   }
  70. }
  71.  
  72. export default Register;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement