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

Upload New File

parent 45eedcef
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 Admin from './admin-page';
import axois from 'axios';
class Alogin 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,
};
}
handleChange(e) {
this.setState({ [e.target.name]: e.target.value });
}
login(e) {
axois.get('http://localhost:5000/admin/'+ this.state.user_id.toString())
.then(response => {
if(response.data!==null){
if(response.data.password===this.state.password){
this.setState({rnd:1});
}
else window.alert("Invalid credentials");
}
else window.alert('Invalid Admin_id')
});
e.preventDefault();
}
render() {
if(this.state.rnd===0){
return (
<div>
<div class="topnav" id="myTopnav">
<Link to = '/'>Home</Link>
</div>
<h1 style={{color : "red",fontFamily : "fantasy"}}>Login as Admin</h1>
<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 for="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:'200px',textAlign:'center',borderRadius:'10px'}}>
<p>admin_id : admin</p>
<p>password : admin</p>
</div>
</div>
);
}
else{
return <Redirect to='/Admin'/>
}
}
}
export default Alogin;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment