Skip to content

Commit 1638c96

Browse files
author
Becky Sroufe
committed
Merge remote-tracking branch 'curtislacy/Connection-Returns' into loadingview
2 parents e6922ce + 4a6c854 commit 1638c96

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

app/app-js/modules/menu/menuPanel/menuPanel.view.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ define(function (require) {
4848
if (this.model.get('connected')) {
4949
window.location.assign('/disconnect/' + this.model.get('serviceKey'));
5050
} else {
51-
window.location.assign('/auth/' + this.model.get('serviceKey'));
51+
window.location.assign('/auth/' + this.model.get('serviceKey') + '?auth-return=' + encodeURIComponent( window.location.pathname + window.location.hash ));
5252
}
5353
},
5454

server.js

+47-21
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ passport.use( 'facebook', new FacebookStrategy(
4747
owner: 'facebook:' + profile.id,
4848
accessToken: accessToken
4949
};
50+
console.trace( '** Facebook strategy!' );
5051
return done( null, allUserData );
5152
}
5253
));
@@ -152,6 +153,13 @@ app.configure(function () {
152153
}
153154
next();
154155
} );
156+
app.use( function( req, res, next ) {
157+
if( req.query[ 'auth-return' ])
158+
{
159+
req.session[ 'auth-return' ] = req.query[ 'auth-return' ];
160+
}
161+
next();
162+
});
155163
app.use(express.static(__dirname+'/dist'));
156164

157165
});
@@ -169,37 +177,55 @@ app.get('/auth/connections', function (req, res) {
169177
}
170178
});
171179

172-
app.get( '/auth/facebook',
173-
passport.authenticate( 'facebook' ));
174-
app.get(
175-
'/auth/facebook/callback',
176-
passport.authenticate( 'facebook', { failureRedirect: '#auth-failure' }),
180+
app.get( '/auth/imap',
177181
function( req, res ) {
178-
res.redirect( '/' );
182+
res.redirect( '/#imap' );
179183
}
180184
);
181-
app.get( '/auth/twitter',
182-
passport.authenticate( 'twitter' ));
183-
app.get(
184-
'/auth/twitter/callback',
185-
passport.authenticate( 'twitter', { failureRedirect: '#auth-failure' }),
185+
186+
app.get( '/auth/facebook/callback',
187+
passport.authenticate( 'facebook', { failureRedirect: '#auth-failure' } ),
186188
function( req, res ) {
187-
res.redirect( '/' );
189+
if( req.session[ 'auth-return' ] )
190+
res.redirect( req.session[ 'auth-return' ]);
191+
else
192+
res.redirect( '/' );
188193
}
189194
);
190-
app.get( '/auth/gmail',
191-
passport.authenticate( 'gmail' ));
192-
app.get(
193-
'/auth/gmail/callback',
194-
passport.authenticate( 'gmail', { failureRedirect: '#auth-failure' }),
195+
196+
app.get( '/auth/twitter/callback',
197+
passport.authenticate( 'twitter', { failureRedirect: '#auth-failure' } ),
195198
function( req, res ) {
196-
res.redirect( '/' );
199+
if( req.session[ 'auth-return' ] )
200+
res.redirect( req.session[ 'auth-return' ]);
201+
else
202+
res.redirect( '/' );
197203
}
198204
);
199-
app.post( '/auth/imap/callback',
200-
passport.authenticate( 'imap', { failureRedirect: '#auth-failure' }),
205+
206+
app.get( '/auth/imap/callback',
207+
passport.authenticate( 'imap', { failureRedirect: '#auth-failure' } ),
208+
function( req, res ) {
209+
if( req.session[ 'auth-return' ] )
210+
res.redirect( req.session[ 'auth-return' ]);
211+
else
212+
res.redirect( '/' );
213+
}
214+
);
215+
216+
app.get( '/auth/gmail/callback',
217+
passport.authenticate( 'gmail', { failureRedirect: '#auth-failure' } ),
218+
function( req, res ) {
219+
if( req.session[ 'auth-return' ] )
220+
res.redirect( req.session[ 'auth-return' ]);
221+
else
222+
res.redirect( '/' );
223+
}
224+
);
225+
226+
app.get( '/auth/:service',
201227
function( req, res ) {
202-
res.redirect( '/' );
228+
( passport.authenticate( req.params.service ))( req, res );
203229
}
204230
);
205231

0 commit comments

Comments
 (0)