annotate src/routes.coffee @ 0:b73191efc65b

Initial import of pumpbridge (bloody bloody alpha)
author Mathias Gebbe <mgebbe@intevation.de>
date Thu, 05 Jun 2014 10:35:15 +0200
parents
children 98a070c98982
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 #
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
4 # This file is Free Software under the Apache License, Version 2.0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
5 # (the "License"); and comes with ABSOLUTELY NO WARRANTY!
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
6 # You may not use this file except in compliance with the License.
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
7 # See LICENSE for details.
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
8
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
9 async = require("async")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
10 _ = require("underscore")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
11 PumpIOClientApp = require("pump.io-client-app")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
12 databank = require 'databank'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
13 Databank = databank.Databank
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
14 DatabankObject = databank.DatabankObject
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
15 RequestToken = PumpIOClientApp.RequestToken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
16 userAuth = PumpIOClientApp.userAuth
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
17 userOptional = PumpIOClientApp.userOptional
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
18 userRequired = PumpIOClientApp.userRequired
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
19 noUser = PumpIOClientApp.noUser
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
20 Usermap = require("./usermap")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
21 Google = require("./google")
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
22 Facebook = require("./facebook")
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
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
45
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
46 fbid = req.body.fbid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
47 fbtoken = req.body.fbtoken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
48
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
49 # create/update userdb entrys
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
50 # 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
51
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 #### PUMPIO STUFF ####
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
54 if pumpid is "" or typeof pumpid is "undefined"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
55 console.log 'no pumpio'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
56 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
57 saveUsermap(pumpid,pumpid,pumptoken+';'+pumpsecret,pumpsecret, (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
58 Pump.getUser(result))
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 #async.waterfall [(callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
61 # searchUsermap(bridgeid,bridgeid, callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
62 #], (result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
63 # 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
64
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
65
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 #### GOOGLE STUFF ####
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
68 if gpid is "" or typeof gpid is "undefined" or gptoken is "" or typeof gptoken is "undefined"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
69 console.log 'no google'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
70 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
71 async.waterfall [
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
72 (callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
73 saveUsermap(pumpid,gpid,gptoken,'', callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
74 (user, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
75 Google.getRefreshToken(user,callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
76 (token, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
77 saveUsermap(pumpid,gpid,token.access_token+";"+gptoken.substr(gptoken.indexOf(';')+1 ,gptoken.lenght),token.refresh_token,callback)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
79 # now we have a gp refresh token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
80 #console.log 'done'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
81
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
82 #### FACEBOOK STUFF ####
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
83 if fbid is "" or typeof fbid is "undefined" or fbtoken is "" or typeof fbtoken is "undefined"
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
84 console.log 'no facebook'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
85 else
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
86 # get long-lived token
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
87 # (token is callback function)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
88 # get the long lived token from facebook
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
89 Facebook.getLongLivedToken fbtoken,(token) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
90 saveUsermap(pumpid,fbid,token,fbtoken, (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
91 console.log 'fbsave.')
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
92
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
93
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
94 # go back to main page
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
95 #res.send JSON.stringify(req.body.pumpobj)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
96 #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
97 res.redirect('/')
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 # END
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
100 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
101
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
102 # Routes
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
103 app.get "/bridge", userAuth, userRequired, getBridge
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
104 app.post "/bridge", userAuth, userRequired, saveBridge
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
105
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
106 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
107
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
108 # update or create usermap
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
109 saveUsermap = (pumpid,esnid,esntoken, extra, callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
110 saveMap = new Usermap(
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
111 id : Usermap.key(pumpid,esnid)
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
112 user_pumpio : pumpid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
113 user_ESN : esnid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
114 oauth_token : esntoken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
115 extra_token : extra
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
116 created : Date.now()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
117 )
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
118 saveMap.save (cb) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
119 #console.log 'saved.'
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
120 callback null, saveMap
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
121
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
122 # only create and not update usermap
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
123 createUsermap = (pumpid,esnid,esntoken) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
124 async.waterfall [(callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
125 Usermap.create
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
126 user_pumpio: pumpid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
127 user_ESN: esnid
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
128 oauth_token: esntoken
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
129 , callback
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
130 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
131 if err instanceof databank.AlreadyExistsError
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
132 console.log err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
133 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
134 if err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
135 console.log err
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
136 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
137 else
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 # update or create a user
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
141 updateUserDB = (id, name, displayName, profileLink, profilePicLink) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
142 async.waterfall [(callback) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
143 saveUser = new User()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
144 saveUser.id = id
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
145 saveUser.name = name
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
146 saveUser.displayName = displayName
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
147 saveUser.profileLink = profileLink
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
148 saveUser.profilePicLink = profilePicLink
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
149 saveUser.created = Date.now()
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
150 saveUser.save callback
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
151 ], (err, result) ->
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
152 return
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
153
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
154 exports.saveUsermap = saveUsermap
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
155 exports.updateUserDB = updateUserDB
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
156 exports.addRoutes = addRoutes
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)