Mercurial > pumpbridge
comparison src/routes.coffee @ 3:98a070c98982
add Twitter support
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Thu, 05 Jun 2014 18:02:25 +0200 |
parents | b73191efc65b |
children | 2123f355ab68 |
comparison
equal
deleted
inserted
replaced
2:e942a968cb52 | 3:98a070c98982 |
---|---|
1 # Copyright (C) 2014 by Intevation GmbH | 1 # Copyright (C) 2014 by Intevation GmbH |
2 # Author: Mathias Gebbe <mgebbe@intevation.de> | 2 # Author: Mathias Gebbe <mgebbe@intevation.de> |
3 # | 3 # |
4 # This file is Free Software under the Apache License, Version 2.0 | 4 # This file is Free Software under the Apache License, Version 2.0; |
5 # (the "License"); and comes with ABSOLUTELY NO WARRANTY! | 5 # and comes with NO WARRANTY! |
6 # You may not use this file except in compliance with the License. | 6 # See the documentation coming with pumpbridge for details. |
7 # See LICENSE for details. | |
8 | 7 |
9 async = require("async") | 8 async = require("async") |
10 _ = require("underscore") | 9 _ = require("underscore") |
11 PumpIOClientApp = require("pump.io-client-app") | 10 PumpIOClientApp = require("pump.io-client-app") |
12 databank = require 'databank' | 11 databank = require 'databank' |
18 userRequired = PumpIOClientApp.userRequired | 17 userRequired = PumpIOClientApp.userRequired |
19 noUser = PumpIOClientApp.noUser | 18 noUser = PumpIOClientApp.noUser |
20 Usermap = require("./usermap") | 19 Usermap = require("./usermap") |
21 Google = require("./google") | 20 Google = require("./google") |
22 Facebook = require("./facebook") | 21 Facebook = require("./facebook") |
22 Twitterroutes = require("./twitterroutes") | |
23 Pump = require("./pumpio") | 23 Pump = require("./pumpio") |
24 User = require("./user") | 24 User = require("./user") |
25 Edge = require("./edge") | 25 Edge = require("./edge") |
26 Host = require("../node_modules/pump.io-client-app/lib/models/host") | 26 Host = require("../node_modules/pump.io-client-app/lib/models/host") |
27 https = require("https") | 27 https = require("https") |
49 # create/update userdb entrys | 49 # create/update userdb entrys |
50 # SET THE CONNECTION BETWEENS PUMPIO AND ESN-ACCOUNT (facebook or google) | 50 # SET THE CONNECTION BETWEENS PUMPIO AND ESN-ACCOUNT (facebook or google) |
51 | 51 |
52 | 52 |
53 #### PUMPIO STUFF #### | 53 #### PUMPIO STUFF #### |
54 if pumpid is "" or typeof pumpid is "undefined" | 54 if not (pumpid?) |
55 console.log 'no pumpio' | 55 console.log 'no pumpio' |
56 else | 56 else |
57 saveUsermap(pumpid,pumpid,pumptoken+';'+pumpsecret,pumpsecret, (err, result) -> | 57 saveUsermap(pumpid,pumpid,pumptoken+';'+pumpsecret,pumpsecret, (err, result) -> |
58 Pump.getUser(result)) | 58 Pump.getUser(result)) |
59 | 59 |
63 # Pump.postUser(result, 'mgebbe@io.intevation.de','Hallo Welt') | 63 # Pump.postUser(result, 'mgebbe@io.intevation.de','Hallo Welt') |
64 | 64 |
65 | 65 |
66 | 66 |
67 #### GOOGLE STUFF #### | 67 #### GOOGLE STUFF #### |
68 if gpid is "" or typeof gpid is "undefined" or gptoken is "" or typeof gptoken is "undefined" | 68 if not (gpid?) or not (gptoken?) |
69 console.log 'no google' | 69 console.log 'no google' |
70 else | 70 else |
71 async.waterfall [ | 71 async.waterfall [ |
72 (callback) -> | 72 (callback) -> |
73 saveUsermap(pumpid,gpid,gptoken,'', callback) | 73 saveUsermap(pumpid,gpid,gptoken,'', callback) |
74 (user, callback) -> | 74 (user, callback) -> |
75 Google.getRefreshToken(user,callback) | 75 Google.getRefreshToken(user,callback) |
76 (token, callback) -> | 76 (token, callback) -> |
77 saveUsermap(pumpid,gpid,token.access_token+";"+gptoken.substr(gptoken.indexOf(';')+1 ,gptoken.lenght),token.refresh_token,callback) | 77 saveUsermap(pumpid,gpid,token.access_token + ";" + gptoken.substr(gptoken.indexOf(';')+1,gptoken.length),token.refresh_token,callback) |
78 ], (err, result) -> | 78 ], (err, result) -> |
79 # now we have a gp refresh token | 79 # now we have a gp refresh token |
80 #console.log 'done' | 80 #console.log 'done' |
81 | 81 |
82 #### FACEBOOK STUFF #### | 82 #### FACEBOOK STUFF #### |
83 if fbid is "" or typeof fbid is "undefined" or fbtoken is "" or typeof fbtoken is "undefined" | 83 if not (fbid?) or not (fbtoken?) |
84 console.log 'no facebook' | 84 console.log 'no facebook' |
85 else | 85 else |
86 # get long-lived token | 86 # get long-lived token |
87 # (token is callback function) | 87 # (token is callback function) |
88 # get the long lived token from facebook | 88 # get the long lived token from facebook |
100 return | 100 return |
101 | 101 |
102 # Routes | 102 # Routes |
103 app.get "/bridge", userAuth, userRequired, getBridge | 103 app.get "/bridge", userAuth, userRequired, getBridge |
104 app.post "/bridge", userAuth, userRequired, saveBridge | 104 app.post "/bridge", userAuth, userRequired, saveBridge |
105 Twitterroutes.addRoutes(app) | |
105 | 106 |
106 return | 107 return |
107 | 108 |
108 # update or create usermap | 109 # update or create usermap |
109 saveUsermap = (pumpid,esnid,esntoken, extra, callback) -> | 110 saveUsermap = (pumpid,esnid,esntoken, extra, callback) -> |