comparison 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
comparison
equal deleted inserted replaced
6:a94ac7c3b182 7:2123f355ab68
40 pumptoken = req.body.pumptoken 40 pumptoken = req.body.pumptoken
41 pumpsecret = req.body.pumpsecret 41 pumpsecret = req.body.pumpsecret
42 42
43 gpid = req.body.gpid 43 gpid = req.body.gpid
44 gptoken = req.body.gptoken 44 gptoken = req.body.gptoken
45 gpdelete = req.body.gpdelete
45 46
46 fbid = req.body.fbid 47 fbid = req.body.fbid
47 fbtoken = req.body.fbtoken 48 fbtoken = req.body.fbtoken
49 fbdelete = req.body.fbdelete
50
51 twdelete = req.body.twdelete
48 52
49 # create/update userdb entrys 53 # create/update userdb entrys
50 # SET THE CONNECTION BETWEENS PUMPIO AND ESN-ACCOUNT (facebook or google) 54 # SET THE CONNECTION BETWEENS PUMPIO AND ESN-ACCOUNT (facebook or google)
51
52 55
53 #### PUMPIO STUFF #### 56 #### PUMPIO STUFF ####
54 if not (pumpid?) 57 if not (pumpid?)
55 console.log 'no pumpio' 58 console.log 'no pumpio'
56 else 59 else
59 62
60 #async.waterfall [(callback) -> 63 #async.waterfall [(callback) ->
61 # searchUsermap(bridgeid,bridgeid, callback) 64 # searchUsermap(bridgeid,bridgeid, callback)
62 #], (result) -> 65 #], (result) ->
63 # Pump.postUser(result, 'mgebbe@io.intevation.de','Hallo Welt') 66 # Pump.postUser(result, 'mgebbe@io.intevation.de','Hallo Welt')
64
65
66 67
67 #### GOOGLE STUFF #### 68 #### GOOGLE STUFF ####
68 if not (gpid?) or not (gptoken?) 69 if not (gpid?) or not (gptoken?)
69 console.log 'no google' 70 console.log 'no google'
70 else 71 else
76 (token, callback) -> 77 (token, callback) ->
77 saveUsermap(pumpid,gpid,token.access_token + ";" + gptoken.substr(gptoken.indexOf(';')+1,gptoken.length),token.refresh_token,callback) 78 saveUsermap(pumpid,gpid,token.access_token + ";" + gptoken.substr(gptoken.indexOf(';')+1,gptoken.length),token.refresh_token,callback)
78 ], (err, result) -> 79 ], (err, result) ->
79 # now we have a gp refresh token 80 # now we have a gp refresh token
80 #console.log 'done' 81 #console.log 'done'
82 if (gpdelete?)
83 console.log "delete gp account"
84 async.waterfall [
85 (callback) ->
86 Usermap.search {user_pumpio: gpdelete}, callback
87 (result, callback) ->
88 _.each result, (um) ->
89 if um.user_ESN.indexOf('@google') isnt -1
90 deleteUsermap(um.id,callback)
91 return
92 ], (err, result) ->
93
81 94
82 #### FACEBOOK STUFF #### 95 #### FACEBOOK STUFF ####
83 if not (fbid?) or not (fbtoken?) 96 if not (fbid?) or not (fbtoken?)
84 console.log 'no facebook' 97 console.log 'no facebook'
85 else 98 else
86 # get long-lived token 99 # get long-lived token
87 # (token is callback function) 100 # (token is callback function)
88 # get the long lived token from facebook 101 # get the long lived token from facebook
89 Facebook.getLongLivedToken fbtoken,(token) -> 102 Facebook.getLongLivedToken fbtoken,(token) ->
90 saveUsermap(pumpid,fbid,token,fbtoken, (err, result) -> 103 saveUsermap(pumpid,fbid,token,fbtoken, (err, result) ->
91 console.log 'fbsave.') 104 console.log 'fbsave.')
105 if (fbdelete?)
106 console.log "delete fb account"
107 async.waterfall [
108 (callback) ->
109 Usermap.search {user_pumpio: fbdelete}, callback
110 (result, callback) ->
111 _.each result, (um) ->
112 if um.user_ESN.indexOf('@facebook') isnt -1
113 deleteUsermap(um.id,callback)
114 return
115 ], (err, result) ->
92 116
117 if (twdelete?)
118 console.log "delete tw account"
119 async.waterfall [
120 (callback) ->
121 Usermap.search {user_pumpio: twdelete}, callback
122 (result, callback) ->
123 _.each result, (um) ->
124 if um.user_ESN.indexOf('@twitter') isnt -1
125 deleteUsermap(um.id,callback)
126 return
127 ], (err, result) ->
93 128
129
94 # go back to main page 130 # go back to main page
95 #res.send JSON.stringify(req.body.pumpobj) 131 #res.send JSON.stringify(req.body.pumpobj)
96 #res.send 'bridge update for:'+ pumpid + '<br>--> ' + gpid + ' ' + gptoken + '<br>--> ' + fbid + ' ' + fbtoken 132 #res.send 'bridge update for:'+ pumpid + '<br>--> ' + gpid + ' ' + gptoken + '<br>--> ' + fbid + ' ' + fbtoken
97 res.redirect('/') 133 res.redirect('/')
98 134
150 saveUser.created = Date.now() 186 saveUser.created = Date.now()
151 saveUser.save callback 187 saveUser.save callback
152 ], (err, result) -> 188 ], (err, result) ->
153 return 189 return
154 190
191 deleteUsermap = (id, callback) ->
192 bank = Usermap.bank()
193 bank.del Usermap.type, id, callback
194 return
195
155 exports.saveUsermap = saveUsermap 196 exports.saveUsermap = saveUsermap
156 exports.updateUserDB = updateUserDB 197 exports.updateUserDB = updateUserDB
157 exports.addRoutes = addRoutes 198 exports.addRoutes = addRoutes
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)