annotate index.js_to_pump.io-client-app_lib_routes @ 20:9436298e6d78

wrong callback
author Mathias Gebbe <mgebbe@intevation.de>
date Fri, 13 Jun 2014 18:29:55 +0200
parents d2208a4ed5c8
children faeb3b96bdeb
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"),
16
d2208a4ed5c8 require wrong usermap. fixed.
Mathias Gebbe <mgebbe@intevation.de>
parents: 15
diff changeset
25 Usermap = require("../../../../src/usermap"),
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
26 RequestToken = require("../models/requesttoken"),
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
27 RememberMe = require("../models/rememberme"),
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
28 site = require("../models/site");
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
29
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
30 exports.hostmeta = function(req, res) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
31 res.json({
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
32 links: [
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
33 {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
34 rel: "dialback",
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
35 href: site.url("/dialback")
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 ]
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 exports.index = function(req, res, next) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
42 var hosts, users, bank = Host.bank();
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
43
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
44 if (req.user) {
15
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
45 var fb=false, gp=false, tw=false;
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
46 Usermap.search({
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
47 user_pumpio: req.user.id
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
48 }, function(err, result) {
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
49 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
50 _.each(result, function(um) {
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
51 if ( um.id.indexOf('@facebook') != -1 ) fb=true;
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
52 if ( um.id.indexOf('@twitter') != -1 ) tw=true;
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
53 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
54 });
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
55 res.render('index', { pageTitle: "pumpbridge" , user: req.user, usermapfb: fb, usermapgp: gp, usermaptw: tw});
c5bf4e02958e add/delete credentials, new layout, alpha version ribbon, contact
Mathias Gebbe <mgebbe@intevation.de>
parents: 12
diff changeset
56 });
0
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
57 } else {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
58 res.render('login', { pageTitle: "pumpbridge" });
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 };
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
61
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
62 exports.login = function(req, res) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
63 res.render('login', { pageTitle: "Login" });
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 exports.handleLogin = function(req, res, next) {
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 var id = req.body.webfinger,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
69 rememberme = req.body.rememberme,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
70 hostname = User.getHostname(id),
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
71 host;
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 req.log.debug(req.body, "Handling login");
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
74
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
75 async.waterfall([
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
76 function(callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
77 Host.ensureHost(hostname, callback);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78 },
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
79 function(results, callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
80 host = results;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
81 host.getRequestToken(callback);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
82 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
83 ], function(err, rt) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
84 if (err) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
85 if (err instanceof Error) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
86 next(err);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
87 } else if (err.data) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
88 next(new Error(err.data));
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
89 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
90 } else {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
91 // 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
92 req.session.remembermeChecked = (rememberme == "on");
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
93 res.redirect(host.authorizeURL(rt));
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 });
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
96 };
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
97
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
98 exports.authorized = function(req, res, next) {
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 var hostname = req.params.hostname,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
101 token = req.query.oauth_token,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
102 verifier = req.query.oauth_verifier,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
103 rt,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
104 host,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
105 access_token,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
106 token_secret,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
107 id,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
108 object,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
109 user,
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
110 newUser = false;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
111
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
112 async.waterfall([
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
113 function(callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
114 async.parallel([
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
115 function(callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
116 RequestToken.get(RequestToken.key(hostname, token), callback);
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 function(callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
119 Host.get(hostname, callback);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
120 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
121 ], 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(results, callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
124 rt = results[0];
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
125 host = results[1];
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
126 host.getAccessToken(rt, verifier, 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(token, secret, extra, callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
129 access_token = token;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
130 token_secret = secret;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
131 async.parallel([
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
132 function(callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
133 rt.del(callback);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
134 },
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
135 function(callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
136 host.whoami(access_token, token_secret, callback);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
137 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
138 ], 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(results, callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
141 object = results[1];
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
142 id = object.id;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
143 if (id.substr(0, 5) == "acct:") {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
144 id = id.substr(5);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
145 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
146 User.get(id, function(err, user) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
147 if (err && err.name === "NoSuchThingError") {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
148 newUser = true;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
149 User.fromPerson(object, access_token, token_secret, callback);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
150 } else if (err) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
151 callback(err, null);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
152 } else {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
153 callback(null, user);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
154 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
155 });
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
156 },
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
157 function(results, callback) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
158 user = results;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
159 if (req.session.remembermeChecked) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
160 req.log.debug("Setting rememberme cookie");
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
161 RememberMe.create({user: user.id}, function(err, rm) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
162 if (err) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
163 callback(err);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
164 } else {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
165 req.log.debug({rm: rm}, "Created rememberme record");
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
166 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
167 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
168 callback(null);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
169 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
170 });
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
171 } else {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
172 callback(null);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
173 }
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 ], function(err) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
176 if (err) {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
177 next(err);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
178 } else {
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
179 req.session.userID = user.id;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
180 delete req.session.remembermeChecked;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
181 res.redirect("/");
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
182 }
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
183 });
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
184 };
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
185
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
186 exports.handleLogout = function(req, res) {
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 delete req.session.userID;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
189 delete req.session.remembermeChecked;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
190 delete req.user;
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
191
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
192 res.clearCookie("rememberme");
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
193
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
194 res.redirect("/", 303);
b73191efc65b Initial import of pumpbridge (bloody bloody alpha)
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
195 };
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)