annotate src/routes.coffee @ 31:8238d312e281

var checks
author Mathias Gebbe <mgebbe@intevation.de>
date Tue, 30 Sep 2014 07:30:54 +0200
parents 3e3fa35e3ce2
children
rev   line source
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2014 by Intevation GmbH
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
2 # Author: Mathias Gebbe <mgebbe@intevation.de>
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
3 #
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
4 # This file is Free Software under the Apache License, Version 2.0;
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
5 # and comes with NO WARRANTY!
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
6 # See the documentation coming with pumpbridge for details.
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
7
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
8 async = require("async")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
9 _ = require("underscore")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
10 PumpIOClientApp = require("pump.io-client-app")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
11 databank = require 'databank'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
12 Databank = databank.Databank
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
13 DatabankObject = databank.DatabankObject
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
14 RequestToken = PumpIOClientApp.RequestToken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
15 userAuth = PumpIOClientApp.userAuth
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
16 userOptional = PumpIOClientApp.userOptional
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
17 userRequired = PumpIOClientApp.userRequired
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
18 noUser = PumpIOClientApp.noUser
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
19 Usermap = require("./usermap")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
20 Google = require("./google")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
21 Facebook = require("./facebook")
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
22 Twitterroutes = require("./twitterroutes")
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
23 Pump = require("./pumpio")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
24 User = require("./user")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
25 Edge = require("./edge")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
26 Host = require("../node_modules/pump.io-client-app/lib/models/host")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
27 https = require("https")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
28 OAuth = require('oauth')
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
29 Sync = require('./sync')
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
30
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
31 addRoutes = (app, options) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
32
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
33 getBridge = (req, res) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
34 res.send 'Hello, i am the bridge you looking for!'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
35 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
36
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
37 saveBridge = (req, res) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
38
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
39 pumpid = req.body.pumpid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
40 pumptoken = req.body.pumptoken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
41 pumpsecret = req.body.pumpsecret
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
42
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
43 gpid = req.body.gpid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
44 gptoken = req.body.gptoken
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
45 gpdelete = req.body.gpdelete
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
46
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
47 fbid = req.body.fbid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
48 fbtoken = req.body.fbtoken
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
49 fbdelete = req.body.fbdelete
17
a52b5b244e51 removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents: 8
diff changeset
50
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
51 twdelete = req.body.twdelete
31
8238d312e281 var checks
Mathias Gebbe <mgebbe@intevation.de>
parents: 30
diff changeset
52
30
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
53 twmode = req.body.twmode
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
54 if(req.body.twtoesn?) then twtoesn=true else twtoesn=false
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
55 if(req.body.twfromesn?) then twfromesn=true else twfromesn=false
31
8238d312e281 var checks
Mathias Gebbe <mgebbe@intevation.de>
parents: 30
diff changeset
56
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
57 # create/update userdb entrys
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
58 # SET THE CONNECTION BETWEENS PUMPIO AND ESN-ACCOUNT (facebook or google)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
59
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
60 #### PUMPIO STUFF ####
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
61 if not (pumpid?)
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
62 console.log 'no pumpio'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
63 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
64 saveUsermap(pumpid,pumpid,pumptoken+';'+pumpsecret,pumpsecret, (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
65 Pump.getUser(result))
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
66
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
67 #async.waterfall [(callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
68 # searchUsermap(bridgeid,bridgeid, callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
69 #], (result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
70 # Pump.postUser(result, 'mgebbe@io.intevation.de','Hallo Welt')
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
71
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
72 #### GOOGLE STUFF ####
8
6fd0a307850f check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
73 if not (gpid?) or not (gptoken?) or gpid is "" or gptoken is ""
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
74 console.log 'no google'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
75 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
76 async.waterfall [
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
77 (callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78 saveUsermap(pumpid,gpid,gptoken,'', callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
79 (user, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
80 Google.getRefreshToken(user,callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
81 (token, callback) ->
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
82 saveUsermap(pumpid,gpid,token.access_token + ";" + gptoken.substr(gptoken.indexOf(';')+1,gptoken.length),token.refresh_token,callback)
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
83 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
84 # now we have a gp refresh token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
85 #console.log 'done'
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
86 if (gpdelete?)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
87 console.log "delete gp account"
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
88 async.waterfall [
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
89 (callback) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
90 Usermap.search {user_pumpio: gpdelete}, callback
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
91 (result, callback) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
92 _.each result, (um) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
93 if um.user_ESN.indexOf('@google') isnt -1
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
94 deleteUsermap(um.id,callback)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
95 return
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
96 ], (err, result) ->
17
a52b5b244e51 removed unnecessary underscore and replaced it with async
Mathias Gebbe <mgebbe@intevation.de>
parents: 8
diff changeset
97
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
98
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
99 #### FACEBOOK STUFF ####
8
6fd0a307850f check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
100 if not (fbid?) or not (fbtoken?) or fbid is "" or fbtoken is ""
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
101 console.log 'no facebook'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
102 else
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
103 # get long-lived token
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
104 # (token is callback function)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
105 # get the long lived token from facebook
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
106 Facebook.getLongLivedToken fbtoken,(token) ->
8
6fd0a307850f check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
107 if (token?)
6fd0a307850f check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
108 saveUsermap(pumpid,fbid,token,fbtoken, (err, result) ->
6fd0a307850f check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
109 console.log 'fbsave.')
6fd0a307850f check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents: 7
diff changeset
110
30
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
111 #### Twitter MODUS ###
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
112 if (twmode?)
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
113 console.log "mod tw account"
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
114 async.waterfall [
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
115 (callback) ->
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
116 Usermap.search {user_pumpio: twmode}, callback
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
117 (result, callback) ->
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
118 _.each result, (um) ->
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
119 if um.user_ESN.indexOf('@twitter') isnt -1
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
120 saveUsermapSelect(um.user_pumpio, um.user_ESN, um.oauth_token, um.extra_token,twfromesn,twtoesn,callback)
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
121 return
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
122 ], (err, result) ->
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
123
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
124 if (fbdelete?)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
125 console.log "delete fb account"
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
126 async.waterfall [
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
127 (callback) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
128 Usermap.search {user_pumpio: fbdelete}, callback
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
129 (result, callback) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
130 _.each result, (um) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
131 if um.user_ESN.indexOf('@facebook') isnt -1
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
132 deleteUsermap(um.id,callback)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
133 return
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
134 ], (err, result) ->
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
135
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
136 if (twdelete?)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
137 console.log "delete tw account"
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
138 async.waterfall [
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
139 (callback) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
140 Usermap.search {user_pumpio: twdelete}, callback
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
141 (result, callback) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
142 _.each result, (um) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
143 if um.user_ESN.indexOf('@twitter') isnt -1
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
144 deleteUsermap(um.id,callback)
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
145 return
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
146 ], (err, result) ->
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
147
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
148 # go back to main page
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
149 #res.send JSON.stringify(req.body.pumpobj)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
150 #res.send 'bridge update for:'+ pumpid + '<br>--> ' + gpid + ' ' + gptoken + '<br>--> ' + fbid + ' ' + fbtoken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
151 res.redirect('/')
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
152
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
153 # END
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
154 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
155
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
156 # Routes
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
157 app.get "/bridge", userAuth, userRequired, getBridge
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
158 app.post "/bridge", userAuth, userRequired, saveBridge
3
98a070c98982 add Twitter support
Mathias Gebbe <mgebbe@intevation.de>
parents: 0
diff changeset
159 Twitterroutes.addRoutes(app)
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
160
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
161 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
162
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
163 # update or create usermap
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
164 saveUsermap = (pumpid,esnid,esntoken, extra, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
165 saveMap = new Usermap(
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
166 id : Usermap.key(pumpid,esnid)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
167 user_pumpio : pumpid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
168 user_ESN : esnid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
169 oauth_token : esntoken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
170 extra_token : extra
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
171 created : Date.now()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
172 )
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
173 saveMap.save (cb) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
174 #console.log 'saved.'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
175 callback null, saveMap
30
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
176 return
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
177
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
178 # update or create usermap
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
179 saveUsermapSelect = (pumpid, esnid, esntoken, extra, fromesn, toesn, callback) ->
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
180 saveMap = new Usermap(
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
181 id : Usermap.key(pumpid,esnid)
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
182 user_pumpio : pumpid
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
183 user_ESN : esnid
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
184 oauth_token : esntoken
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
185 extra_token : extra
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
186 fromesn : fromesn
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
187 toesn: toesn
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
188 created : Date.now()
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
189 )
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
190 saveMap.save (cb) ->
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
191 #console.log 'saved.'
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
192 callback null, saveMap
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
193 return
3e3fa35e3ce2 twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents: 17
diff changeset
194
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
195
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
196 # only create and not update usermap
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
197 createUsermap = (pumpid,esnid,esntoken) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
198 async.waterfall [(callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
199 Usermap.create
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
200 user_pumpio: pumpid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
201 user_ESN: esnid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
202 oauth_token: esntoken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
203 , callback
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
204 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
205 if err instanceof databank.AlreadyExistsError
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
206 console.log err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
207 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
208 if err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
209 console.log err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
210 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
211 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
212 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
213
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
214 # update or create a user
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
215 updateUserDB = (id, name, displayName, profileLink, profilePicLink) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
216 async.waterfall [(callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
217 saveUser = new User()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
218 saveUser.id = id
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
219 saveUser.name = name
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
220 saveUser.displayName = displayName
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
221 saveUser.profileLink = profileLink
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
222 saveUser.profilePicLink = profilePicLink
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
223 saveUser.created = Date.now()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
224 saveUser.save callback
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
225 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
226 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
227
7
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
228 deleteUsermap = (id, callback) ->
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
229 bank = Usermap.bank()
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
230 bank.del Usermap.type, id, callback
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
231 return
2123f355ab68 go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents: 3
diff changeset
232
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
233 exports.saveUsermap = saveUsermap
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
234 exports.updateUserDB = updateUserDB
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
235 exports.addRoutes = addRoutes
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)