-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kazirafi71
committed
May 4, 2021
1 parent
698b94c
commit a58bc8e
Showing
13 changed files
with
163 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SET__USER } from "./authTypes"; | ||
|
||
const init = { | ||
user: {}, | ||
}; | ||
|
||
const authReducer = (state = init, action) => { | ||
switch (action.type) { | ||
case SET__USER: | ||
return { | ||
user: action.payload, | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
|
||
export default authReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SET__USER='SET__USER' | ||
export const CLEAR__USER='CLEAR__USER' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { combineReducers } from "redux"; | ||
import authReducer from "./auth/authReducer"; | ||
|
||
|
||
const rootReducer=combineReducers({ | ||
auth: authReducer | ||
}) | ||
|
||
export default rootReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { applyMiddleware, createStore } from 'redux' | ||
import rootReducer from './rootReduer' | ||
import Thunk from 'redux-thunk' | ||
import { composeWithDevTools } from 'redux-devtools-extension'; | ||
|
||
const store=createStore(rootReducer,composeWithDevTools(applyMiddleware(Thunk))) | ||
|
||
export default store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
const AdminDashboard = () => { | ||
return ( | ||
<div> | ||
AdminDashboard | ||
</div> | ||
); | ||
}; | ||
|
||
export default AdminDashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import Styles from './login.module.css' | ||
import Styles from "./login.module.css"; | ||
import { Button, Container, Paper, Typography } from "@material-ui/core"; | ||
import React, { useEffect, useState } from "react"; | ||
import { Col, Form, Row } from "react-bootstrap"; | ||
import Alert_Comp from "../../components/Alert/Alert_Comp"; | ||
import Spinner_comp from "../../components/Spinner/Spinner_comp"; | ||
import Toast_Comp from "../../components/Toast/Toast_Comp"; | ||
import { Link, useHistory } from "react-router-dom"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
const Login = () => { | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
const [error, setError] = useState(); | ||
const [loading, setLoading] = useState(false); | ||
const [toast, setToast] = useState(false); | ||
const history = useHistory(); | ||
const [email, setEmail] = useState("[email protected]"); | ||
const [password, setPassword] = useState("123456"); | ||
const [error, setError] = useState(); | ||
const [loading, setLoading] = useState(false); | ||
const [toast, setToast] = useState(false); | ||
const history = useHistory(); | ||
const {user} = useSelector((state) => state.auth); | ||
//console.log(user); | ||
|
||
const dispatch = useDispatch(); | ||
|
||
|
||
const formSubmitHandler = (e) => { | ||
e.preventDefault(); | ||
setLoading(true); | ||
|
@@ -26,33 +29,52 @@ const Login = () => { | |
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
|
||
email, | ||
password, | ||
|
||
}), | ||
}) | ||
.then((res) => res.json()) | ||
.then((result) => { | ||
setLoading(false); | ||
console.log(result); | ||
// console.log(result); | ||
if (result.errors) { | ||
setError(result.errors); | ||
} else { | ||
dispatch({ type: "SET__USER", payload: result.userInfo }); | ||
localStorage.setItem("auth_token", result.token); | ||
localStorage.setItem("user", JSON.stringify(result.userInfo)); | ||
setToast(true); | ||
setError(null); | ||
// setTimeout(() => { | ||
// history.push("/"); | ||
// }, 3000); | ||
// clearTimeout(); | ||
// setError(null); | ||
// setTimeout(() => { | ||
// history.push("/"); | ||
// }, 3000); | ||
// clearTimeout(); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}; | ||
return ( | ||
<div style={{ fontFamily: "Poppins" }}> | ||
|
||
useEffect(() => { | ||
console.log(user) | ||
console.log(user.role) | ||
if(user && user.role=="Student") | ||
{ | ||
history.push('/') | ||
} | ||
else if(user && user.role==="Admin") | ||
{ | ||
history.push('/admin-dashboard') | ||
} | ||
else if(user && user.role==="Teacher") | ||
{ | ||
history.push('/teacher-dashboard') | ||
} | ||
|
||
}, [user]); | ||
return ( | ||
<div style={{ fontFamily: "Poppins" }}> | ||
<Container> | ||
<Toast_Comp | ||
setToast={setToast} | ||
|
@@ -74,10 +96,10 @@ const Login = () => { | |
)} | ||
|
||
<Form onSubmit={formSubmitHandler}> | ||
|
||
<Form.Group controlId="formBasicEmail"> | ||
<Form.Label>Email address</Form.Label> | ||
<Form.Control | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
type="email" | ||
placeholder="Enter email" | ||
|
@@ -87,6 +109,7 @@ const Login = () => { | |
<Form.Group controlId="formBasicPassword"> | ||
<Form.Label>Password</Form.Label> | ||
<Form.Control | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
type="password" | ||
placeholder="Password" | ||
|
@@ -95,7 +118,7 @@ const Login = () => { | |
{error && error.password} | ||
</span> | ||
</Form.Group> | ||
|
||
<Typography style={{ color: "GrayText" }} variant="subtitle2"> | ||
Don't Have an account? | ||
<Link to="/register">Register Here</Link> | ||
|
@@ -114,7 +137,7 @@ const Login = () => { | |
</Row> | ||
</Container> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
export default Login; | ||
export default Login; |
11 changes: 11 additions & 0 deletions
11
client/src/pages/Teacher/TeacherDashboard/TeacherDashboard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
const TeacherDashboard = () => { | ||
return ( | ||
<div> | ||
TeacherDashboard | ||
</div> | ||
); | ||
}; | ||
|
||
export default TeacherDashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters