-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Naresh-chandanbatve/main
added sessions integration and remaining schemas
- Loading branch information
Showing
16 changed files
with
218 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -60,6 +60,7 @@ sysinfo.txt | |
*.aab | ||
*.unitypackage | ||
*.app | ||
dist/ | ||
|
||
#server files | ||
node_modules/ | ||
|
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,3 +1,4 @@ | ||
node_modules/ | ||
*.env | ||
.env | ||
.env | ||
dist/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,31 @@ | ||
import jwt from 'jsonwebtoken' | ||
|
||
const indexController = async (req, res) => { | ||
res.status(200).json({message:"Arrow Server is running..."}) | ||
|
||
/** | ||
* check if there is already any session | ||
* if yes get the session data and login | ||
* else redirect to landing page | ||
*/ | ||
if(req.session.user){ | ||
|
||
let isTokenValid = jwt.decode(req.session.user.token) | ||
if(isTokenValid){ | ||
res.status(200).json({ | ||
success: true, | ||
user: req.session.user, | ||
msg: req.session.user.user.name +" is logged in successfully" | ||
}); | ||
} | ||
|
||
} | ||
else{ | ||
//show landing page | ||
res.status(200).json({message:"Arrow Server is running..."}) | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
export default indexController; |
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,29 @@ | ||
import jwt from "jsonwebtoken" | ||
|
||
const SECRET = process.env.ADMIN_SECRET | ||
|
||
const authAdmin = (req, next) => { | ||
|
||
try { | ||
const token = req.headers.authprization.split(" ")[1] | ||
const isCustomAuth = token.lenght < 500 | ||
|
||
let decodedData | ||
if(token && isCustomAuth){ | ||
decodedData = jwt.verify(token, SECRET) | ||
req.userId = decodedData?.id | ||
} | ||
else{ | ||
decodedData = jwt.decode(token) | ||
req.userId = decodedData?.sub | ||
} | ||
|
||
next() | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
|
||
} | ||
|
||
|
||
export default authAdmin |
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,19 @@ | ||
import express from "express" | ||
import session from 'express-session' | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
|
||
const app = express(); | ||
app.use(session({ | ||
secret: process.env.SESSION_SECRET, | ||
resave: false, | ||
saveUninitialized: false | ||
}, | ||
(next)=>{ | ||
next() | ||
} | ||
)) | ||
|
||
export default app | ||
|
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,19 @@ | ||
import mongoose from "mongoose"; | ||
|
||
|
||
//estimated user schema | ||
const userFacultyModel = mongoose.Schema({ | ||
id: { type: String }, | ||
name: { type: String, required: true }, | ||
branch: { type: String, required: true }, | ||
email: { type: String, required: true }, | ||
password: { type: String, required: true }, | ||
subjects: { type: String, required: true }, | ||
designation: { type: String, required: true }, | ||
education: { type: String, required: true }, | ||
bio: { type: String }, | ||
intrest: { type: String } | ||
|
||
}) | ||
|
||
export default mongoose.model("userFaculties",userFacultyModel); |
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,14 @@ | ||
import mongoose from "mongoose"; | ||
|
||
|
||
//estimated user schema | ||
const userGuestModel = mongoose.Schema({ | ||
id: { type: String }, | ||
name: { type: String, required: true }, | ||
email: { type: String, required: true }, | ||
password: { type: String, required: true }, | ||
bio: { type: String, required: true }, | ||
|
||
}) | ||
|
||
export default mongoose.model("userGuests", userGuestModel); |
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,17 @@ | ||
import mongoose from "mongoose"; | ||
|
||
|
||
//estimated user schema | ||
const userStaffModel = mongoose.Schema({ | ||
id: { type: String }, | ||
name: { type: String, required: true }, | ||
branch: { type: String, required: true }, | ||
email: { type: String, required: true }, | ||
password: { type: String, required: true }, | ||
designation: { type: String, required: true }, | ||
bio: { type: String }, | ||
mobile: { type: Number } | ||
|
||
}) | ||
|
||
export default mongoose.model("userStaffs",userStaffModel); |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import express from 'express'; | ||
import session from '../middlewares/session.js'; | ||
const router = express.Router(); | ||
|
||
import indexController from "../controllers/index.js"; | ||
|
||
|
||
router.get("/", indexController) | ||
router.get("/", session, indexController) | ||
|
||
export default router; |
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,11 +1,13 @@ | ||
import express from 'express'; | ||
import session from '../middlewares/session.js' | ||
|
||
const router = express.Router(); | ||
|
||
import {userAdmin, signup, signin} from "../controllers/userAdmin.js"; | ||
|
||
|
||
router.get("/", userAdmin) | ||
router.post("/signup", signup) | ||
router.post("/signin", signin) | ||
router.post("/signin", session, signin) | ||
|
||
export default router; |
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,11 +1,12 @@ | ||
import express from 'express'; | ||
const router = express.Router(); | ||
import session from '../middlewares/session.js'; | ||
|
||
import {userStudent, signup, signin} from "../controllers/userStudent.js"; | ||
|
||
|
||
router.get("/", userStudent) | ||
router.post("/signup", signup) | ||
router.post("/signin", signin) | ||
router.post("/signin",session, signin) | ||
|
||
export default router; |