-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from OmSingh5092/master
Made registration screen
- Loading branch information
Showing
49 changed files
with
4,589 additions
and
24 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
const config = require('./config'); | ||
const database = require('./database/database'); | ||
const session = require('express-session'); | ||
const cors = require('cors'); | ||
|
||
require('./passport'); | ||
|
||
//Applying middlewares | ||
app.use(express.json()); | ||
app.use(session(config.session)); | ||
app.use(cors()); | ||
|
||
//Importing rotues | ||
const signInRoute = require('./routes/signinRouter'); | ||
const profileRoute =require('./routes/profileRouter'); | ||
|
||
//Applying routes | ||
app.use('/api/signin',signInRoute); | ||
app.use('/api/profile',profileRoute); | ||
|
||
app.listen(config.app.local.port, ()=>{ | ||
console.log("\n\n App listening... \n\n"); | ||
}) |
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,34 @@ | ||
const config = { | ||
app:{ | ||
local:{ | ||
port: 8000, | ||
} | ||
}, | ||
session:{ | ||
// It holds the secret key for session | ||
secret: 'Your_Secret_Key', | ||
// Forces the session to be saved | ||
// back to the session store | ||
resave: true, | ||
// Forces a session that is "uninitialized" | ||
// to be saved to the store | ||
saveUninitialized: true | ||
}, | ||
jwt:{ | ||
TOKEN_SECRET:"OmSingh" | ||
}, | ||
database:{ | ||
local:{ | ||
uri:"mongodb://localhost:27017/CodeView" | ||
}, | ||
prod:{ | ||
|
||
} | ||
}, | ||
gcp:{ | ||
clientId: "41880489918-ff5sebqstbkdjru2po7gmgsepqhnuio7.apps.googleusercontent.com", | ||
clientSecret:"-1JWDbVE3ytYo5_qpXwPYHje" | ||
}, | ||
} | ||
|
||
module.exports = config; |
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,38 @@ | ||
const Interviewer = require('../database/schema/interviewer'); | ||
|
||
const getProfile = async (req,res)=>{ | ||
const id = req.user.id; | ||
|
||
try{ | ||
const profile = await Interviewer.findOne({id:id}); | ||
|
||
return res.status(200).json({ | ||
success:true, | ||
profile:profile, | ||
}) | ||
}catch(err){ | ||
console.log("Error",err); | ||
return res.status(500).json({ | ||
success:false, | ||
msg:"Internal Server Error", | ||
}) | ||
} | ||
} | ||
|
||
const updateProfile = (req,res) =>{ | ||
const id = req.user | ||
Interviewer.updateOne({id:id},req.body) | ||
.then((doc)=>{ | ||
return res.status(200).json({ | ||
success:true, | ||
update:doc, | ||
}) | ||
}).catch((err)=>{ | ||
return res.status(500).json({ | ||
success:false, | ||
msg:"Update not possible", | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = {getProfile,updateProfile}; |
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,75 @@ | ||
const { OAuth2Client } = require('google-auth-library'); | ||
const jwt = require('jsonwebtoken'); | ||
const config = require('../config'); | ||
|
||
const Interviewer = require('../database/schema/interviewer'); | ||
const googleSignIn= async (req,res)=>{ | ||
const idToken = req.body.idToken; | ||
const client = new OAuth2Client(config.gcp.clientId); | ||
|
||
if(idToken == null){ | ||
return res.json({ | ||
success:false, | ||
message:"Token not found" | ||
}) | ||
} | ||
|
||
const ticket = await client.verifyIdToken({ | ||
idToken:idToken, | ||
audience:config.gcp.clientId, | ||
}); | ||
|
||
const payload = ticket.getPayload(); | ||
const userEmail = payload['email']; | ||
const userName = payload['name']; | ||
|
||
const authData = { | ||
email: userEmail, | ||
name: userName, | ||
} | ||
|
||
try{ | ||
const document = await Interviewer.findOne({email:userEmail}); | ||
console.log("User Exists") | ||
authData.id = document.id; | ||
const token = jwt.sign(authData,config.jwt.TOKEN_SECRET); | ||
return res.status(200).json({ | ||
success:true, | ||
newUser:false, | ||
jwt:token | ||
}) | ||
} | ||
catch(err){ | ||
console.log("error",err); | ||
console.log("User doesnot exists"); | ||
const interviewer = new Interviewer({ | ||
name:userName, | ||
email:userEmail, | ||
}) | ||
interviewer.save() | ||
.then((data)=>{ | ||
authData.id = data.id; | ||
const token = jwt.sign(authData,config.jwt.TOKEN_SECRET); | ||
return res.status(200).json({ | ||
success:true, | ||
newUser:true, | ||
jwt: token | ||
}) | ||
}) | ||
.catch((err)=>{ | ||
console.log(err); | ||
return res.status(500).json({ | ||
success:false, | ||
msg:"Internal server error", | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
const emailSignIn = (req,res)=>{ | ||
|
||
} | ||
|
||
|
||
|
||
module.exports = {googleSignIn,emailSignIn}; |
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,12 @@ | ||
const mongoose = require('mongoose'); | ||
const config = require('../config'); | ||
|
||
mongoose.connect(config.database.local.uri); | ||
|
||
const connection = mongoose.connection; | ||
|
||
connection.once("open",function(){ | ||
console.log("\n\nMongoose connection successfull\n\n"); | ||
}); | ||
|
||
module.exports = connection; |
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,33 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const interviewer = new Schema( | ||
{ | ||
name:{ | ||
type:String | ||
}, | ||
email:{ | ||
type:String | ||
}, | ||
phone:{ | ||
type:Number | ||
}, | ||
company:{ | ||
type:String | ||
}, | ||
website:{ | ||
type:String, | ||
}, | ||
photo:{ | ||
type:String, | ||
} | ||
},{ | ||
timestamps:true | ||
}, | ||
{ | ||
collection:"interviewers" | ||
} | ||
) | ||
|
||
module.exports = mongoose.model("interviewer",interviewer); |
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,5 @@ | ||
var passport = require('passport'); | ||
|
||
const user = passport.authenticate('jwt', { session: false }); | ||
|
||
module.exports = {user} |
Oops, something went wrong.