diff --git a/controllers/api.js b/controllers/api.js index 543e257a567..5d50c349b33 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -21,6 +21,14 @@ exports.getApi = function(req, res) { * GET /api/foursquare */ exports.getFoursquare = function(req, res) { + if (!req.user.tokens.foursquare) { + return res.render('api/unauthorized', { + title: 'Foursquare API', + provider: 'Foursquare', + user: req.user + }); + } + async.parallel({ trendingVenues: function(callback) { var geo = geoip.lookup('4.17.136.0'); @@ -43,12 +51,8 @@ exports.getFoursquare = function(req, res) { } }, function(err, results) { - if (err) { - req.flash('info', err); - } res.render('api/foursquare', { title: 'Foursquare API', - message: req.flash('info'), user: req.user, trendingVenues: results.trendingVenues, venueDetail: results.venueDetail, diff --git a/views/api/foursquare.jade b/views/api/foursquare.jade index 09d7c727fa9..c2c787ab6a3 100644 --- a/views/api/foursquare.jade +++ b/views/api/foursquare.jade @@ -1,64 +1,54 @@ extends ../layout block content - if !user.tokens.foursquare - h3 - i.fa.fa-shield - | Authorization Required - a(href='/auth/foursquare') - .label.label-primary.label-block - h2 - i.fa.fa-qrcode - | Get Foursquare Token - else + .page-header h1 i.fa.fa-foursquare | Foursquare APIs - .btn-group.btn-group-justified - a.btn.btn-lg.btn-primary(href='https://developer.foursquare.com/start', target='_blank') - i.fa.fa-check-square-o - | Getting Started - a.btn.btn-lg.btn-primary(href='https://developer.foursquare.com/docs/explore', target='_blank') - i.fa.fa-laptop - | API Console - a.btn.btn-lg.btn-primary(href='https://developer.foursquare.com/docs/', target='_blank') - i.fa.fa-code-fork - | API Endpoints - - h3.text-primary Trending Venues - table.dataTable.table.table-striped.table-bordered - thead + .btn-group.btn-group-justified + a.btn.btn-lg.btn-primary(href='https://developer.foursquare.com/start', target='_blank') + i.fa.fa-check-square-o + | Getting Started + a.btn.btn-lg.btn-primary(href='https://developer.foursquare.com/docs/explore', target='_blank') + i.fa.fa-laptop + | API Console + a.btn.btn-lg.btn-primary(href='https://developer.foursquare.com/docs/', target='_blank') + i.fa.fa-code-fork + | API Endpoints + h3.text-primary Trending Venues + table.dataTable.table.table-striped.table-bordered + thead + tr + th Name + th.hidden-xs.hidden-sm Category + th.hidden-xs Checkins + th Here Now + tbody + for venue in trendingVenues.venues tr - th Name - th.hidden-xs.hidden-sm Category - th.hidden-xs Checkins - th Here Now - tbody - for venue in trendingVenues.venues - tr - td= venue.name - td.hidden-xs.hidden-sm #{venue.categories[0].name} - td.hidden-xs #{venue.stats.checkinsCount} - td= venue.hereNow.count - h3.text-primary Venue Detail - p - img(src='#{venueDetail.venue.photos.groups[0].items[0].prefix}150x150#{venueDetail.venue.photos.groups[0].items[0].suffix}') - .label.label-primary #{venueDetail.venue.name} (#{venueDetail.venue.categories[0].shortName}) - .label.label-success #{venueDetail.venue.location.address}, #{venueDetail.venue.location.city}, #{venueDetail.venue.location.state} - .label.label-warning #{venueDetail.venue.likes.count} likes, #{venueDetail.venue.rating} rating + td= venue.name + td.hidden-xs.hidden-sm #{venue.categories[0].name} + td.hidden-xs #{venue.stats.checkinsCount} + td= venue.hereNow.count + h3.text-primary Venue Detail + p + img(src='#{venueDetail.venue.photos.groups[0].items[0].prefix}150x150#{venueDetail.venue.photos.groups[0].items[0].suffix}') + .label.label-primary #{venueDetail.venue.name} (#{venueDetail.venue.categories[0].shortName}) + .label.label-success #{venueDetail.venue.location.address}, #{venueDetail.venue.location.city}, #{venueDetail.venue.location.state} + .label.label-warning #{venueDetail.venue.likes.count} likes, #{venueDetail.venue.rating} rating - h3.text-primary User Checkins - table.dataTable.table.table-bordered.table-hover - thead + h3.text-primary User Checkins + table.dataTable.table.table-bordered.table-hover + thead + tr + th Name + th Location + th Category + th Checkins + tbody + for checkin in userCheckins.checkins.items tr - th Name - th Location - th Category - th Checkins - tbody - for checkin in userCheckins.checkins.items - tr - td= checkin.venue.name - td #{checkin.venue.location.address}, #{checkin.venue.location.city}, #{checkin.venue.location.state} - td= checkin.venue.categories[0].shortName - td= checkin.venue.stats.checkinsCount + td= checkin.venue.name + td #{checkin.venue.location.address}, #{checkin.venue.location.city}, #{checkin.venue.location.state} + td= checkin.venue.categories[0].shortName + td= checkin.venue.stats.checkinsCount diff --git a/views/api/unauthorized.jade b/views/api/unauthorized.jade new file mode 100644 index 00000000000..d4c0929ae25 --- /dev/null +++ b/views/api/unauthorized.jade @@ -0,0 +1,9 @@ +extends ../layout + +block content + h3 + i.fa.fa-lock + | Authorization Required + a.btn.btn-lg.btn-primary(href='/auth/foursquare') + i.fa.fa-qrcode + | Get #{provider} Token \ No newline at end of file