Browse files

Redirect Users to attempted URL if page required authentication first

  • Loading branch information...
1 parent 270ffbb commit 94e2c32170959f0af2720091036019e21e80cf5f @dstroot committed Mar 5, 2014
Showing with 55 additions and 11 deletions.
  1. +1 −0 config/passport.js
  2. +0 −1 controllers/api.js
  3. +50 −6 controllers/user.js
  4. +1 −1 package.json
  5. +1 −1 public/css/Skeleton.min.css
  6. +1 −1 public/js/Skeleton.min.js
  7. +1 −1 public/js/Skeleton.min.js.map
View
1 config/passport.js
@@ -188,6 +188,7 @@ exports.isAuthenticated = function (req, res, next) {
if (req.isAuthenticated()) {
return next();
} else {
+ req.session.attemptedURL = req.url; // Save URL so we can redirect to it after authentication
res.set('X-Auth-Required', 'true');
req.flash('errors', { msg: 'You must be logged in to reach that page.' });
res.redirect('/login');
View
1 controllers/api.js
@@ -315,7 +315,6 @@ module.exports.controller = function(app) {
token_secret: token.tokenSecret
});
client.posts('danielmoyerdesign.tumblr.com', { type: 'photo' }, function (err, data) {
- console.log('data: ' + JSON.stringify(data));
res.render('api/tumblr', {
url: '/apilocked',
blog: data.blog,
View
56 controllers/user.js
@@ -45,7 +45,6 @@ module.exports.controller = function (app) {
app.post('/login', function (req, res, next) {
-
// Begin a workflow
var workflow = new (require('events').EventEmitter)();
@@ -162,7 +161,16 @@ module.exports.controller = function (app) {
req.flash('errors', { msg: err.message });
return res.redirect('back');
}
- return res.redirect('/api');
+
+ // Send user on their merry way
+ if (req.session.attemptedURL) {
+ var redirectURL = req.session.attemptedURL;
+ delete req.session.attemptedURL;
+ res.redirect(redirectURL);
+ } else {
+ res.redirect('/api');
+ }
+
});
}
@@ -849,7 +857,16 @@ module.exports.controller = function (app) {
if (err) {
return next(err);
}
- return res.redirect('/api');
+
+ // Send user on their merry way
+ if (req.session.attemptedURL) {
+ var redirectURL = req.session.attemptedURL;
+ delete req.session.attemptedURL;
+ return res.redirect(redirectURL);
+ } else {
+ return res.redirect('/api');
+ }
+
});
});
} else {
@@ -917,7 +934,16 @@ module.exports.controller = function (app) {
if (err) {
return next(err);
}
- return res.redirect('/api');
+
+ // Send user on their merry way
+ if (req.session.attemptedURL) {
+ var redirectURL = req.session.attemptedURL;
+ delete req.session.attemptedURL;
+ return res.redirect(redirectURL);
+ } else {
+ return res.redirect('/api');
+ }
+
});
});
} else {
@@ -985,7 +1011,16 @@ module.exports.controller = function (app) {
if (err) {
return next(err);
}
- return res.redirect('/api');
+
+ // Send user on their merry way
+ if (req.session.attemptedURL) {
+ var redirectURL = req.session.attemptedURL;
+ delete req.session.attemptedURL;
+ return res.redirect(redirectURL);
+ } else {
+ return res.redirect('/api');
+ }
+
});
});
} else {
@@ -1053,7 +1088,16 @@ module.exports.controller = function (app) {
if (err) {
return next(err);
}
- return res.redirect('/api');
+
+ // Send user on their merry way
+ if (req.session.attemptedURL) {
+ var redirectURL = req.session.attemptedURL;
+ delete req.session.attemptedURL;
+ return res.redirect(redirectURL);
+ } else {
+ return res.redirect('/api');
+ }
+
});
});
} else {
View
2 package.json
@@ -1,6 +1,6 @@
{
"private": true,
- "version": "0.0.2",
+ "version": "0.0.2-1",
"name": "Skeleton",
"company": "Skeleton, Inc.",
"subdomain": "skeleton-app",
View
2 public/css/Skeleton.min.css
@@ -1,6 +1,6 @@
/**
* Skeleton - A friendly node and express framework
- * @version v0.0.2
+ * @version v0.0.2-1
* @link http://skeleton-app.jit.su
* @license
*/
View
2 public/js/Skeleton.min.js
@@ -1,6 +1,6 @@
/**
* Skeleton - A friendly node and express framework
- * @version v0.0.2
+ * @version v0.0.2-1
* @link http://skeleton-app.jit.su
* @license
*/
View
2 public/js/Skeleton.min.js.map
@@ -1,6 +1,6 @@
/**
* Skeleton - A friendly node and express framework
- * @version v0.0.2
+ * @version v0.0.2-1
* @link http://skeleton-app.jit.su
* @license
*/

0 comments on commit 94e2c32

Please sign in to comment.