routes/index.js


 

module.exports = function(app,app_secure,hasher){
  var nodemailer = require('nodemailer');
  var userController = require('./../routes/user.js');
  var passport = require('passport');
  var dotenv = require('dotenv');
  dotenv.load({ path: './.env' });
  /**
 * API keys and Passport configuration.
 */
  var passportConfig = require('./../config/passport');
  app.use(passport.initialize());
  app.use(passport.session());

  hasher.hash('ownerPassWord', function(err, salt, hash){
      if (err) throw err;
      // store the salt & hash in the "db"
      users.ownerUserId.salt = salt;
      users.ownerUserId.hash = hash;
    });


    // dummy database

    var users = {
      ownerUserId: { name: 'ownerUserId' }
    };
    var redirect_secure = function(req, res, next){

        if(app.get('server') == 'digital'){
            if(req.headers['x-forwarded-proto']=='https'){
                 res.redirect('https://' + req.header('Host') + req.url);
            }else{
                next();
            }
        }else{
            if(!req.secure){
                res.redirect('https://' + req.header('Host') + req.url);}
            else{
                next();
            }
        }

    }


    app.get('/partials/:name', function (req, res) {
        var name = req.params.name;
        res.render('site/partials/' + name);
    });

    app.get('/partials/account/:name', function (req, res) {
        var name = req.params.name;
        res.render('site/partials/account/' + name);
    });

  /*  app.get('/',function(req,res){
         if(req.secure){
            res.redirect('/spotit/adLogin');
        }else{
            res.redirect('/home');
        }
        res.redirect('/index');
    });
    */

    app.get('/',function (req, res, next) {
         res.render('site/indexsp.jade', { title: 'SpotDekho' });
    });

 /*   app.get('/contactus',function (req, res, next) {
         res.render('site/partials/contactus.jade', { title: 'SpotDekho' });
    });
*/
  var commonPaths = [
    '/contactus',
    '/termsofser','/privacypolicy',
    '/login','/forgot',
    '/signup','/account',
    '/account/profile','/account/password',
    '/account/delete','/listIndia',
    '/RegionWise','/aboutus'
  ];


  app.get(commonPaths, function (req, res) {

      var lo =  req.url;
      var baseUrl;
      if(lo.match(/contactus/g) && lo.match(/contactus/g).length>0){
      baseUrl = '/contactus';
      }else if(lo.match(/termsofser/g) && lo.match(/termsofser/g).length>0){
      baseUrl = '/termsofser';
      }else if(lo.match(/privacypolicy/g) && lo.match(/privacypolicy/g).length>0){
      baseUrl = '/privacypolicy';
      }else if(lo.match(/login/g) && lo.match(/login/g).length>0){
      baseUrl = '/login';
      }else if(lo.match(/forgot/g) && lo.match(/forgot/g).length>0){
      baseUrl = '/forgot';
      }else if(lo.match(/signup/g) && lo.match(/signup/g).length>0){
      baseUrl = '/signup';
      }else if(lo.match(/account/g) && lo.match(/account/g).length>0){
      baseUrl = '/account';
      }else if(lo.match(/\/account\/profile/g) && lo.match(/\/account\/profile/g).length>0){
      baseUrl = '/account/profile';
      }else if(lo.match(/\/account\/password/g) && lo.match(/\/account\/password/g).length>0){
      baseUrl = '/account/password';
      }else if(lo.match(/\/account\/delete/g) && lo.match(/\/account\/delete/g).length>0){
      baseUrl = '/account/delete';
      }else if(lo.match(/listIndia/g) && lo.match(/listIndia/g).length>0){
      baseUrl = '/listIndia';
      }else if(lo.match(/RegionWise/g) && lo.match(/RegionWise/g).length>0){
      baseUrl = '/RegionWise';
      }else if(lo.match(/\/aboutus\//g) && lo.match(/\/aboutus\//g).length>0){
      baseUrl = '/aboutus';
      }
        res.render('site/index.jade',{'baseUrl':baseUrl});
});


var secCommonPaths = [
    '/agra','/agra/*',
    '/andaman','/andaman/*',
    '/bengaluru','/bengaluru/*',
    '/chennai','/chennai/*',
    '/delhi','/delhi/*',
    '/goa','/goa/*',
    '/gurgaon','/gurgaon/*',
    '/hyderabad','/hyderabad/*',
    '/jaipur','/jaipur/*',
    '/kerala','/kerala/*',
    '/kolkata','/kolkata/*',
    '/lakshadweep','/lakshadweep/*',
    '/mumbai','/mumbai/*',
    '/noida','/noida/*',
    '/pune','/pune/*',
    '/surat','/surat/*',
    '/kashmir','/kashmir/*',
    '/puri','/puri/*',
    '/bhubaneshwar','/bhubaneshwar/*',
    '/sikkim','/sikkim/*',
    '/indore','/indore/*',
    '/ranchi','/ranchi/*',
    '/ahmedabad','/ahmedabad/*',
    '/guwahati','/guwahati/*',
    '/chandigarh','/chandigarh/*',
    '/varanasi','/varanasi/*',
    '/allahabad','/allahabad/*',
    '/bhopal','/bhopal/*',
    '/patna','/patna/*',
    '/visakhapatnam','/visakhapatnam/*',
    '/India','/India/*',
    '/USA','/USA/*',
    '/venues/:id','/offers/:id',
    '/subList/:id','/advertise-hotel-cab-restaurant-travel-packages',
    '/Advertise-hotels','/Advertise-restaurant',
    '/Advertise-cab-taxi','/Advertise-tour-travel-packages',
    '/add-tourist-spots'
];


app.get(secCommonPaths, function (req, res) {
        var lo =  req.url;
        var baseUrl;

        if(lo.match(/agra/g) && lo.match(/agra/g).length>0){
        baseUrl = '/agra';
        }else if(lo.match(/advertise-hotel-cab-restaurant-travel-packages/g) && lo.match(/advertise-hotel-cab-restaurant-travel-packages/g).length>0){
        baseUrl = '/advertise-hotel-cab-restaurant-travel-packages';
        }else if(lo.match(/Advertise-hotels/g) && lo.match(/Advertise-hotels/g).length>0){
        baseUrl = '/Advertise-hotels';
        }else if(lo.match(/Advertise-restaurant/g) && lo.match(/Advertise-restaurant/g).length>0){
        baseUrl = '/Advertise-restaurant';
        }else if(lo.match(/Advertise-cab-taxi/g) && lo.match(/Advertise-cab-taxi/g).length>0){
        baseUrl = '/Advertise-cab-taxi';
        }else if(lo.match(/Advertise-tour-travel-packages/g) && lo.match(/Advertise-tour-travel-packages/g).length>0){
        baseUrl = '/Advertise-tour-travel-packages';
        }else if(lo.match(/add-tourist-spots/g) && lo.match(/add-tourist-spots/g).length>0){
        baseUrl = '/add-tourist-spots';
        }else if(lo.match(/andaman/g) && lo.match(/andaman/g).length>0){
        baseUrl = '/andaman';
        }else if(lo.match(/bengaluru/g) && lo.match(/bengaluru/g).length>0){
        baseUrl = '/bengaluru';
        }else if(lo.match(/chennai/g) && lo.match(/chennai/g).length>0){
        baseUrl = '/chennai';
        }else if(lo.match(/delhi/g) && lo.match(/delhi/g).length>0){
        baseUrl = '/delhi';
        }else if(lo.match(/goa/g) && lo.match(/goa/g).length>0){
        baseUrl = '/goa';
        }else if(lo.match(/gurgaon/g) && lo.match(/gurgaon/g).length>0){
        baseUrl = '/gurgaon';
        }else if(lo.match(/hyderabad/g) && lo.match(/hyderabad/g).length>0){
        baseUrl = '/hyderabad';
        }else if(lo.match(/jaipur/g) && lo.match(/jaipur/g).length>0){
        baseUrl = '/jaipur';
        }else if(lo.match(/kolkata/g) && lo.match(/kolkata/g).length>0){
        baseUrl = '/kolkata';
        }else if(lo.match(/kerala/g) && lo.match(/kerala/g).length>0){
        baseUrl = '/kerala';
        }else if(lo.match(/lakshadweep/g) && lo.match(/lakshadweep/g).length>0){
        baseUrl = '/lakshadweep';
        }else if(lo.match(/mumbai/g) && lo.match(/mumbai/g).length>0){
        baseUrl = '/mumbai';
        }else if(lo.match(/noida/g) && lo.match(/noida/g).length>0){
        baseUrl = '/noida';
        }else if(lo.match(/pune/g) && lo.match(/pune/g).length>0){
        baseUrl = '/pune';
        }else if(lo.match(/surat/g) && lo.match(/surat/g).length>0){
        baseUrl = '/surat';
        }else if(lo.match(/kashmir/g) && lo.match(/kashmir/g).length>0){
        baseUrl = '/kashmir';
        }else if(lo.match(/puri/g) && lo.match(/puri/g).length>0){
        baseUrl = '/puri';
        }else if(lo.match(/bhubaneshwar/g) && lo.match(/bhubaneshwar/g).length>0){
        baseUrl = '/bhubaneshwar';
        }else if(lo.match(/sikkim/g) && lo.match(/sikkim/g).length>0){
        baseUrl = '/sikkim';
        }else if(lo.match(/indore/g) && lo.match(/indore/g).length>0){
        baseUrl = '/indore';
        }else if(lo.match(/ranchi/g) && lo.match(/ranchi/g).length>0){
        baseUrl = '/ranchi';
        }else if(lo.match(/ahmedabad/g) && lo.match(/ahmedabad/g).length>0){
        baseUrl = '/ahmedabad';
        }else if(lo.match(/guwahati/g) && lo.match(/guwahati/g).length>0){
        baseUrl = '/guwahati';
        }else if(lo.match(/chandigarh/g) && lo.match(/chandigarh/g).length>0){
        baseUrl = '/chandigarh';
        }else if(lo.match(/varanasi/g) && lo.match(/varanasi/g).length>0){
        baseUrl = '/varanasi';
        }else if(lo.match(/allahabad/g) && lo.match(/allahabad/g).length>0){
        baseUrl = '/allahabad';
        }else if(lo.match(/bhopal/g) && lo.match(/bhopal/g).length>0){
        baseUrl = '/bhopal';
        }else if(lo.match(/patna/g) && lo.match(/patna/g).length>0){
        baseUrl = '/patna';
        }else if(lo.match(/visakhapatnam/g) && lo.match(/visakhapatnam/g).length>0){
        baseUrl = '/visakhapatnam';
        }else if(lo.match(/USA/g) && lo.match(/USA/g).length>0){
        baseUrl = '/USA';
        }else if(lo.match(/India/g) && lo.match(/India/g).length>0){
        baseUrl = '/India';
        }else if(lo.match(/\/subList\//g) && lo.match(/\/subList\//g).length>0){
        baseUrl = '/subList';
        }else if(lo.match(/\/venues\//g) && lo.match(/\/venues\//g).length>0){
        baseUrl = '/venues';
        }else if(lo.match(/\/offers\//g) && lo.match(/\/offers\//g).length>0){
        baseUrl = '/offers';
      }
        res.render('site/varIndex.jade',{'baseUrl':baseUrl});
    });

    app.get('/admin/logout', function(req, res){
      // destroy the user's session to log them out
      // will be re-created next request
      req.session.destroy(function(){
        res.redirect('/spotit/adLogin');
      });
    });

    app.get('/spotitOffer',restrict,function(req, res) {
        var db = req.db;
        db.collection('venue').find().toArray(function (err, venue) {
              res.render('spotitOffer', { title: 'Offers' ,'venue':venue});
        });
    });

    app.get('/spotitPanel',restrict,function(req, res) {
      res.render('spotitPanel', { title: 'Partyy' });
    });

    app.get('/uploadPic',restrict,function(req, res) {
      res.render('uploadPic', { title: 'uploadPic' });
    });

    app.get('/spotitReview',restrict,function(req, res) {
      res.render('spotitReview', { title: 'Review' });
    });

    app.get('/spotitVenue',restrict, function(req, res) {
      res.render('spotitVenue', { title: 'Venues List' });
    });

    app.get('/spotitsubList',restrict, function(req, res) {
      res.render('spotitsubList', { title: 'Venues Sub List' });
    });

    app.get('/spotit/adLogin',redirect_secure,function(req, res) {
        res.render('spotitAdminLogin', { title: 'Sign In' });
    });

    app.post('/spotit/adLogin', function(req, res){
      authenticate(req.body.user, req.body.pass, function(err, user){
        if (user) {
          // Regenerate session when signing in
          // to prevent fixation
          req.session.regenerate(function(){
            // Store the user's primary key
            // in the session store to be retrieved,
            // or in this case the entire user object
            req.session.user = user;
            req.session.success = 'Authenticated as ' + user.name
              + ' click to <a href="/logout">logout</a>. '
              + ' You may now access <a href="/restricted">/restricted</a>.';
            res.redirect('/spotitPanel');

          });
        } else {
          req.session.error = 'Authentication failed, please check your '
            + ' username and password.' ;
          res.redirect('/spotit/adLogin');
        }
      });
    });

    // when you create a user, generate a salt


// Authenticate using our plain-object database of doom!

    function authenticate(name, pass, fn) {
      var user = users[name];
      // query the db for the given username
      if (!user) return fn(new Error('cannot find user'));
      // apply the same algorithm to the POSTed password, applying
      // the hash against the pass / salt, if there is a match we
      // found the user
      hasher.hash(pass, user.salt, function(err, hash){
        if (err) return fn(err);
        if (hash == user.hash) return fn(null, user);
        fn(new Error('invalid password'));
      });
    }

    function restrict(req, res, next) {
      if (req.session.user) {
        next();
      } else {
        req.session.error = 'Access denied!';
        res.redirect('/spotit/adLogin');
      }
    }
    /**
 * Primary app routes.
 */
    app.post('/login', userController.postLogin);
    app.get('/logout', userController.logout);
    app.post('/forgot', userController.postForgot);
    app.post('/reset/:token', userController.postReset);
    app.post('/signup', userController.postSignup);
    app.get('/account', passportConfig.isAuthenticated, userController.getAccount);
    app.post('/account/profile', passportConfig.isAuthenticated, userController.postUpdateProfile);
    app.post('/account/password', passportConfig.isAuthenticated, userController.postUpdatePassword);
    app.post('/account/delete', passportConfig.isAuthenticated, userController.postDeleteAccount);
    app.get('/account/unlink/:provider', passportConfig.isAuthenticated, userController.getOauthUnlink);
    app.get('/reset/:token', userController.getReset);
    app.post('/reset/:token', userController.postReset);

   /**
     * OAuth authentication routes. (Sign in)
     */
    app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] }));
    app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) {
      res.redirect(req.session.returnTo || '/');
    });
    app.get('/auth/google', passport.authenticate('google', { scope: 'profile email' }));
    app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/login' }), function(req, res) {
      res.redirect(req.session.returnTo || '/');
    });
    app.get('/auth/twitter', passport.authenticate('twitter'));
    app.get('/auth/twitter/callback', passport.authenticate('twitter', { failureRedirect: '/login' }), function(req, res) {
      res.redirect(req.session.returnTo || '/');
    });

    app.post('/contactus', function (req, res) {
      var mailOpts, smtpTrans;
      //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
      smtpTrans = nodemailer.createTransport('SMTP', {
        service: 'Gmail',
        auth: {
          user: "spotdekho@gmail.com",
          pass: "ufascxvzxcvsblhkn"
        }
      });
      //Mail options
      mailOpts = {
        from: req.body.name + req.body.email,
        to: 'spotdekho@gmail.com',
        subject: req.body.email + '  --Msg from TS contact-form',
        text: "Name: " + req.body.name + "    Email: "  + req.body.email + "    Contact No:  " + req.body.contactNo + "    QUERY: " + req.body.message
      };
      smtpTrans.sendMail(mailOpts, function (error, response) {
        //Alert on event of message sent succeeds or fail - at present this functionality is not working.
        if (error) {
          res.render('site/index.jade',{baseUrl : '/contactus', msg : 'Error occured, message not sent.', err : true});
        }
        else {
          res.render('site/index.jade',{baseUrl:'/contactus', msg : 'Message sent! Thank you.', err : false});
        }
        smtpTrans.close();
      });
    });

    app.post('/Advertise-hotels', function (req, res) {
      var mailOpts, smtpTrans;
      //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
      smtpTrans = nodemailer.createTransport('SMTP', {
        service: 'Gmail',
        auth: {
          user: "spotdekho@gmail.com",
          pass: "ufascxvzxcvsblhkn"
        }
      });
      //Mail options
      mailOpts = {
        from: req.body.name + req.body.email,
        to: 'spotdekho@gmail.com',
        subject: req.body.email + '  --Msg from Advertise hotels page',
        text: "Advertiser-Name: " + req.body.name + " Email: "  + req.body.email + " Contact No: " + req.body.contactnum +  " Property-name: " + req.body.propertyname +
              " propertytype: " + req.body.propertytype + " propcontactno: " + req.body.propcontactno + " property-address: " + req.body.address + " smalldesc: " + req.body.smalldesc +
              " detaildesc: " + req.body.detaildesc + " ppicurl: " + req.body.ppicurl + " proptiming: " + req.body.proptiming + " weblink: " + req.body.weblink + " sp-ad-page: " + req.body.spadpage
      };
      smtpTrans.sendMail(mailOpts, function (error, response) {
        //Alert on event of message sent succeeds or fail - at present this functionality is not working.
        if (error) {
          res.render('site/varIndex.jade',{baseUrl : '/Advertise-hotels', msg : 'Error occured, message not sent.', err : true});
        }
        else {
          res.render('site/varIndex.jade',{baseUrl:'/Advertise-hotels', msg : 'Thanks for submitting form, we will get back soon !', err : false});
        }
        smtpTrans.close();
      });
    });

    app.post('/Advertise-restaurant', function (req, res) {
      var mailOpts, smtpTrans;
      //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
      smtpTrans = nodemailer.createTransport('SMTP', {
        service: 'Gmail',
        auth: {
          user: "spotdekho@gmail.com",
          pass: "ufascxvzxcvsblhkn"
        }
      });
      //Mail options
      mailOpts = {
        from: req.body.name + req.body.email,
        to: 'spotdekho@gmail.com',
        subject: req.body.email + '  --Msg from advertise restaurant page',
        text: "Advertiser-Name: " + req.body.name + " Email: "  + req.body.email + " Contact No: " + req.body.contactnum +  " Property-name: " + req.body.propertyname +
              " propcontactno: " + req.body.propcontactno + " property-address: " + req.body.address + " smalldesc: " + req.body.smalldesc +
              " detaildesc: " + req.body.detaildesc + " ppicurl: " + req.body.ppicurl + " weblink: " + req.body.weblink + " sp-ad-page: " + req.body.spadpage
      };
      smtpTrans.sendMail(mailOpts, function (error, response) {
        //Alert on event of message sent succeeds or fail - at present this functionality is not working.
        if (error) {
          res.render('site/varIndex.jade',{baseUrl : '/Advertise-restaurant', msg : 'Error occured, message not sent.', err : true});
        }
        else {
          res.render('site/varIndex.jade',{baseUrl:'/Advertise-restaurant', msg : 'Thanks for submitting form, we will get back soon !', err : false});
        }
        smtpTrans.close();
      });
    });


    app.post('/Advertise-tour-travel-packages', function (req, res) {
      var mailOpts, smtpTrans;
      //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
      smtpTrans = nodemailer.createTransport('SMTP', {
        service: 'Gmail',
        auth: {
          user: "spotdekho@gmail.com",
          pass: "ufascxvzxcvsblhkn"
        }
      });
      //Mail options
      mailOpts = {
        from: req.body.name + req.body.email,
        to: 'spotdekho@gmail.com',
        subject: req.body.email + '  --Msg from TS advertise tour - travel pkgs',
        text: "Advertiser-Name: " + req.body.name + " Email: "  + req.body.email + " Contact No: " + req.body.contactnum +  " Property-name: " + req.body.propertyname +
              " propcontactno: " + req.body.propcontactno + " property-address: " + req.body.address + " smalldesc: " + req.body.smalldesc +
              " detaildesc: " + req.body.detaildesc + " ppicurl: " + req.body.ppicurl + " proptiming: " + req.body.proptiming + " weblink: " + req.body.weblink + " sp-ad-page: " + req.body.spadpage
      };
      smtpTrans.sendMail(mailOpts, function (error, response) {
        //Alert on event of message sent succeeds or fail - at present this functionality is not working.
        if (error) {
          res.render('site/varIndex.jade',{baseUrl : '/Advertise-tour-travel-packages', msg : 'Error occured, message not sent.', err : true});
        }
        else {
          res.render('site/varIndex.jade',{baseUrl:'/Advertise-tour-travel-packages', msg : 'Thanks for submitting form, we will get back soon !', err : false});
        }
        smtpTrans.close();
      });
    });

    app.post('/Advertise-cab-taxi', function (req, res) {
      var mailOpts, smtpTrans;
      //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
      smtpTrans = nodemailer.createTransport('SMTP', {
        service: 'Gmail',
        auth: {
          user: "spotdekho@gmail.com",
          pass: "ufascxvzxcvsblhkn"
        }
      });
      //Mail options
      mailOpts = {
        from: req.body.name + req.body.email,
        to: 'spotdekho@gmail.com',
        subject: req.body.email + '  --Msg from TS advertise cab taxi page',
        text: "Advertiser-Name: " + req.body.name + " Email: "  + req.body.email + " Contact No: " + req.body.contactnum +  " Property-name: " + req.body.propertyname +
              " propertytype: " + req.body.propertytype + " propcontactno: " + req.body.propcontactno + " property-address: " + req.body.address + " smalldesc: " + req.body.smalldesc +
              " detaildesc: " + req.body.detaildesc + " ppicurl: " + req.body.ppicurl + " weblink: " + req.body.weblink + " sp-ad-page: " + req.body.spadpage
      };
      smtpTrans.sendMail(mailOpts, function (error, response) {
        //Alert on event of message sent succeeds or fail - at present this functionality is not working.
        if (error) {
          res.render('site/varIndex.jade',{baseUrl : '/Advertise-cab-taxi', msg : 'Error occured, message not sent.', err : true});
        }
        else {
          res.render('site/varIndex.jade',{baseUrl:'/Advertise-cab-taxi', msg : 'Thanks for submitting form, we will get back soon !', err : false});
        }
        smtpTrans.close();
      });
    });


    app.post('/add-tourist-spots', function (req, res) {
      var mailOpts, smtpTrans;
      //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
      smtpTrans = nodemailer.createTransport('SMTP', {
        service: 'Gmail',
        auth: {
          user: "spotdekho@gmail.com",
          pass: "ufascxvzxcvsblhkn"
        }
      });
      //Mail options
      mailOpts = {
        from: req.body.username + req.body.useremail,
        to: 'spotdekho@gmail.com',
        subject: req.body.venuename + '  --Msg from TS add-spot page',
        text: "Venue-Name: " + req.body.venuename + " Venue-address: "  + req.body.venueadd + " Venue City: " + req.body.venuecity +  " Venue Desc: " + req.body.venuedesc +
              " Venue Timing: " + req.body.venuetiming + " Venue Contactno: " + req.body.venuecontactnum + " User Name: " + req.body.username + "  User Email add: " + req.body.useremail +
              " User Contact no.: " + req.body.usercontactnum + " UserID: " + req.body.userid
      };
      smtpTrans.sendMail(mailOpts, function (error, response) {
        //Alert on event of message sent succeeds or fail - at present this functionality is not working.
        if (error) {
          res.render('site/varIndex.jade',{baseUrl : '/add-tourist-spots', msg : 'Error occured, message not sent.', err : true});
        }
        else {
          res.render('site/varIndex.jade',{baseUrl:'/add-tourist-spots', msg : 'Thanks for submitting form, we will get back soon !', err : false});
        }
        smtpTrans.close();
      });
    });

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *