Mercurial > pumpbridge
annotate src/routes.coffee @ 8:6fd0a307850f
check empty strings and users
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Wed, 11 Jun 2014 21:58:41 +0200 |
parents | 2123f355ab68 |
children | a52b5b244e51 |
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 | 4 # This file is Free Software under the Apache License, Version 2.0; |
5 # and comes with NO WARRANTY! | |
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 | 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 |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
50 |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
51 twdelete = req.body.twdelete |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
52 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
53 # create/update userdb entrys |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
54 # 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
|
55 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
56 #### PUMPIO STUFF #### |
3 | 57 if not (pumpid?) |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
58 console.log 'no pumpio' |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
59 else |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
60 saveUsermap(pumpid,pumpid,pumptoken+';'+pumpsecret,pumpsecret, (err, result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
61 Pump.getUser(result)) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
62 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
63 #async.waterfall [(callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
64 # searchUsermap(bridgeid,bridgeid, callback) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
65 #], (result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
66 # 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
|
67 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
68 #### GOOGLE STUFF #### |
8
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
7
diff
changeset
|
69 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
|
70 console.log 'no google' |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
71 else |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
72 async.waterfall [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
73 (callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
74 saveUsermap(pumpid,gpid,gptoken,'', callback) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
75 (user, callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
76 Google.getRefreshToken(user,callback) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
77 (token, callback) -> |
3 | 78 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
|
79 ], (err, result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
80 # now we have a gp refresh token |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
81 #console.log 'done' |
7
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
82 if (gpdelete?) |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
83 console.log "delete gp account" |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
84 async.waterfall [ |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
85 (callback) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
86 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
|
87 (result, callback) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
88 _.each result, (um) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
89 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
|
90 deleteUsermap(um.id,callback) |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
91 return |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
92 ], (err, result) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
93 |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
94 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
95 #### FACEBOOK STUFF #### |
8
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
7
diff
changeset
|
96 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
|
97 console.log 'no facebook' |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
98 else |
7
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
99 # get long-lived token |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
100 # (token is callback function) |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
101 # get the long lived token from facebook |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
102 Facebook.getLongLivedToken fbtoken,(token) -> |
8
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
7
diff
changeset
|
103 if (token?) |
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
7
diff
changeset
|
104 saveUsermap(pumpid,fbid,token,fbtoken, (err, result) -> |
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
7
diff
changeset
|
105 console.log 'fbsave.') |
6fd0a307850f
check empty strings and users
Mathias Gebbe <mgebbe@intevation.de>
parents:
7
diff
changeset
|
106 |
7
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
107 if (fbdelete?) |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
108 console.log "delete fb account" |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
109 async.waterfall [ |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
110 (callback) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
111 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
|
112 (result, callback) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
113 _.each result, (um) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
114 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
|
115 deleteUsermap(um.id,callback) |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
116 return |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
117 ], (err, result) -> |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
118 |
7
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
119 if (twdelete?) |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
120 console.log "delete tw account" |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
121 async.waterfall [ |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
122 (callback) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
123 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
|
124 (result, callback) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
125 _.each result, (um) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
126 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
|
127 deleteUsermap(um.id,callback) |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
128 return |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
129 ], (err, result) -> |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
130 |
7
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
131 |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
132 # go back to main page |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
133 #res.send JSON.stringify(req.body.pumpobj) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
134 #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
|
135 res.redirect('/') |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
136 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
137 # END |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
138 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
139 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
140 # Routes |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
141 app.get "/bridge", userAuth, userRequired, getBridge |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
142 app.post "/bridge", userAuth, userRequired, saveBridge |
3 | 143 Twitterroutes.addRoutes(app) |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
144 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
145 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
146 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
147 # update or create usermap |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
148 saveUsermap = (pumpid,esnid,esntoken, extra, callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
149 saveMap = new Usermap( |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
150 id : Usermap.key(pumpid,esnid) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
151 user_pumpio : pumpid |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
152 user_ESN : esnid |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
153 oauth_token : esntoken |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
154 extra_token : extra |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
155 created : Date.now() |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
156 ) |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
157 saveMap.save (cb) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
158 #console.log 'saved.' |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
159 callback null, saveMap |
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 # only create and not update usermap |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
162 createUsermap = (pumpid,esnid,esntoken) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
163 async.waterfall [(callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
164 Usermap.create |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
165 user_pumpio: pumpid |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
166 user_ESN: esnid |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
167 oauth_token: esntoken |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
168 , callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
169 ], (err, result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
170 if err instanceof databank.AlreadyExistsError |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
171 console.log err |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
172 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
173 if err |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
174 console.log err |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
175 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
176 else |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
177 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
178 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
179 # update or create a user |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
180 updateUserDB = (id, name, displayName, profileLink, profilePicLink) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
181 async.waterfall [(callback) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
182 saveUser = new User() |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
183 saveUser.id = id |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
184 saveUser.name = name |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
185 saveUser.displayName = displayName |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
186 saveUser.profileLink = profileLink |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
187 saveUser.profilePicLink = profilePicLink |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
188 saveUser.created = Date.now() |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
189 saveUser.save callback |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
190 ], (err, result) -> |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
191 return |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
192 |
7
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
193 deleteUsermap = (id, callback) -> |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
194 bank = Usermap.bank() |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
195 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
|
196 return |
2123f355ab68
go back interval or 15 min, delete credentials, layout
Mathias Gebbe <mgebbe@intevation.de>
parents:
3
diff
changeset
|
197 |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
198 exports.saveUsermap = saveUsermap |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
199 exports.updateUserDB = updateUserDB |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
200 exports.addRoutes = addRoutes |