Skip to content
Browse files

Use twitter observer

  • Loading branch information...
1 parent fd4efa9 commit bd346703fdbe0e280bdbdeb6b557e3f592b34060 Anatoliy Chakkaev committed May 27, 2011
Showing with 15 additions and 3 deletions.
  1. +1 −3 README.md
  2. +14 −0 install.js
View
4 README.md
@@ -22,7 +22,7 @@ as event emitter, so you can:
// redirect user to a proper location
});
-Just put code like this into the environment settings (`config/environment.js`):
+Example of `app/observers/twitter_observer`:
app.on('twitterConnect', function (twitter, req, res) {
User.findOne({twitterId: twitter.id}, function (err, user) {
@@ -34,5 +34,3 @@ Just put code like this into the environment settings (`config/environment.js`):
});
res.redirect('/');
});
-
-Ideally, in application should be specific place for stuff like this (maybe app/observers).
View
14 install.js
@@ -13,11 +13,25 @@ var config = [
' callbackPath: "/twitter_callback"'
].join('\n');
+var observer = [
+ 'app.on(\'twitterConnect\', function (user, req, res) {',
+ ' var location = req.session && req.session.beforeTwitterAuth || \'/\';',
+ ' delete req.session.beforeTwitterAuth;',
+ ' redirect(location);',
+ '});'
+].join('\n');
+
var fs = require('fs');
var path = require('path');
if (path.existsSync(app.root + '/config') && !path.existsSync(app.root + '/config/twitter.yml')) {
fs.writeFileSync(app.root + '/config/twitter.yml', config);
+ console.log('new file ./config/twitter.yml');
+}
+
+if (path.existsSync(app.root + '/observers') && !path.existsSync(app.root + '/observers/twitter_observer.js')) {
+ fs.writeFileSync(app.root + '/observers/twitter_observer.js', observer);
+ console.log('new file ./observers/twitter_observer.js');
}
process.exit(0);

0 comments on commit bd34670

Please sign in to comment.
Something went wrong with that request. Please try again.