Added "Compose New Tweet" form on Twitter API demo
This commit is contained in:
2
app.js
2
app.js
@ -129,6 +129,7 @@ app.post('/account/profile', passportConf.isAuthenticated, userController.postUp
|
||||
app.post('/account/password', passportConf.isAuthenticated, userController.postUpdatePassword);
|
||||
app.post('/account/delete', passportConf.isAuthenticated, userController.postDeleteAccount);
|
||||
app.get('/account/unlink/:provider', passportConf.isAuthenticated, userController.getOauthUnlink);
|
||||
|
||||
app.get('/api', apiController.getApi);
|
||||
app.get('/api/lastfm', apiController.getLastfm);
|
||||
app.get('/api/nyt', apiController.getNewYorkTimes);
|
||||
@ -146,6 +147,7 @@ app.get('/api/tumblr', passportConf.isAuthenticated, passportConf.isAuthorized,
|
||||
app.get('/api/facebook', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getFacebook);
|
||||
app.get('/api/github', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getGithub);
|
||||
app.get('/api/twitter', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getTwitter);
|
||||
app.post('/api/twitter', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.postTwitter);
|
||||
app.get('/api/venmo', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getVenmo);
|
||||
app.post('/api/venmo', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.postVenmo);
|
||||
app.get('/api/linkedin', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getLinkedin);
|
||||
|
@ -262,6 +262,29 @@ exports.getTwitter = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.postTwitter = function(req, res, next) {
|
||||
req.assert('tweet', 'Tweet cannot be empty.').notEmpty();
|
||||
|
||||
var errors = req.validationErrors();
|
||||
|
||||
if (errors) {
|
||||
req.flash('errors', errors);
|
||||
return res.redirect('/api/twitter');
|
||||
}
|
||||
|
||||
var token = _.findWhere(req.user.tokens, { kind: 'twitter' });
|
||||
var T = new Twit({
|
||||
consumer_key: secrets.twitter.consumerKey,
|
||||
consumer_secret: secrets.twitter.consumerSecret,
|
||||
access_token: token.accessToken,
|
||||
access_token_secret: token.tokenSecret
|
||||
});
|
||||
T.post('statuses/update', { status: req.body.tweet }, function(err, data, response) {
|
||||
req.flash('success', { msg: 'Tweet has been posted.'});
|
||||
res.redirect('/api/twitter');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /api/steam
|
||||
* Steam API example.
|
||||
|
@ -18,7 +18,27 @@ block content
|
||||
| API Endpoints
|
||||
|
||||
br
|
||||
.lead Latest #{tweets.length} Tweets containing the term "nodejs" in NYC within 5 miles radius
|
||||
|
||||
.well
|
||||
h4 Compose new Tweet
|
||||
form(role='form', method='POST')
|
||||
input(type='hidden', name='_csrf', value=_csrf)
|
||||
.form-group
|
||||
input.form-control(type='text', name='tweet', autofocus)
|
||||
p.help-block This new Tweet will be posted on your Twitter profile.
|
||||
button.btn.btn-primary(type='submit')
|
||||
i.fa.fa-twitter
|
||||
| Tweet
|
||||
|
||||
br
|
||||
|
||||
.lead Latest
|
||||
strong #{tweets.length}
|
||||
| Tweets containing the term
|
||||
strong nodejs
|
||||
| in NYC within
|
||||
strong 5
|
||||
| miles radius
|
||||
|
||||
ul.media-list
|
||||
for tweet in tweets
|
||||
|
Reference in New Issue
Block a user