Mercurial > pumpbridge
annotate index.js_to_pump.io-client-app_lib_routes @ 32:ca0b44c1a870 tip
Readme: twitter in the summary, it is best working currently.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 13 Oct 2014 13:22:17 +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 // index.js |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
2 // |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
3 // Most of the routes in the application |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
4 // |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
5 // Copyright 2013, E14N https://e14n.com/ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
6 // |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
7 // Licensed under the Apache License, Version 2.0 (the "License"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
8 // 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
|
9 // You may obtain a copy of the License at |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
10 // |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
11 // http://www.apache.org/licenses/LICENSE-2.0 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
12 // |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
13 // Unless required by applicable law or agreed to in writing, software |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
14 // distributed under the License is distributed on an "AS IS" BASIS, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
16 // See the License for the specific language governing permissions and |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
17 // limitations under the License. |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
18 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
19 var wf = require("webfinger"), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
20 async = require("async"), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
21 _ = require("underscore"), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
22 uuid = require("node-uuid"), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
23 User = require("../models/user"), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
24 Host = require("../models/host"), |
28 | 25 Usermap = require("../../../../lib/usermap"), |
30
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
26 //Usermap = require("../../../../src/usermap"), |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
27 RequestToken = require("../models/requesttoken"), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
28 RememberMe = require("../models/rememberme"), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
29 site = require("../models/site"); |
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 exports.hostmeta = function(req, res) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
32 res.json({ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
33 links: [ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
34 { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
35 rel: "dialback", |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
36 href: site.url("/dialback") |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
37 } |
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 }); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
40 }; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
41 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
42 exports.index = function(req, res, next) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
43 var hosts, users, bank = Host.bank(); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
44 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
45 if (req.user) { |
30
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
46 var fb=false, gp=false, tw=false, twfromesn=true, twtoesn=true; |
15
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
47 Usermap.search({ |
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
48 user_pumpio: req.user.id |
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
49 }, function(err, result) { |
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
50 if(err) res.render('login', { pageTitle: "pumpbridge" }); |
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
51 _.each(result, function(um) { |
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
52 if ( um.id.indexOf('@facebook') != -1 ) fb=true; |
30
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
53 if ( um.id.indexOf('@twitter') != -1 ) { |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
54 tw=true; |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
55 if(typeof um.fromesn != "undefined") twfromesn = um.fromesn; |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
56 if(typeof um.toesn != "undefined") twtoesn = um.toesn; |
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
57 } |
15
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
58 if ( um.id.indexOf('@google') != -1 ) gp=true; |
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
59 }); |
30
3e3fa35e3ce2
twitter sync likes, recommend mongodb
Mathias Gebbe <mgebbe@intevation.de>
parents:
28
diff
changeset
|
60 res.render('index', { pageTitle: "pumpbridge" , user: req.user, usermapfb: fb, usermapgp: gp, usermaptw: tw, twfromesn: twfromesn, twtoesn: twtoesn}); |
15
c5bf4e02958e
add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents:
12
diff
changeset
|
61 }); |
0
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
62 } else { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
63 res.render('login', { pageTitle: "pumpbridge" }); |
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 exports.login = function(req, res) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
68 res.render('login', { pageTitle: "Login" }); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
69 }; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
70 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
71 exports.handleLogin = function(req, res, next) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
72 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
73 var id = req.body.webfinger, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
74 rememberme = req.body.rememberme, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
75 hostname = User.getHostname(id), |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
76 host; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
77 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
78 req.log.debug(req.body, "Handling login"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
79 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
80 async.waterfall([ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
81 function(callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
82 Host.ensureHost(hostname, callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
83 }, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
84 function(results, callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
85 host = results; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
86 host.getRequestToken(callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
87 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
88 ], function(err, rt) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
89 if (err) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
90 if (err instanceof Error) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
91 next(err); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
92 } else if (err.data) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
93 next(new Error(err.data)); |
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 } else { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
96 // Remember if the user asked for a rememberme cookie |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
97 req.session.remembermeChecked = (rememberme == "on"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
98 res.redirect(host.authorizeURL(rt)); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
99 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
100 }); |
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 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
103 exports.authorized = function(req, res, next) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
104 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
105 var hostname = req.params.hostname, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
106 token = req.query.oauth_token, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
107 verifier = req.query.oauth_verifier, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
108 rt, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
109 host, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
110 access_token, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
111 token_secret, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
112 id, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
113 object, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
114 user, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
115 newUser = false; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
116 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
117 async.waterfall([ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
118 function(callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
119 async.parallel([ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
120 function(callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
121 RequestToken.get(RequestToken.key(hostname, token), callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
122 }, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
123 function(callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
124 Host.get(hostname, callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
125 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
126 ], callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
127 }, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
128 function(results, callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
129 rt = results[0]; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
130 host = results[1]; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
131 host.getAccessToken(rt, verifier, callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
132 }, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
133 function(token, secret, extra, callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
134 access_token = token; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
135 token_secret = secret; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
136 async.parallel([ |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
137 function(callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
138 rt.del(callback); |
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 function(callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
141 host.whoami(access_token, token_secret, callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
142 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
143 ], callback); |
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 function(results, callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
146 object = results[1]; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
147 id = object.id; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
148 if (id.substr(0, 5) == "acct:") { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
149 id = id.substr(5); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
150 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
151 User.get(id, function(err, user) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
152 if (err && err.name === "NoSuchThingError") { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
153 newUser = true; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
154 User.fromPerson(object, access_token, token_secret, callback); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
155 } else if (err) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
156 callback(err, null); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
157 } else { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
158 callback(null, user); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
159 } |
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 }, |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
162 function(results, callback) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
163 user = results; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
164 if (req.session.remembermeChecked) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
165 req.log.debug("Setting rememberme cookie"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
166 RememberMe.create({user: user.id}, function(err, rm) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
167 if (err) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
168 callback(err); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
169 } else { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
170 req.log.debug({rm: rm}, "Created rememberme record"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
171 res.cookie("rememberme", rm.uuid, {path: "/", expires: new Date(Date.now() + 180 * 24 * 60 * 60 * 1000), httpOnly: true}); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
172 req.log.debug({rememberme: rm.uuid}, "Set rememberme cookie"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
173 callback(null); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
174 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
175 }); |
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 callback(null); |
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 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
180 ], function(err) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
181 if (err) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
182 next(err); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
183 } else { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
184 req.session.userID = user.id; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
185 delete req.session.remembermeChecked; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
186 res.redirect("/"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
187 } |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
188 }); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
189 }; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
190 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
191 exports.handleLogout = function(req, res) { |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
192 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
193 delete req.session.userID; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
194 delete req.session.remembermeChecked; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
195 delete req.user; |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
196 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
197 res.clearCookie("rememberme"); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
198 |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
199 res.redirect("/", 303); |
b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
200 }; |