Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import './instaAuth.css';
  3.  
  4. class InstaAuth extends Component {
  5.   constructor(){
  6.   super();
  7.     this.state = {
  8.       username: '',
  9.       password: '',
  10.       message:  '',
  11.       isloggedIn: true,
  12.       userdata : {
  13.         userid : '',
  14.         username : '',
  15.         fullname : '',
  16.         profile_pic : ''
  17.       }
  18.     }
  19.     this.handleChange = this.handleChange.bind(this);
  20.     this.handleSubmit = this.handleSubmit.bind(this);
  21.   }
  22.  
  23. handleChange(event,type) {
  24.   if(type == 'username')
  25.     this.setState({username: event.target.value});
  26.   if(type == 'password')
  27.     this.setState({password: event.target.value});
  28. }
  29.  
  30.   handleSubmit(event) {
  31.     var username = this.state.username;
  32.     var password = this.state.password;
  33.     fetch('/auth' , {
  34.       method: 'POST',
  35.       credentials:'include',
  36.       headers:{
  37.         'Accept': 'application/json',
  38.         'Content-Type': 'application/json',
  39.       },
  40.       body: JSON.stringify(this.state)
  41.     })
  42.     .then(json =>{
  43.       if(json.sucess){
  44.         this.state({message: 'Logged in sucessfully',userdata: json.userdata, isloggedIn: true})
  45.       }
  46.       else{
  47.         this.setState({message:json.message})
  48.       }
  49.     })
  50.     .catch(e => {
  51.       this.setState({message: "Something went wrong! Try Again"})
  52.     })
  53.     event.preventDefault();
  54.   }
  55.  
  56.   render(){
  57.   return (
  58.     <div class="container" id="container">
  59.       <div class="nav-container headers-container">
  60.         <label>
  61.           <input type="checkbox" />
  62.           <span class="check"> </span>
  63.         </label>
  64.       </div>
  65.       <div class=" sss-container">
  66.         <div class=" profile-container">
  67.           <div class="wrapper">
  68.             <div class="profile-card js-profile-card">
  69.               <div class="form-container sign-in-container">
  70.                 <form>
  71.                   <h1>Sign in</h1>
  72.                   <span>use your instagram account</span>
  73.                   <input type="text" value={this.state.value} placeholder="Username" onChange={(e) => this.handleChange(e,'username')} />
  74.                   <input type="password" value={this.state.value} placeholder="Password" onChange={(e) => this.handleChange(e,'password')} />
  75.                   <input type="submit" onClick={this.handleSubmit} value="Submit" />
  76.                 </form>
  77.               </div>
  78.             </div>
  79.           </div>
  80.       </div>
  81.     </div>
  82.   </div>
  83.   );
  84. }
  85. }
  86.  
  87. export default InstaAuth;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement