Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Token is rendered now in view
Browse files Browse the repository at this point in the history
  • Loading branch information
iltempo committed May 31, 2010
1 parent d7e9b40 commit 8b1b048
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
16 changes: 6 additions & 10 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ Your API key <api_key> can be found in the API section of the admin documentatio
Default properties are stored in a file named uservoice.yml in the config
directory of your Rails application. Make it fitting to your needs.

Link Uservoice javascript file and add configuration to HTML HEAD
section of your template file:
<%= javascript_include_tag 'uservoice' %>
Add javascript function and configuration to HTML HEAD section of your template file:
<%= uservoice_config_javascript %>

You can override default uservoice settings in your view:
<%= uservoice_config_javascript(:alignment => 'right', :forum => 12983) %>


== Single Sign-on
== Single Sign-On

Single sign-on authenticates your users automatically against the Uservoice
service. The second login is not needed any more.
service. A second login is not needed any more.

Uservoice is allowing single sign-on starting from the Bronze plan.
http://uservoice.com/signup?ref=nav
Expand All @@ -47,12 +45,10 @@ To use single sign-on with on uservoice you have to set your api_key in
config/uservoice.yml. Find it on
https://ACCOUNT.uservoice.com/admin2/docs#/legacy_api

Set user data in your controller action.
def index
set_uservoice_sso(:guid => @current_user.id, :email => @current_user.email)
end
The user properties can be set via the :sso parameter.
<%= uservoice_config_javascript(:sso => {:guid => @current_user.id, :email => @current_user.email}) %>

Parameter <em>:guid</em> should be unique identifier for example the user id in your
Parameter <em>:guid</em> should be unique identifier, for example the user id in your
system. Uservoice recommends setting <em>:email</em> parameter to enable users to get
updates and notifications via email.
See https://ACCOUNT.uservoice.com/admin2/docs#/sso for a list of parameters
Expand Down
13 changes: 2 additions & 11 deletions lib/uservoice/instance_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@ def uservoice_configuration_file #:nodoc:
"#{RAILS_ROOT}/config/uservoice.yml"
end

# Generates token for uservoice single sign-on
# that will be delivered by uservoice helper.
# See https://ACCOUNT.uservoice.com/admin2/docs#/sso for
# properties available.
# Returns the uservoice configuration hash.
# It's been lazy loaded and cached in the controller class.
#
def set_uservoice_sso(user_data)
@uservoice_sso_token = Uservoice::Token.new(
uservoice_configuration['uservoice_options']['key'],
uservoice_configuration['uservoice_api']['api_key'],
user_data)
end

def uservoice_configuration
@@uservoice_configuration = begin
configuration = YAML::load(IO.read(uservoice_configuration_file))
Expand Down
7 changes: 5 additions & 2 deletions lib/uservoice/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ def uservoice_config_javascript(options={})
config = uservoice_configuration['uservoice_options'].dup
config.merge!(options)

if @uservoice_sso_token
config.merge!({:params => {:sso => @uservoice_sso_token.data}})
if config[:sso] && config[:sso][:guid]
config.merge!(:params => {:sso => Uservoice::Token.new(
uservoice_configuration['uservoice_options']['key'],
uservoice_configuration['uservoice_api']['api_key'],
config.delete(:sso)).to_s})
end

<<-EOS
Expand Down
3 changes: 1 addition & 2 deletions test/test_uservoice_sso.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ def uservoice_configuration_file
end

def action_with_sso
set_uservoice_sso(:guid => 123, :display_name => 'Bancheff', :email => '[email protected]')
render :inline => '<%= uservoice_config_javascript %>'
render :inline => '<%= uservoice_config_javascript(:sso => {:guid => 123, :display_name => "Bancheff", :email => "[email protected]"}) %>'
end

end
Expand Down

0 comments on commit 8b1b048

Please sign in to comment.