diff src/routes.coffee @ 7:2123f355ab68

go back interval or 15 min, delete credentials, layout
author Mathias Gebbe <mgebbe@intevation.de>
date Wed, 11 Jun 2014 02:32:53 +0200
parents 98a070c98982
children 6fd0a307850f
line wrap: on
line diff
--- a/src/routes.coffee	Sat Jun 07 10:22:12 2014 +0200
+++ b/src/routes.coffee	Wed Jun 11 02:32:53 2014 +0200
@@ -42,14 +42,17 @@
 
     gpid = req.body.gpid
     gptoken = req.body.gptoken
+    gpdelete = req.body.gpdelete
 
     fbid = req.body.fbid
     fbtoken = req.body.fbtoken
+    fbdelete = req.body.fbdelete
+  
+    twdelete = req.body.twdelete
 
     # create/update userdb entrys
     # SET THE CONNECTION BETWEENS PUMPIO AND ESN-ACCOUNT (facebook or google)
 
-
     #### PUMPIO STUFF ####
     if not (pumpid?)
       console.log 'no pumpio'
@@ -62,8 +65,6 @@
      #], (result) ->
      #  Pump.postUser(result, 'mgebbe@io.intevation.de','Hallo Welt')
 
-
-
     #### GOOGLE STUFF ####
     if not (gpid?) or not (gptoken?)
       console.log 'no google'
@@ -78,19 +79,54 @@
       ], (err, result) ->
         # now we have a gp refresh token
         #console.log 'done'
+    if (gpdelete?)
+      console.log "delete gp account"
+      async.waterfall [
+        (callback) ->
+          Usermap.search {user_pumpio: gpdelete}, callback
+        (result, callback) ->
+          _.each result, (um) ->
+            if um.user_ESN.indexOf('@google') isnt -1
+              deleteUsermap(um.id,callback)
+            return
+       ], (err, result) ->
+ 
 
     #### FACEBOOK STUFF ####
     if not (fbid?) or not (fbtoken?)
       console.log 'no facebook'
     else
-    # get long-lived token
-    # (token is callback function)
-    # get the long lived token from facebook
+      # get long-lived token
+      # (token is callback function)
+      # get the long lived token from facebook
       Facebook.getLongLivedToken fbtoken,(token) ->
         saveUsermap(pumpid,fbid,token,fbtoken, (err, result) ->
           console.log 'fbsave.')
+    if (fbdelete?)
+      console.log "delete fb account"
+      async.waterfall [
+        (callback) ->
+          Usermap.search {user_pumpio: fbdelete}, callback
+        (result, callback) ->
+          _.each result, (um) ->
+            if um.user_ESN.indexOf('@facebook') isnt -1
+              deleteUsermap(um.id,callback)
+            return
+       ], (err, result) ->
 
+    if (twdelete?)
+      console.log "delete tw account"
+      async.waterfall [
+        (callback) ->
+          Usermap.search {user_pumpio: twdelete}, callback
+        (result, callback) ->
+          _.each result, (um) ->
+            if um.user_ESN.indexOf('@twitter') isnt -1
+              deleteUsermap(um.id,callback)
+            return
+       ], (err, result) ->
 
+ 
     # go back to main page
     #res.send JSON.stringify(req.body.pumpobj)
     #res.send 'bridge update for:'+ pumpid + '<br>--> ' + gpid + ' ' + gptoken + '<br>--> ' + fbid + ' ' + fbtoken
@@ -152,6 +188,11 @@
   ], (err, result) ->
   return
 
+deleteUsermap = (id, callback) ->
+  bank = Usermap.bank()
+  bank.del Usermap.type, id, callback
+  return
+
 exports.saveUsermap = saveUsermap
 exports.updateUserDB = updateUserDB
 exports.addRoutes = addRoutes
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)