2014-03-21 03:23:33 +00:00
|
|
|
require 'base64'
|
|
|
|
|
require 'js_connect'
|
|
|
|
|
|
|
|
|
|
class VanillaForumsController < ApplicationController
|
|
|
|
|
|
2015-01-01 05:17:47 +00:00
|
|
|
def log
|
|
|
|
|
@log || Logging.logger[VanillaForumsController ]
|
|
|
|
|
end
|
2014-03-21 03:23:33 +00:00
|
|
|
|
|
|
|
|
# displays the embedded forum
|
|
|
|
|
# see http://vanillaforums.com/blog/jsconnect-technical-documentation-for-embedded-sso/
|
|
|
|
|
def show
|
|
|
|
|
|
|
|
|
|
user = {name: '', photourl: ''}
|
|
|
|
|
if current_user
|
2014-10-02 19:04:36 +00:00
|
|
|
name = current_user.admin ? "#{current_user.name} #{Rails.application.config.vanilla_staff_postfix}" : current_user.name
|
|
|
|
|
user = {email: current_user.email, name: name,
|
2014-03-21 03:23:33 +00:00
|
|
|
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
|
|
|
|
|
|
2014-10-02 19:04:36 +00:00
|
|
|
name = current_user.admin ? "#{current_user.name} #{Rails.application.config.vanilla_staff_postfix}" : current_user.name
|
|
|
|
|
user = {'email' => current_user.email, 'name' => name,
|
2014-03-21 03:23:33 +00:00
|
|
|
'photourl' => current_user.resolved_photo_url,
|
|
|
|
|
'uniqueid' => current_user.id}
|
|
|
|
|
|
2015-01-01 05:17:47 +00:00
|
|
|
log.debug("user is logged in: #{user}")
|
2014-03-21 03:23:33 +00:00
|
|
|
else
|
2015-01-01 05:17:47 +00:00
|
|
|
log.debug("user is not logged in")
|
2014-03-21 03:23:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render :json => JsConnect::getJsConnectString(user, request,
|
2016-12-05 15:00:49 +00:00
|
|
|
Rails.application.config.vanilla_client_id, Rails.application.config.vanilla_secret), :content_type => 'application/javascript'
|
2014-03-21 03:23:33 +00:00
|
|
|
|
|
|
|
|
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
|