Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added lock for sms spam

  • Loading branch information...
commit 6097c1e4ed2410068bc54abea165c3a3f379c91a 1 parent 60ea8f1
@edhiley edhiley authored
Showing with 32 additions and 42 deletions.
  1. +12 −3 app/controllers/location.js
  2. +0 −39 package.json.orig
  3. +20 −0 smslock.js
View
15 app/controllers/location.js
@@ -3,11 +3,19 @@ var mongoose = require('mongoose'),
User = require('../models/user'),
Config = require('../../config/config'),
Game = require('../models/game'),
- unirest = require('unirest');
+ unirest = require('unirest'),
+ smslock = require('../../smslock');
var sendSms = function(message, phoneNumber) {
console.log("Send Sms to user: " + message);
+ if (smslock.recentlySent(phoneNumber)) {
+ console.log("Avoiding spamming SMS service");
+ return;
+ }
+
+ smslock.add(phoneNumber);
+
var phoneNumber = "07944166597";
phoneNumber = (phoneNumber.charAt(0) === "0") ?
@@ -17,8 +25,9 @@ var sendSms = function(message, phoneNumber) {
url = "https://api.clockworksms.com/http/send.aspx?key=" + key + "&to=" + phoneNumber + "&content=" + encodeURIComponent(message);
console.log(url);
- //var Request = unirest.get(url);
- //console.log(Request);
+ unirest.get(url).end(function(response){
+ console.log(response);
+ });
};
if (typeof Number.prototype.toRad == 'undefined') {
View
39 package.json.orig
@@ -1,39 +0,0 @@
-{
- "name": "appsassin",
- "version": "0.0.1-9",
- "private": true,
- "scripts": {
- "start": "app.js"
- },
- "dependencies": {
- "express": "~3.3.4",
- "jade": "~0.34.0",
- "mongoose": "~3.6.14",
- "express-restify-mongoose": "~0.3.3",
-<<<<<<< HEAD
- "node-geonames": "0.0.11",
- "underscore": "~1.5.2",
- "request": "~2.27.0"
-=======
- "unirest": "0.0.5"
->>>>>>> 932f9d8b43a4ac4fd183b52311b1b981890e2f26
- },
- "devDependencies": {
- "grunt": "~0.4.1",
- "grunt-develop": "~0.1.1",
- "grunt-contrib-watch": "~0.4.4",
- "grunt-contrib-compass": "~0.2.0",
- "request": "~2.22.0",
- "time-grunt": "~0.1.1",
- "load-grunt-tasks": "~0.2.0",
- "grunt-mocha": "~0.4.1",
- "grunt-lib-phantomjs": "~0.4.0"
- },
- "subdomain": "appsassin",
- "domains": [
- "appsass.in"
- ],
- "engines": {
- "node": "0.10.x"
- }
-}
View
20 smslock.js
@@ -0,0 +1,20 @@
+
+var locks = module.exports = (function(){
+ var locks = {},
+ lockDick = [];
+
+ locks.add = function(number) {
+ lockDick[number] = Date.now();
+ };
+
+ locks.recentlySent = function(number) {
+ var previous = lockDick[number];
+
+ if (!previous)
+ return false;
+
+ return ((Date.now() - previous) / 1000) < 600;
+ };
+
+ return locks;
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.