Skip to content
Snippets Groups Projects
Commit fb7ad5e5 authored by Ashwanth K's avatar Ashwanth K
Browse files

Upload New File

parent 378aeafb
No related branches found
No related tags found
No related merge requests found
import React, { Component } from 'react';
import {Link,Redirect} from 'react-router-dom'
import '../pages.css'
import axios from 'axios';
class Slogin extends Component {
constructor(props) {
super(props);
this.login = this.login.bind(this);
this.handleChange = this.handleChange.bind(this);
this.state = {
user_id: '',
password: '',
rnd: 0,
user_name:''
};
}
handleChange(e) {
this.setState({ [e.target.name]: e.target.value });
}
login(e) {
axios.get('http://localhost:5000/user/'+ this.state.user_id.toString())
.then(response => {
if(response.data!==null){
if(response.data.password===this.state.password){
this.setState({rnd:1,user_name:response.data.name});
}
else window.alert("Invalid credentials");
}
else window.alert("Invalid user_id");
});
e.preventDefault();
}
render() {
if(this.state.rnd===0){
return (
<div>
<div className="topnav" id="myTopnav">
<Link to = '/'>Home</Link>
</div>
<h1 style={{color : "red",fontFamily : "fantasy"}}>Login as User</h1>
<div>
</div>
<div id="cred">
<form>
<div><label htmlfor="exampleInputuser_id1">User_id</label></div>
<input value={this.state.user_id} onChange={this.handleChange} type="text" name="user_id" class="form-control" id="exampleInputuser_id1" aria-describedby="user_idHelp" style={{width:"330px"}} placeholder="Enter user_id" />
<br/><br/>
<div><label htmlfor="exampleInputPassword1">Password</label></div>
<input value={this.state.password} onChange={this.handleChange} type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="Password" /><br/>
<button type="submit" onClick={this.login} class="btn btn-5">Login</button>
<br/>
</form>
</div>
<div style={{backgroundColor:'white',position:'absolute',right:'2%',top:'10%',width:'300px',textAlign:'center',borderRadius:'10px'}}>
<p>user_id : user1</p>
<p>password : 123456</p>
<p>user_id : user2</p>
<p>password : 123456</p>
<p>You can add further users from admin page.</p>
</div>
</div>
);
}
else{
return (
<Redirect to={"/Home/"+this.state.user_id+"/"+this.state.user_name}/>
);
}
}
}
export default Slogin;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment