This file contains hidden or 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
| //invite route | |
| app.post("/invite", (req, res) => { | |
| let senderId = req.body.link, | |
| sendermsg = req.body.msg, | |
| receiverId = req.body.to, | |
| newLink = shortid.generate(); | |
| senderName = req.body.name; | |
| let current = new Date().toISOString() | |
| client.query( | |
| `INSERT INTO invitations (created_at,updated_at, link, senderId,sendermsg,senderName,receiverId) VALUES ('${current}','${current}','${newLink}','${senderId}','${sendermsg}','${senderName}','${receiverId}')`, |
This file contains hidden or 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
| //function to send invite | |
| function invite() { | |
| let sender = document.getElementById('currentUser').innerHTML; | |
| let link = document.getElementById('link').innerHTML; | |
| let inviteTo = document.getElementById('invite_mail').value; | |
| let message = document.getElementById('message').value; | |
| let name = document.getElementById('name').innerHTML; | |
| fetch('/invite', { | |
| method: 'POST', | |
| headers: { |
This file contains hidden or 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
| <script> | |
| //function to send invite | |
| function invite() { | |
| let sender = document.getElementById('currentUser').innerHTML; | |
| let link = document.getElementById('link').innerHTML; | |
| let inviteTo = document.getElementById('invite_mail').value; | |
| let message = document.getElementById('message').value; | |
| let name = document.getElementById('name').innerHTML; | |
| fetch('/invite', { | |
| method: 'POST', |
This file contains hidden or 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
| <div class="container"> | |
| <div class="jumbotron text-center"> | |
| <div style="float:right;"><a href="/logout" class="btn btn-default btn-sm">Logout</a></div> | |
| <h3> Welcome | |
| <span id="name"><%= name %></span> | |
| </h3> | |
| <p id="currentUser"><%= email %></p> | |
| <p>Your Invitation Code is: | |
| <span id="link"><%= link %></span> |
This file contains hidden or 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
| <!-- views/index.ejs --> | |
| <html> | |
| <head> | |
| <title>Node Authentication</title> | |
| <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
| <!-- load bootstrap css --> | |
| <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> | |
| <!-- load fontawesome --> | |
| <style> |
This file contains hidden or 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
| //after authentication - home route | |
| app.get("/home", isLoggedIn, (req, res) => { | |
| res.render("home", { | |
| name: req.user.rows[0].name, | |
| link: req.user.rows[0].link, | |
| email: req.user.rows[0].email | |
| }); | |
| }); | |
| //middleware for cheking logged in session |
This file contains hidden or 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
| app.use(passport.initialize()); | |
| app.use(passport.session()); | |
| passport.serializeUser((user, done) => done(null, user)); | |
| // Deserialize user from the sessions | |
| passport.deserializeUser((user, done) => done(null, user)); | |
| //passport middleware | |
| passport.use( | |
| new FacebookStrategy( | |
| { |
This file contains hidden or 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
| const { Client } = require("pg"); | |
| const client = new Client({ | |
| connectionString: process.env.DATABASE_URL, | |
| ssl: true | |
| }); | |
| //connection query and creation of tables | |
| client.connect(); | |
| const db_creation_string = `CREATE TABLE IF NOT EXISTS invitations(id SERIAL PRIMARY KEY, created_at TIMESTAMP, | |
| updated_at TIMESTAMP, link TEXT, senderId TEXT, sendermsg TEXT, senderName TEXT, | |
| receiverId TEXT); |
This file contains hidden or 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
| const express = require("express"); | |
| const app = express(); | |
| var session = require("express-session"); | |
| const path = require("path"); | |
| var passport = require("passport"); | |
| var shortid = require("shortid"); | |
| const FacebookStrategy = require("passport-facebook").Strategy; | |
| const bodyParser = require("body-parser"); | |
| var nodemailer = require("nodemailer"); | |
| //set our client folder and view |
This file contains hidden or 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
| { | |
| "name": "invitation", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "dependencies": { | |
| "axios": "^0.17.1", | |
| "body-parser": "^1.18.2", | |
| "cookie-session": "^2.0.0-beta.3", | |
| "ejs": "^2.5.7", |