Skip to content

Commit

Permalink
Merge pull request #24 from abhiram2600/master
Browse files Browse the repository at this point in the history
fixed login issue
  • Loading branch information
bsaikiran618 authored Jun 17, 2020
2 parents e3d83aa + ad9f296 commit 73f4494
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 86 deletions.
45 changes: 44 additions & 1 deletion backend/validkeys.json
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
{"dummy":"dummyval","codingStudio":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.Y29kaW5nU3R1ZGlv.GBhRWeGSZGxpkK6j9m3eX4f_WObnR0pYl9rMum45sFE","userType":"FORUM"},"17P61A0596":"eyJhbGciOiJIUzI1NiJ9.MTdQNjFBMDU5Ng.azCUBLRWn2091kJITCohCYQT3ukol-t2CDBcJkFGTf4","stumagz":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.c3R1bWFneg.RjCpnTu611-dPJPSDP1iyOFjvnLRPn49JEn5tQhp2bw","userType":"FORUM"},"saikiran":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.c2Fpa2lyYW4.dwns7EmnfJ-TZDOMvk1xl53zx75RD-kBlw87OD4cAFs","userType":"FORUM"},"Stutalk":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.U3R1dGFsaw.jIS1zPQW-LpPqHFNJWpyoy0cUgSnSk0IdGUdcbmwoYk","userType":"FORUM"},"17p61a0584":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.MTdwNjFhMDU4NA.xtokuKplZMtmJ_GKjK61QR5UZV9fLqNLtTA6LSQKDbs","userType":"FACULTY"},"STUTALK":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.U1RVVEFMSw.wC24KmKQmiWiVJha_ATQHl1WqaOuLkrrcLosofswyqw","userType":"FORUM"},"IEEE":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.SUVFRQ.yWyuU7C1-qXerxcOBV2x205uAIqwTqWrSCkDaWiiSpE","userType":"FORUM"},"STREETCAUSE":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.U1RSRUVUQ0FVU0U.vPLRw-KYpZXqSD4bgrJb4_-ipsoMU0-H9SRlEq9VDoc","userType":"FORUM"},"CODINGSTUDIO":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.Q09ESU5HU1RVRElP.xPXSKV8gyEmY1X4pcqorKxmDcGAkCPrSCRLS6JlqeTc","userType":"FORUM"},"CODING.STUDIO();":{"accessToken":"eyJhbGciOiJIUzI1NiJ9.Q09ESU5HLlNUVURJTygpOw.Xb0O-f-86_LRrhzLWIH4f-gmdlAty1ruoYpgaUJIqvY","userType":"FORUM"}}
{
"dummy": "dummyval",
"codingStudio": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.Y29kaW5nU3R1ZGlv.GBhRWeGSZGxpkK6j9m3eX4f_WObnR0pYl9rMum45sFE",
"userType": "FORUM"
},
"17P61A0596": "eyJhbGciOiJIUzI1NiJ9.MTdQNjFBMDU5Ng.azCUBLRWn2091kJITCohCYQT3ukol-t2CDBcJkFGTf4",
"stumagz": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.c3R1bWFneg.RjCpnTu611-dPJPSDP1iyOFjvnLRPn49JEn5tQhp2bw",
"userType": "FORUM"
},
"saikiran": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.c2Fpa2lyYW4.dwns7EmnfJ-TZDOMvk1xl53zx75RD-kBlw87OD4cAFs",
"userType": "FORUM"
},
"Stutalk": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.U3R1dGFsaw.jIS1zPQW-LpPqHFNJWpyoy0cUgSnSk0IdGUdcbmwoYk",
"userType": "FORUM"
},
"17p61a0584": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.MTdwNjFhMDU4NA.xtokuKplZMtmJ_GKjK61QR5UZV9fLqNLtTA6LSQKDbs",
"userType": "FACULTY"
},
"STUTALK": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.U1RVVEFMSw.wC24KmKQmiWiVJha_ATQHl1WqaOuLkrrcLosofswyqw",
"userType": "FORUM"
},
"IEEE": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.SUVFRQ.yWyuU7C1-qXerxcOBV2x205uAIqwTqWrSCkDaWiiSpE",
"userType": "FORUM"
},
"STREETCAUSE": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.U1RSRUVUQ0FVU0U.vPLRw-KYpZXqSD4bgrJb4_-ipsoMU0-H9SRlEq9VDoc",
"userType": "FORUM"
},
"CODINGSTUDIO": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.Q09ESU5HU1RVRElP.xPXSKV8gyEmY1X4pcqorKxmDcGAkCPrSCRLS6JlqeTc",
"userType": "FORUM"
},
"CODING.STUDIO();": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9.Q09ESU5HLlNUVURJTygpOw.Xb0O-f-86_LRrhzLWIH4f-gmdlAty1ruoYpgaUJIqvY",
"userType": "FORUM"
}
}
14 changes: 7 additions & 7 deletions react/src/helpers/DashboardRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ const DashboardRoutes = () => {
if (type == "FACULTY")
return (
<div>
<ProtectedRoute exact path="/dashboard" component={Dashboard} />
<ProtectedRoute path="/dashboard" component={Dashboard} />
<ProtectedRoute
path="/Dashboard/TemplateDetails"
path="/dashboard/TemplateDetails"
component={TemplateDetails}
/>
<ProtectedRoute path="/Remarks" component={Remarks} />
<ProtectedRoute
path="/Dashboard/TemplateList"
path="/dashboard/TemplateList"
component={TemplateList}
/>

Expand All @@ -62,14 +62,14 @@ const DashboardRoutes = () => {

return (
<div>
<ProtectedRoute exact path="/dashboard" component={Dashboard} />
<ProtectedRoute path="/dashboard" component={Dashboard} />
<ProtectedRoute
path="/Dashboard/TemplateDetails"
path="/dashboard/TemplateDetails"
component={TemplateDetails}
/>
<ProtectedRoute path="/Remarks" component={Remarks} />
<ProtectedRoute path="/Dashboard/AddTemplate" component={AddTemplate} />
<ProtectedRoute path="/Dashboard/TemplateList" component={TemplateList} />
<ProtectedRoute path="/dashboard/AddTemplate" component={AddTemplate} />
<ProtectedRoute path="/dashboard/TemplateList" component={TemplateList} />
<ProtectedRoute path="/ViewStatus" component={ViewStatus} />
<ProtectedRoute path="/profile" component={ForumProfile} />
</div>
Expand Down
47 changes: 24 additions & 23 deletions react/src/helpers/ProtectedRoute.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import React from 'react';
import {Route, Redirect} from 'react-router-dom';
import React from "react";
import { Route, Redirect } from "react-router-dom";

export const ProtectedRoute = ({component:Component, ...rest}) => {
var user = JSON.parse(localStorage.getItem("user"));
console.log(user);
export function ProtectedRoute({ component: Component, ...rest }) {
return (
<Route {...rest}
render={
(props) => {
if(user!==null){
return <Component {...props} />;
}
else{
return <Redirect to={
{
pathname:"/",
state: {
from:props.location
}
}
}/>;
}
}
}/>
<div>
<Route
{...rest}
render={(props) => {
if (JSON.parse(localStorage.getItem("user"))) {
return <Component {...props} />;
} else {
return (
<Redirect
to={{
pathname: "/",
state: {
from: props.location,
},
}}
/>
);
}
}}
/>
</div>
);
}
1 change: 1 addition & 0 deletions react/src/modules/Auth/LandingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const LandingPage = () => {
e.preventDefault();
history.push("/");
};

return (
<div className="all-items">
<br />
Expand Down
124 changes: 69 additions & 55 deletions react/src/modules/Auth/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ const Login = () => {
console.log(err);
});
}, []);

const ss = (userName, accessToken, callback) => {
localStorage.setItem(
"user",
JSON.stringify({
userName: userName,
accessToken: accessToken,
})
);
return callback();
};

const handleLogin = (e) => {
e.preventDefault();
let un = value;
Expand All @@ -48,14 +60,11 @@ const Login = () => {
console.log("fdf");
let userName = res.data.message.split(" ")[1];
let accessToken = res.data.accessToken;
localStorage.setItem(
"user",
JSON.stringify({
userName: userName,
accessToken: accessToken,
})
);
history.push("/dashboard");
ss(userName, accessToken, () => {
history.push("/dashboard");
}); //history.push("/dashboard"));
// localStorage.setItem("user", JSON.stringify(res.data));
// history.push("/dashboard");
} else {
let errors = res.data.err;
setError(errors);
Expand All @@ -69,24 +78,32 @@ const Login = () => {
};
const userType = "FORUM";
return (
<div className="forms">
<form>
<h1 style={{ color: "white" }}> Forum login </h1>
<br/>
<div className="container">
<div className="form-group login-row row">
<div className="col-md login-text"><h4 style={{paddingTop:"3%" }}>Forum : </h4></div>
<div className="col-md"><select
className="login-dropdown round"
style={{margin:0}}
name="value"
onChange={(e) => ForumChangeHandler(e)}
>
{ForumList.map((club) => (<option> {club.actual_name} </option>))}
</select></div>
</div>
<div className="form-group login-row row">
<div className="col-md login-text"><h4 style={{paddingTop:"3%" }}>Password : </h4></div>
<div className="forms">
<form>
<h1 style={{ color: "white" }}> Forum login </h1>
<br />
<div className="container">
<div className="form-group login-row row">
<div className="col-md login-text">
<h4 style={{ paddingTop: "3%" }}>Forum : </h4>
</div>
<div className="col-md">
<select
className="login-dropdown round"
style={{ margin: 0 }}
name="value"
onChange={(e) => ForumChangeHandler(e)}
>
{ForumList.map((club) => (
<option> {club.actual_name} </option>
))}
</select>
</div>
</div>
<div className="form-group login-row row">
<div className="col-md login-text">
<h4 style={{ paddingTop: "3%" }}>Password : </h4>
</div>
<div className="col-md">
<input
type="password"
Expand All @@ -96,38 +113,35 @@ const Login = () => {
onChange={(e) => setPassword(e.target.value)}
/>
</div>
</div>
<div className="row">
<button
className="btn btn-link"
style={{ color: "#cc00ff" }}
onClick={() => setModalShow(true)}
type="button"
>
Forgot Password
</button>
</div>
</div>
<div className="row">
<button
className="btn btn-link"
style={{ color: "#cc00ff" }}
onClick={() => setModalShow(true)}
type="button"
>
Forgot Password
</button>
</div>
</div>

<br/>
<button className="buttonpurple" onClick={handleLogin} type="submit">
Login
</button>
<br />
<button className="buttonpurple" onClick={handleLogin} type="submit">
Login
</button>

<h4 style={{ color: "#ff1744" }}>{error} </h4>
<Link
to={"/register"}
style={{ color: "#00e676" }}
>
Go to Forum Registration Page
</Link>
</form>
<ForgotPasswordForum
userType={userType}
show={modalShow}
onHide={() => setModalShow(false)}
/>
</div>
<h4 style={{ color: "#ff1744" }}>{error} </h4>
<Link to={"/register"} style={{ color: "#00e676" }}>
Go to Forum Registration Page
</Link>
</form>
<ForgotPasswordForum
userType={userType}
show={modalShow}
onHide={() => setModalShow(false)}
/>
</div>
);
};

Expand Down

0 comments on commit 73f4494

Please sign in to comment.