Skip to content

Rishika #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: santan
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const express = require("express");
const passport = require('passport');
const router=require('./routes/auth_routes');
const router1=require('./routes/payment_routes');
const surveyRouter= require('./routes/servey');
const keys= require('./config/keys');
const passportSetup = require('./config/passport-setup');
const GoogleStrategy = require('passport-google-oauth20').Strategy;

const mongoose = require("mongoose");
const cors = require("cors");
Expand All @@ -11,7 +18,15 @@ app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());

app.use('/auth',router);
app.use('/payment',router1);


app.get('/',(req,res)=>{
res.send('sucess');
});
app.use("/api", authRoutes);
app.use('/create', surveyRouter);

app.listen(process.env.PORT || 2000, () => {
console.log("server running on port 2000");
Expand Down
6 changes: 6 additions & 0 deletions config/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports={
google:{
clientID: 'CLIENT_ID',
clientSecret: 'CLIENT_SECRET'
}
};
6 changes: 6 additions & 0 deletions config/keys_stripe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports={
stripe:{
PUBLISHABLE_KEY:'pk_test_51IyWvWSBus84JHp3FF2d9wrzVUVoNQpcLvMqL06ibfh7yVgcK7sJ7Txxl9l7sG8wsXBpsuve988GFvhrSdkXjtvs00zOhzuDiZ',
SECRET_KEY:'sk_test_51IyWvWSBus84JHp3yx38LYmP99jRqag35aakEBCFq46vMyGgdmSgdjIBJh93ncuNHyE69hdkQmQ8OBOGbaUIkDoE00ShqtMkDz'
}
};
29 changes: 29 additions & 0 deletions config/passport-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const keys= require('./keys');
const User=require('../models/user_oauth');
passport.use(new GoogleStrategy({
clientID:keys.google.clientID ,
clientSecret: keys.google.clientSecret,
callbackURL: "/auth/google/callback"
},(accessToken, refreshToken, profile, done)=> {
User.findOne({googleId: profile.id})
.then((currentuser)=>{
if(currentuser){
console.log('presnt');
done(null, currentuser);
}
else{
const user = new User({
googleId: profile.id
});
user.save()
.then((result)=>{
console.log('db created');
done(null, result);
})
}

});
}
));
36 changes: 36 additions & 0 deletions controllers/createservey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const User_ques = require('../models/userques');

const create_servey = (req,res)=>{
const user=new User(req.body);
user.save()
.then((value)=>{
res.redirect('/');
})
.catch((err)=>{
res.send(err);
})
});
const invite_user = (req,res)=>{
const title=req.params.title;
Customer.findOne({title})
.then((data)=>{
var mailOptions={
from:'[email protected]',
to:`${data.list}`,
subject:'regarding survey',
text:`http://localhost:7000/survey/${data._id}`
};
transporter.sendMail(mailOptions,(err,info)=>{
if(err)
{console.log(err);}
else
{res.send(info.response);}
})

})
};

module.exports ={
create_servey,
invite_user
};
9 changes: 9 additions & 0 deletions models/user_oauth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const db = new Schema({
googleId: {
type: String, required: true
}
});
const User = mongoose.model('User', db);
module.exports = User;
12 changes: 12 additions & 0 deletions routes/auth-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const router=require('express').Router();
router.get('/google',
passport.authenticate('google', { scope: ['profile'] }));

router.get('/google/callback',
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
module.exports=router;
2 changes: 1 addition & 1 deletion routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ router.post('/activate', verifyAccount)
router.post('/resetlink', resetlink)
router.post('/changepassword',changepassword)
router.post('/login',login)
module.exports = router;
module.exports = router;
31 changes: 31 additions & 0 deletions routes/payment_routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const keys= require('../config/keys_stripe');
const router=require('express').Router();
const path = require('path');
const PUBLISHABLE_KEY=keys.stripe.PUBLISHABLE_KEY;
const SECRET_KEY=keys.stripe.SECRET_KEY;
const stripe=require('stripe')(SECRET_KEY)
router.get('/',(req,res)=>{
res.render('payment',{key:PUBLISHABLE_KEY});
});
router.post('/',(req,res)=>{
stripe.customers.create({
email:req.body.stripeEmail,
source:req.body.stripeToken,
})
.then((customer)=>{
return stripe.charges.create({
amount:50,
description:'Add credits',
currency:'inr',
customer:customer.id
})
})
.then((charge)=>{
res.send('success');
})
.catch((err)=>{
res.send(err);
})
});


6 changes: 6 additions & 0 deletions routes/surveyRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const express = require('express');
const survey = require('../controllers/createservey')
const router = express.Router();
router.post('/createservey',create_survey);
router.get('/email/:title', invite_user);
module.exports = router;