From fb7ad5e542e88502ea6099f43333bc9f51aa1451 Mon Sep 17 00:00:00 2001 From: Ashwanth K <cb.en.u4cse19305@cb.students.amrita.edu> Date: Sun, 27 Dec 2020 20:18:32 +0530 Subject: [PATCH] Upload New File --- .../src/Components/Student(User)/slogin.jsx | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 client/src/Components/Student(User)/slogin.jsx diff --git a/client/src/Components/Student(User)/slogin.jsx b/client/src/Components/Student(User)/slogin.jsx new file mode 100644 index 0000000..9f237f5 --- /dev/null +++ b/client/src/Components/Student(User)/slogin.jsx @@ -0,0 +1,79 @@ +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; -- GitLab