diff --git a/account/package.json b/account/package.json index 43a3834..4a3eacc 100644 --- a/account/package.json +++ b/account/package.json @@ -47,6 +47,7 @@ "mongoose": "5.11.10", "node-mailjet": "3.3.1", "passport": "0.4.1", - "passport-local": "1.0.0" + "passport-local": "1.0.0", + "passport-twitter": "1.0.4" } } diff --git a/account/server/config/passport-strategies/twitter.js b/account/server/config/passport-strategies/twitter.js new file mode 100644 index 0000000..68a4039 --- /dev/null +++ b/account/server/config/passport-strategies/twitter.js @@ -0,0 +1,19 @@ +var Strategy = require('passport-twitter').Strategy; +const User = require("../../models/user"); + +const twitter = new Strategy({ + consumerKey: process.env['TWITTER_CONSUMER_KEY'], + consumerSecret: process.env['TWITTER_CONSUMER_SECRET'], + callbackURL: '/oauth/callback', + proxy: trustProxy + }, + function(token, tokenSecret, profile, cb) { + // In this example, the user's Twitter profile is supplied as the user + // record. In a production-quality application, the Twitter profile should + // be associated with a user record in the application's database, which + // allows for account linking and authentication with other identity + // providers. + return cb(null, profile); + }) + + module.exports = local; \ No newline at end of file diff --git a/account/server/config/passport.js b/account/server/config/passport.js index ea3b8d9..74c917e 100644 --- a/account/server/config/passport.js +++ b/account/server/config/passport.js @@ -1,6 +1,7 @@ /* Initializing PassportJS */ const User = require("../models/user"); const local = require("./passport-strategies/local"); +const twitter = require("./passport-strategies/twitter"); module.exports = function (app, passport) { // Configure Passport authenticated session persistence. diff --git a/backend/index.js b/backend/index.js index dd9e2ff..740fbe3 100644 --- a/backend/index.js +++ b/backend/index.js @@ -32,6 +32,7 @@ const server = require('http').createServer(app); const io = require('socket.io')(server, {}); +var Twitter = require('twitter-lite'); io.origins('*:*'); @@ -50,6 +51,23 @@ io.on('connection', function(socket){ }); }); + +const client = new Twitter({ + subdomain: "api", // "api" is the default (change for other subdomains) + version: "1.1", // version "1.1" is the default (change for other subdomains) + consumer_key: process.env.TWITTER_CONSUMER_KEY, // from Twitter. + consumer_secret: process.env.TWITTER_CONSUMER_SECRET, // from Twitter. + access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY, // from your User (oauth_token) + access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET // from your User (oauth_token_secret) +}); + +client + .get("account/verify_credentials") + .then(results => { + console.log("results", results); + }) + .catch(console.error); + function getRole(req) { if (req.params.shortName && req.user) { var short_name = req.params.shortName.toLowerCase(); @@ -156,8 +174,19 @@ app.post('/:shortName/star/:id', calls.add_star, function(req,res) { /*------ UPLOADS ---------- upload.single('call'), uploads.upload,*/ -app.post('/:shortName/upload', upload.single('call'), uploads.upload, function(req,res) { +app.post('/:shortName/upload', upload.single('call'), uploads.upload, async function(req,res) { notify_clients(req.call); + if ((req.call.shortName=="dcfd") && (req.call.talkgroupNum==101)) { + var call_time = new Date(req.call.time); + var call_link = "https://openmhz.com/system/dcfd?call-id=" + req.call._id + "&time=" + call_time.getTime(); + + var call_time_label = call_time.toLocaleDateString() + " " + call_time.toLocaleTimeString() + var status = req.call.len +" sec transmission\n" + call_time_label + "\n" + call_link; + const response = await client.post('statuses/update', { + status: status, + }); + //console.log("Tweet Response: " + response); + } }); /*------ SYSTEMS ----------*/ diff --git a/docker-compose.yml b/docker-compose.yml index cf06c2d..d7f3fd4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,6 +65,10 @@ services: - S3_ENDPOINT - S3_BUCKET - S3_PROFILE + - TWITTER_CONSUMER_KEY + - TWITTER_CONSUMER_SECRET + - TWITTER_ACCESS_TOKEN_KEY + - TWITTER_ACCESS_TOKEN_SECRET volumes: - "~/.aws:/home/app/.aws" depends_on: diff --git a/test.env.example b/test.env.example index 1a5ef4b..95df1cb 100644 --- a/test.env.example +++ b/test.env.example @@ -22,3 +22,7 @@ export REACT_APP_ACCOUNT_SERVER="${PROTOCOL}account.${DOMAIN_NAME}" export REACT_APP_ADMIN_SERVER="${PROTOCOL}admin.${DOMAIN_NAME}" export REACT_APP_COOKIE_DOMAIN=".${DOMAIN_NAME}" +export TWITTER_CONSUMER_KEY="" +export TWITTER_CONSUMER_SECRET="" +export TWITTER_ACCESS_TOKEN_KEY="" +export TWITTER_ACCESS_TOKEN_SECRET="" \ No newline at end of file