diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 2c5dcae..52c247e 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -1,3 +1,4 @@ +#= require facebook #= require jquery #= require twitter/bootstrap #= require angular diff --git a/app/assets/javascripts/controllers/playlist_new_ctrl.js.coffee b/app/assets/javascripts/controllers/playlist_new_ctrl.js.coffee index 6119488..6964cc5 100644 --- a/app/assets/javascripts/controllers/playlist_new_ctrl.js.coffee +++ b/app/assets/javascripts/controllers/playlist_new_ctrl.js.coffee @@ -45,7 +45,7 @@ ocarina.controller 'PlaylistNewCtrl', ['$rootScope', '$scope', '$location', 'Fac $location.path("/playlists/#{res.data.id}") $scope.currentUser.playlists.push(res.data) message = "I just created a playlist for this event on PlayedBy.me. Go to the site now or at the party to add songs you want to hear!" - link = "http://localhost:4400/playlists/#{res.data.id}" + link = "http://#{Playedbyme.env.domain}/playlists/#{res.data.id}" name = "#{fbEvent.name}'s playlist" # TODO uncomment this when we can prompt user to post # Facebook.postOnEvent(fbEvent.id, message, link, name) diff --git a/app/assets/javascripts/facebook.js.coffee b/app/assets/javascripts/facebook.js.coffee index 7d44135..7f03fe8 100644 --- a/app/assets/javascripts/facebook.js.coffee +++ b/app/assets/javascripts/facebook.js.coffee @@ -1,3 +1,51 @@ +setCookie = (c_name, value, exdays) -> + exdate = new Date() + exdate.setDate exdate.getDate() + exdays + c_value = escape(value) + ((if (not (exdays?)) then "" else "; expires=" + exdate.toUTCString())) + document.cookie = c_name + "=" + c_value + +getCookie = (c_name) -> + c_value = document.cookie + c_start = c_value.indexOf(" " + c_name + "=") + c_start = c_value.indexOf(c_name + "=") if c_start is -1 + if c_start is -1 + c_value = null + else + c_start = c_value.indexOf("=", c_start) + 1 + c_end = c_value.indexOf(";", c_start) + c_end = c_value.length if c_end is -1 + c_value = unescape(c_value.substring(c_start, c_end)) + c_value + +window.fbAsyncInit = -> + console.log "app initialized" + FB.init + appId: "#{Playedbyme.env.facebookAppId}" + channelUrl: "//#{Playedbyme.env.domain}/channel.html" + status: true # check login status + cookie: true # enable cookies to allow the server to access the session + xfbml: true # parse XFBML + + FB.Event.subscribe "auth.authResponseChange", (res) -> + if res.status is "connected" + return if getCookie("user_id") + auth = res.authResponse + FB.api '/me?fields=picture,first_name,last_name,email', (res) -> + authParams = + id: res.id + first_name: res.first_name + last_name: res.last_name + email: res.email + image: res.picture.data.url + access_token: auth.accessToken + $.get "#{apiURL}/api/users/authenticate.json", authParams, (data) -> + setCookie("user_id", data.id, 1) + window.location.replace "#{Playedbyme.env.domain}?user_id=#{data.id}" + else if res.status is "not_authorized" + # if user logged in but hasn't authed app + else + # if user logged out + # load the SDK asynchronously ((d) -> js = undefined @@ -9,4 +57,4 @@ js.async = true js.src = "//connect.facebook.net/en_US/all.js" ref.parentNode.insertBefore js, ref -) document +) document, false diff --git a/app/assets/javascripts/services.js.coffee b/app/assets/javascripts/services.js.coffee index f98647a..0d899fc 100644 --- a/app/assets/javascripts/services.js.coffee +++ b/app/assets/javascripts/services.js.coffee @@ -1,11 +1,11 @@ # API URL -@apiURL = "" +@apiURL = Playedbyme.env.apiURL ocarinaServices = angular.module('ocarinaServices', []) ocarinaServices.factory 'Pusher', -> if Pusher? - pusher = new Pusher("e9eb3f912d37215f7804") + pusher = new Pusher(Playedbyme.env.pusherKey) else # if pusher doesn't load subscribe: -> @@ -60,34 +60,6 @@ ocarinaServices.factory 'Authentication', ['$http', ($http) -> Authentication.deferDropbox = (user_id) -> $http.post "/defer_dropbox_connect", user_id: user_id - window.fbAsyncInit = -> - FB.init - appId: "160916744087752" - channelUrl: "//localhost:4400/channel.html" - status: true # check login status - cookie: true # enable cookies to allow the server to access the session - xfbml: true # parse XFBML - - FB.Event.subscribe "auth.authResponseChange", (res) -> - if res.status is "connected" - return if Authentication.getCookie("user_id") - auth = res.authResponse - FB.api '/me?fields=picture,first_name,last_name,email', (res) -> - authParams = - id: res.id - first_name: res.first_name - last_name: res.last_name - email: res.email - image: res.picture.data.url - access_token: auth.accessToken - $.get "#{apiURL}/api/users/authenticate.json", authParams, (data) -> - Authentication.setCookie("user_id", data.id, 1) - window.location.replace "http://localhost:4400?user_id=#{data.id}" - else if res.status is "not_authorized" - # if user logged in but hasn't authed app - else - # if user logged out - Authentication ] @@ -235,8 +207,8 @@ ocarinaServices.factory 'Player', ['Audio', (Audio) -> ] ocarinaServices.factory 'Facebook', ['$http', ($http) -> - api_url = "http://facebook.com" - app_id = '227387824081363' + api_url = "http://facebook.com" + app_id = Playedbyme.env.facebookAppId Facebook = (data) -> angular.extend(this, data) @@ -253,7 +225,7 @@ ocarinaServices.factory 'Facebook', ['$http', ($http) -> Facebook.sendDialog = (playlist_id) -> FB.ui method: "send" - link: "http://played-by-me.herokuapp.com/playlists/#{playlist_id}" + link: "http://#{Playedbyme.env.domain}/playlists/#{playlist_id}" Facebook.getUsersFavoriteArtists = (id, callback) -> FB.api "/#{id}/music", (res) -> diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 2323da9..04530ce 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -7,22 +7,16 @@ %title= content_for?(:title) ? yield(:title) : "Playedby.me" = stylesheet_link_tag "application", media: "all" = csrf_meta_tags + :javascript - (function(d) { - var id, js, ref; - js = void 0; - id = "facebook-jssdk"; - ref = d.getElementsByTagName("script")[0]; - if (d.getElementById(id)) { - return; + var Playedbyme = { + env: { + apiURL: "", + domain: window.location.origin, + facebookAppId: "160916744087752", + pusherKey: "#{Rails.configuration.pusher_key}" } - js = d.createElement("script"); - js.id = id; - js.async = true; - js.src = "//connect.facebook.net/en_US/all.js"; - return ref.parentNode.insertBefore(js, ref); - })(document); - + }; %body.ng-cloak{ ng_controller: 'UserCtrl' } .logged-out{ ocarina_if: "!auth.loggedIn", ng_include:"'/partials/logged_out'" } @@ -37,6 +31,7 @@ = javascript_include_tag "http://js.pusher.com/2.1/pusher.min.js" = javascript_include_tag "http://connect.soundcloud.com/sdk.js" = javascript_include_tag "application" + :javascript SC.initialize({ client_id: "3d6e76640c62f42c02cb78d2c53d0db9" diff --git a/app/views/partials/_footer.html.haml b/app/views/partials/_footer.html.haml index 29f8f8a..2dc4eac 100644 --- a/app/views/partials/_footer.html.haml +++ b/app/views/partials/_footer.html.haml @@ -6,5 +6,5 @@ %a{ng_href: "", target: "_blank" } Our Blog %a{ng_href: "/contact" } Contact %a{ng_href: "/about" } About Us - %a.legal{ng_href: "//localhost:4400/partials/legal/tos", target: "_blank" } Terms - %a.legal{ng_href: "//localhost:4400/partials/legal/privacy", target: "_blank" } Privacy + %a.legal{ng_href: "//#{Rails.configuration.domain}/partials/legal/tos", target: "_blank" } Terms + %a.legal{ng_href: "//#{Rails.configuration.domain}/partials/legal/privacy", target: "_blank" } Privacy diff --git a/config/environments/development.rb b/config/environments/development.rb index 0b368ce..d6e5f4b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -32,14 +32,22 @@ config.smtp_password = ENV['SMTP_PASSWORD'] || 'jarpadarp' # API URLs + config.api_url = ENV['API_URL'] || 'http://localhost:4400' config.web_url = ENV['WEB_URL'] || 'http://localhost:4400' config.mobile_web_url = ENV['MOBILE_WEB_URL'] || 'http://localhost:8000' + # API ID/Secret Keys + config.facebook_app_id = ENV['FACEBOOK_APP_ID'] || raise_for('FACEBOOK_APP_ID') + config.pusher_key = ENV['PUSHER_KEY'] || raise_for('PUSHER_APP_ID') + + # Other + config.domain = ENV['DOMAIN'] || 'localhost:4400' + ## # CORS support config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors", :debug => true, :logger => Rails.logger do allow do - origins Rails.configuration.mobile_web_url + origins Rails.configuration.mobile_web_url, Rails.configuration.api_url resource '/api/*', headers: :any, diff --git a/config/environments/production.rb b/config/environments/production.rb index b777e2f..fd9965b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -81,22 +81,30 @@ def raise_for(str) # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new - # + # Email Options config.smtp_user_name = ENV['SMTP_USER_NAME'] || raise_for('SMTP_USER_NAME') config.smtp_password = ENV['SMTP_PASSWORD'] || raise_for('SMTP_PASSWORD') # API URLs + config.api_url = ENV['API_URL'] || raise_for('API_URL') config.web_url = ENV['WEB_URL'] || raise_for('WEB_URL') config.mobile_web_url = ENV['MOBILE_WEB_URL'] || raise_for('MOBILE_WEB_URL') + # API ID/Secret Keys + config.facebook_app_id = ENV['FACEBOOK_APP_ID'] || raise_for('FACEBOOK_APP_ID') + config.pusher_key = ENV['PUSHER_KEY'] || raise_for('PUSHER_APP_ID') + + # Other + config.domain = ENV['DOMAIN'] || raise_for('DOMAIN') + ## # CORS support config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors" do allow do - origins Rails.configuration.mobile_web_url + origins Rails.configuration.mobile_web_url, "http://techstars.playedby.me", "http://yc.playedby.me" - resource '/api/*', + resource '/api/*', headers: :any, methods: [:get, :post] end