Skip to content

Commit

Permalink
Merge pull request #1 from OmSingh5092/master
Browse files Browse the repository at this point in the history
Made registration screen
  • Loading branch information
Tanay5175 authored Oct 6, 2020
2 parents e8bc5c9 + 7913f73 commit fd9b42c
Show file tree
Hide file tree
Showing 49 changed files with 4,589 additions and 24 deletions.
1 change: 1 addition & 0 deletions Backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
25 changes: 25 additions & 0 deletions Backend/App.js
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");
})
34 changes: 34 additions & 0 deletions Backend/config.js
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;
38 changes: 38 additions & 0 deletions Backend/controllers/profileCtrl.js
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};
75 changes: 75 additions & 0 deletions Backend/controllers/signInCtrl.js
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};
12 changes: 12 additions & 0 deletions Backend/database/database.js
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;
33 changes: 33 additions & 0 deletions Backend/database/schema/interviewer.js
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);
5 changes: 5 additions & 0 deletions Backend/middlewares/verifyMW.js
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}
Loading

0 comments on commit fd9b42c

Please sign in to comment.