diff --git a/web/app/assets/stylesheets/client/content.css.scss b/web/app/assets/stylesheets/client/content.css.scss index 108892b37..ad578a628 100644 --- a/web/app/assets/stylesheets/client/content.css.scss +++ b/web/app/assets/stylesheets/client/content.css.scss @@ -429,7 +429,7 @@ ul.shortcuts { padding:2px; } - .account-home, .band-setup, .audio, .get-help, .download-app, .invite-friends { + .account-home, .band-setup, .audio, .get-help, .download-app, .community-forum, .invite-friends { border-bottom:1px; border-style:solid; border-color:#ED3618; diff --git a/web/app/controllers/clients_controller.rb b/web/app/controllers/clients_controller.rb index 32ca78db0..0f89b42de 100644 --- a/web/app/controllers/clients_controller.rb +++ b/web/app/controllers/clients_controller.rb @@ -28,11 +28,7 @@ class ClientsController < ApplicationController gon.use_cached_session_scores = Rails.application.config.use_cached_session_scores gon.allow_both_find_algos = Rails.application.config.allow_both_find_algos - #if current_user - render :layout => 'client' - #else - # redirect_to root_url - #end + render :layout => 'client' end AUTHED = %W{friend} diff --git a/web/app/controllers/sessions_controller.rb b/web/app/controllers/sessions_controller.rb index caa63cbbf..fbeb8ec9f 100644 --- a/web/app/controllers/sessions_controller.rb +++ b/web/app/controllers/sessions_controller.rb @@ -5,6 +5,16 @@ class SessionsController < ApplicationController def new @login_error = false + @sso = params[:sso] + @send_back_to = request.headers['REFERER'] + params[:send_back_to] = @send_back_to + + if current_user + # send them on their way + complete_sign_in(current_user) + return + end + render :layout => "landing" end @@ -13,6 +23,8 @@ class SessionsController < ApplicationController if user.nil? @login_error = true + @sso = params[:sso] + @send_back_to = params[:send_back_to] render 'new', :layout => "landing" else @@ -133,16 +145,30 @@ class SessionsController < ApplicationController render 'oauth_complete', :layout => "landing" end + def redirect_after_signin(default) + redirect_to(params['redirect-to'].blank? ? default : params['redirect-to']) + end + + def redirect_to_forums_after_signin + redirect_to("#{Rails.application.config.vanilla_login_url}?client_id=#{Rails.application.config.vanilla_client_id}&Target=#{ERB::Util.url_encode(params[:send_back_to].blank? ? '/' : params[:send_back_to])}") + end + + def redirect_to_support_after_signin(user) + # generate multipass token and sign it + multipass = DeskMultipass.new(user) + callback_url = Rails.application.config.multipass_callback_url + redirect_to "#{callback_url}?multipass=#{multipass.token}&signature=#{multipass.signature}" + end + def complete_sign_in(user) sign_in user - if !params[:sso].nil? && params[:sso] == "desk" - # generate multipass token and sign it - multipass = DeskMultipass.new(user) - callback_url = SampleApp::Application.config.multipass_callback_url - redirect_to "#{callback_url}?multipass=#{multipass.token}&signature=#{multipass.signature}" + if params[:sso] == "desk" + redirect_to_support_after_signin(user) + elsif params[:sso] == 'forums' + redirect_to_forums_after_signin else - redirect_back_or client_url + redirect_after_signin(client_path) end end diff --git a/web/app/controllers/vanilla_forums_controller.rb b/web/app/controllers/vanilla_forums_controller.rb new file mode 100644 index 000000000..34a26dc6f --- /dev/null +++ b/web/app/controllers/vanilla_forums_controller.rb @@ -0,0 +1,63 @@ +require 'base64' +require 'js_connect' + +class VanillaForumsController < ApplicationController + + @@log = Logging.logger[VanillaForumsController] + + # displays the embedded forum + # see http://vanillaforums.com/blog/jsconnect-technical-documentation-for-embedded-sso/ + def show + + user = {name: '', photourl: ''} + if current_user + user = {email: current_user.email, name: current_user.username, + photourl: current_user.profile_pic, + uniqueid: current_user.username} + end + user.merge!({client_id: Rails.application.config.vanilla_client_id}) + + # json encode the user + json = ActiveSupport::JSON.encode(user); + # base 64 encode the user json + signature_string = Base64.strict_encode64(json) + # Sign the signature string with current timestamp using hmac sha1 + signature = Digest::HMAC.hexdigest(signature_string + ' ' + + Time.now.to_i.to_s, Rails.application.config.vanilla_secret, Digest::SHA1) + # build the final sso string + @vanilla_sso = "#{signature_string} #{signature} #{Time.now.to_i} hmacsha1" + + end + + # callback for vanilla authentication + # see http://vanillaforums.com/blog/jsconnect-technical-documentation + # ruby jsconnect client library: https://github.com/vanillaforums/jsConnectRuby + def authenticate + + user = {} + if current_user + + user = {'email' => current_user.email, 'name' => current_user.name, + 'photourl' => current_user.resolved_photo_url, + 'uniqueid' => current_user.id} + + @@log.debug("user is logged in: #{user}") + else + @@log.debug("user is not logged in") + end + + + render :json => JsConnect::getJsConnectString(user, request, + Rails.application.config.vanilla_client_id, Rails.application.config.vanilla_secret) + + end + + # only for testing; routes are conditionally based on test ENV + def fake_root + render layout: 'web' + end + # only for testing; routes are conditionally based on test ENV + def fake_jsconnect + render layout: 'web' + end +end \ No newline at end of file diff --git a/web/app/helpers/sessions_helper.rb b/web/app/helpers/sessions_helper.rb index 1c17dbe93..9966731a6 100644 --- a/web/app/helpers/sessions_helper.rb +++ b/web/app/helpers/sessions_helper.rb @@ -54,7 +54,7 @@ module SessionsHelper def sign_out current_user = nil - cookies.delete(:remember_token) + cookies.delete(:remember_token, domain: Rails.application.config.session_cookie_domain) end def redirect_back_or(default) diff --git a/web/app/views/clients/_footer.html.erb b/web/app/views/clients/_footer.html.erb index 805c33a68..5c4fee259 100644 --- a/web/app/views/clients/_footer.html.erb +++ b/web/app/views/clients/_footer.html.erb @@ -6,7 +6,7 @@ <%= render "clients/recordingManager" %> diff --git a/web/app/views/layouts/corporate.html.erb b/web/app/views/layouts/corporate.html.erb index b15738de9..0b973c562 100644 --- a/web/app/views/layouts/corporate.html.erb +++ b/web/app/views/layouts/corporate.html.erb @@ -63,7 +63,7 @@ - +
<%= version %>
diff --git a/web/app/views/sessions/new.html.erb b/web/app/views/sessions/new.html.erb index aa4334ee8..a59fb1cf6 100644 --- a/web/app/views/sessions/new.html.erb +++ b/web/app/views/sessions/new.html.erb @@ -16,8 +16,9 @@ Enter your email address and password:
- <%= form_for(:session, url: sessions_path) do |f| %> - + <%= form_for(:session, url: signin_path + (request.query_string.blank? ? '' : '?' + request.query_string)) do |f| %> + +