kete_browserid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/app/views/account/_login_form.html.erb +52 -0
- data/app/views/account/signup_as_browserid.html.erb +80 -0
- data/config/locales/en.yml +33 -0
- data/kete_browserid.gemspec +62 -0
- data/lib/kete_browserid.rb +4 -0
- data/lib/kete_browserid/extensions/controllers/account_controller.rb +95 -0
- data/lib/kete_browserid/extensions/controllers/application_controller.rb +41 -0
- data/lib/kete_browserid/extensions/helpers/application_helper.rb +53 -0
- data/lib/kete_browserid/extensions/models/user.rb +17 -0
- data/rails/init.rb +25 -0
- metadata +124 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Horowhenua Library Trust
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= kete_browserid
|
2
|
+
|
3
|
+
An add-on for Kete (http://kete.net.nz) that replaces normal login with a browserid based login.
|
4
|
+
|
5
|
+
== Requirements
|
6
|
+
|
7
|
+
Kete 1.4 or using the master branch.
|
8
|
+
|
9
|
+
Uses the gem Faraday to make requests to browserid.org.
|
10
|
+
|
11
|
+
== Limitations
|
12
|
+
|
13
|
+
Not currently compatible with Kete's "anonymous actions" functionality as it replaces the login form with browserid.org form. Might also have an issue with kete_translatable_content add-on gem due to possible conflict with javascript (guess).
|
14
|
+
|
15
|
+
== Installation
|
16
|
+
|
17
|
+
You'll want to check to make sure that all your users have unique email addresses first:
|
18
|
+
|
19
|
+
script/console # specify production if necessary
|
20
|
+
|
21
|
+
>> User.has_non_unique_emails?
|
22
|
+
|
23
|
+
If this method returns true, you'll need to look at your user emails and come up with plan to change them. This gem puts a "validates_uniqueness" on email once it is in place. Actually if you have legacy users, you'll want to come up with a plan to move them to BrowserID logins anyway.
|
24
|
+
|
25
|
+
== Note on Patches/Pull Requests
|
26
|
+
|
27
|
+
* Fork the project.
|
28
|
+
* Make your feature addition or bug fix in a corresponding branch (even better, make an issue first and name the branch with the ticket number in it)
|
29
|
+
* Add tests for it. This is important so I don't break it in a
|
30
|
+
future version unintentionally.
|
31
|
+
* Commit, do not mess with rakefile, version, or history.
|
32
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
33
|
+
* Send me a pull request.
|
34
|
+
|
35
|
+
== Credits
|
36
|
+
|
37
|
+
This work was funded by Aotearoa New Zealand Association of Social Workers (ANZASW).
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2012 Horowhenua Library Trust. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "kete_browserid"
|
8
|
+
gem.summary = %Q{An add-on for Kete (http://kete.net.nz) that replaces normal login with a browserid based login.}
|
9
|
+
gem.description = %Q{An add-on for Kete (http://kete.net.nz) that replaces normal login with a browserid based login.}
|
10
|
+
gem.email = "walter@katipo.co.nz"
|
11
|
+
gem.homepage = "http://github.com/kete/kete_browserid"
|
12
|
+
gem.authors = ["Walter McGinnis"]
|
13
|
+
gem.add_dependency "system_timer", ">= 0"
|
14
|
+
gem.add_dependency "faraday", ">= 0"
|
15
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
puts "Tests coming."
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "kete_browserid #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,52 @@
|
|
1
|
+
<fieldset>
|
2
|
+
<% unless ::KeteBrowserid::REPLACE_EXISTING_LOGIN -%>
|
3
|
+
<h3><%= t '.use_browserid' -%></h3>
|
4
|
+
<% end -%>
|
5
|
+
|
6
|
+
<p><%= t '.register_via_browserid',
|
7
|
+
:register_link => link_for_register_via_browserid -%></p>
|
8
|
+
<h4><%= link_for_login_with_browserid -%></h4>
|
9
|
+
</fieldset>
|
10
|
+
|
11
|
+
<% unless ::KeteBrowserid::REPLACE_EXISTING_LOGIN -%>
|
12
|
+
<p> </p>
|
13
|
+
<fieldset>
|
14
|
+
<h3><%= t '.or_standard_login' -%></h3>
|
15
|
+
|
16
|
+
<!--[form:login]-->
|
17
|
+
<% if Kete.is_configured? -%>
|
18
|
+
<p><%=t '.register',
|
19
|
+
:register_link => link_to(t('.register_link'),
|
20
|
+
{ :controller => 'account',
|
21
|
+
:action => 'signup',
|
22
|
+
:urlified_name => @site_basket.urlified_name},
|
23
|
+
:tabindex => '1') %></p>
|
24
|
+
<% else -%>
|
25
|
+
<p><%=t '.admin_details' %></p>
|
26
|
+
<% end -%>
|
27
|
+
|
28
|
+
<div class="form-element">
|
29
|
+
<label for="login"><%=t '.login' %></label>
|
30
|
+
<%= text_field_tag 'login', nil, :tabindex => '1' %>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div class="form-element">
|
34
|
+
<label for="password"><%=t '.password' %></label>
|
35
|
+
<%= password_field_tag 'password', nil, :tabindex => '1' %>
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<% if Kete.is_configured? -%>
|
39
|
+
<div class="form-element">
|
40
|
+
<label for="remember_me"><%=t '.remember_me' -%></label>
|
41
|
+
<%= check_box_tag 'remember_me', "1", false, :tabindex => '1' %>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<p><%=t '.forgot_password',
|
45
|
+
:forgot_password_link => link_to(t('.forgot_password_link'),
|
46
|
+
{ :controller => 'account',
|
47
|
+
:action => 'forgot_password',
|
48
|
+
:urlified_name => @site_basket.urlified_name},
|
49
|
+
:tabindex => '1') -%></p>
|
50
|
+
<% end -%>
|
51
|
+
</fieldset>
|
52
|
+
<% end -%>
|
@@ -0,0 +1,80 @@
|
|
1
|
+
<% @title = t('.title') -%>
|
2
|
+
|
3
|
+
<h2><%= h(@title) -%></h2>
|
4
|
+
|
5
|
+
<p><%= t ('.second_step') -%></p>
|
6
|
+
|
7
|
+
<% form_for :user do |f| -%>
|
8
|
+
<fieldset>
|
9
|
+
|
10
|
+
<%= error_messages_for :user %>
|
11
|
+
|
12
|
+
<%= f.hidden_field :email -%>
|
13
|
+
|
14
|
+
<div class="form-element">
|
15
|
+
<label for="user_login"><%=t '.short_name' %></label>
|
16
|
+
<%= f.text_field :login, :tabindex => '1' %>
|
17
|
+
<div class="form_example"><%=t '.short_name_example' %></div>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="form-element">
|
21
|
+
<label for="user_display_name"><%=t 'account.signup.user_name' %></label>
|
22
|
+
<%= f.text_field :display_name, :tabindex => '1' %>
|
23
|
+
<div class="form_example"><%=t '.user_name_example' %></div>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<% form_fields = @content_type.content_type_to_field_mappings -%>
|
27
|
+
<% if form_fields.size > 0 -%>
|
28
|
+
<%= render(:partial => 'extended_fields/extended_field_mapping',
|
29
|
+
:collection => form_fields,
|
30
|
+
:locals => { :form_fields => form_fields,
|
31
|
+
:edit => false,
|
32
|
+
:extended_item => @user,
|
33
|
+
:item_key => 'user'}) %>
|
34
|
+
<% end -%>
|
35
|
+
|
36
|
+
<% if I18n.available_locales_with_labels.keys.size > 1 %>
|
37
|
+
<div class="form-element">
|
38
|
+
<label><%=t 'account.signup.language' %></label>
|
39
|
+
<%= locale_dropdown(f) -%>
|
40
|
+
<div class="form_example"><%=t 'account.signup.language_example' %></div>
|
41
|
+
</div>
|
42
|
+
<% else %>
|
43
|
+
<%= f.hidden_field :locale, :value => I18n.default_locale %>
|
44
|
+
<% end %>
|
45
|
+
|
46
|
+
<div class="form-element">
|
47
|
+
<label><%=t 'account.signup.preferred_license' %></label>
|
48
|
+
<%= render :partial => 'topics/license_chooser_or_agreement',:locals => {:item => @user} %>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<%= render :partial => "captcha_wrapper", :locals => { :f => f } %>
|
52
|
+
|
53
|
+
<div class="form-element">
|
54
|
+
<%= f.check_box :agree_to_terms, :tabindex => '1' %>
|
55
|
+
<% terms_and_conditions_link = link_to_remote(t('account.signup.terms_and_conditions_link'),
|
56
|
+
{ :url => { :action => 'disclaimer', :id => 4 } },
|
57
|
+
{ :href => url_for({ :action => 'disclaimer', :id => 4 }),
|
58
|
+
:tabindex => '1' }) %>
|
59
|
+
<% privacy_policy_link = link_to_remote(t('account.signup.privacy_policy_link'),
|
60
|
+
{ :url => { :action => 'disclaimer', :id => 5 } },
|
61
|
+
{ :href => url_for({ :action => 'disclaimer', :id => 5 }),
|
62
|
+
:tabindex => '1' }) %>
|
63
|
+
<% house_rules_link = link_to_remote(t('account.signup.house_rules_link'),
|
64
|
+
{ :url => { :action => 'disclaimer', :id => 2 } },
|
65
|
+
{ :href => url_for({ :action => 'disclaimer', :id => 2 }),
|
66
|
+
:tabindex => '1' }) %>
|
67
|
+
<%=t 'account.signup.agree_to',
|
68
|
+
:terms_and_conditions_link => terms_and_conditions_link,
|
69
|
+
:privacy_policy_link => privacy_policy_link,
|
70
|
+
:house_rules_link => house_rules_link -%>
|
71
|
+
</div>
|
72
|
+
<div id="disclaimer"></div>
|
73
|
+
|
74
|
+
</fieldset>
|
75
|
+
|
76
|
+
<div style="margin:0;style:0"><%= submit_tag t('account.signup.button'), {:class => "save-button", :tabindex => '1'} %></div>
|
77
|
+
|
78
|
+
<% end -%>
|
79
|
+
|
80
|
+
<%= render(:partial => "topics/content_wrapper_end" ) %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
account:
|
4
|
+
login_form:
|
5
|
+
or_standard_login: "Or use standard {{t.base.login}} {{t.base.form}}"
|
6
|
+
register_via_browserid: "Are {{t.base.you}} {{t.base.registered}}? {{t.base.you.capitalize}} will need to {{register_link}} first before {{t.base.you}} can {{t.base.login}}."
|
7
|
+
use_browserid: "Use {{t.base.browserid}}"
|
8
|
+
signup_as_browserid:
|
9
|
+
second_step: "Now that you have created your {{t.base.browserid}}, we need to ask you a few more questions before completing your sign up on the site."
|
10
|
+
short_name: "{{t.base.short_name.capitalize}}"
|
11
|
+
short_name_example: "Must be unique and contain no spaces. If {{t.base.your}} {{t.base.name}} is \"John Smith\" then {{t.base.you}} could use \"jsmith\" as {{t.base.your}} {{t.base.short_name}}."
|
12
|
+
title: "The {{t.base.browserid}} part is completed. We have a few questions and then we're done."
|
13
|
+
user_name_example: "This is the {{t.base.name}} others will see on {{t.base.your}} {{t.base.profile}} and when you make {{t.base.contribution.pluralize}} to the {{t.base.site}}. If you do not supply one, {{t.base.your}} {{t.base.short_name}} will be used instead. {{t.base.your.capitalize}} {{t.base.username}} can contain spaces. E.g if {{t.base.your}} {{t.base.short_name}} was \"jsmith\" {{t.base.your}} screen {{t.base.name}} could be \"John Smith\"."
|
14
|
+
base:
|
15
|
+
browserid: BrowserID
|
16
|
+
short_name: short name
|
17
|
+
user_model:
|
18
|
+
must_be_unique: "has already been taken"
|
19
|
+
account_controller:
|
20
|
+
login_via_browserid:
|
21
|
+
logged_in: "{{t.account_controller.login.logged_in}}"
|
22
|
+
no_account_matches: "We don't have an account matching your {{t.base.browserid}} login yet. Please sign up."
|
23
|
+
signup_as_browserid:
|
24
|
+
signed_up_login_with_browserid: "{{t.base.thank_you}}! Now that your signup is complete, you may now {{t.base.login}}."
|
25
|
+
application_helper:
|
26
|
+
link_for_login_with_browserid:
|
27
|
+
login_with_browserid: "{{t.application_helper.link_to_login.login_with_browserid}}"
|
28
|
+
link_for_register_via_browserid:
|
29
|
+
register_via_browserid: "{{t.application_helper.link_to_register.register_via_browserid}}"
|
30
|
+
link_to_login:
|
31
|
+
login_with_browserid: "{{t.base.login.capitalize}} with {{t.base.browserid}}"
|
32
|
+
link_to_register:
|
33
|
+
register_via_browserid: "{{t.base.register.capitalize}} via {{t.base.browserid}}"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{kete_browserid}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Walter McGinnis"]
|
12
|
+
s.date = %q{2012-06-13}
|
13
|
+
s.description = %q{An add-on for Kete (http://kete.net.nz) that replaces normal login with a browserid based login.}
|
14
|
+
s.email = %q{walter@katipo.co.nz}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"app/views/account/_login_form.html.erb",
|
27
|
+
"app/views/account/signup_as_browserid.html.erb",
|
28
|
+
"config/locales/en.yml",
|
29
|
+
"kete_browserid.gemspec",
|
30
|
+
"lib/kete_browserid.rb",
|
31
|
+
"lib/kete_browserid/extensions/controllers/account_controller.rb",
|
32
|
+
"lib/kete_browserid/extensions/controllers/application_controller.rb",
|
33
|
+
"lib/kete_browserid/extensions/helpers/application_helper.rb",
|
34
|
+
"lib/kete_browserid/extensions/models/user.rb",
|
35
|
+
"rails/init.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/kete/kete_browserid}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{An add-on for Kete (http://kete.net.nz) that replaces normal login with a browserid based login.}
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<system_timer>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<faraday>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<system_timer>, [">= 0"])
|
53
|
+
s.add_dependency(%q<faraday>, [">= 0"])
|
54
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<system_timer>, [">= 0"])
|
58
|
+
s.add_dependency(%q<faraday>, [">= 0"])
|
59
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# add browserid_login action
|
4
|
+
AccountController.class_eval do
|
5
|
+
before_filter :set_add_on_scripts_and_links
|
6
|
+
|
7
|
+
skip_before_filter :verify_authenticity_token, :only => :login_via_browserid
|
8
|
+
|
9
|
+
# browserid_login action will:
|
10
|
+
# take assertion that browserid submission provides
|
11
|
+
# check if email exists on our site
|
12
|
+
# if so, authenticate the user as per what would be done with normal account_controller#login action
|
13
|
+
# if not, redirect to browserid specific signup action to register the user
|
14
|
+
def login_via_browserid
|
15
|
+
assertion = params[:assertion]
|
16
|
+
|
17
|
+
browserid_response = Faraday.post 'https://browserid.org/verify', { :assertion => assertion, :audience => Kete.site_url }
|
18
|
+
|
19
|
+
browserid_hash = ::ActiveSupport::JSON.decode(browserid_response.body)
|
20
|
+
|
21
|
+
browserid_email = browserid_hash['email']
|
22
|
+
|
23
|
+
raise "BrowserID failure: #{browserid_hash.inspect}" unless browserid_email
|
24
|
+
|
25
|
+
@user = User.find_by_email(browserid_email)
|
26
|
+
|
27
|
+
if @user
|
28
|
+
self.current_user = @user
|
29
|
+
move_session_searches_to_current_user
|
30
|
+
flash[:notice] = t('account_controller.login_via_browserid.logged_in')
|
31
|
+
redirect_back_or_default({ :locale => current_user.locale,
|
32
|
+
:urlified_name => @site_basket.urlified_name,
|
33
|
+
:controller => 'account',
|
34
|
+
:action => 'index' }, current_user.locale)
|
35
|
+
else
|
36
|
+
flash[:notice] = t('account_controller.login_via_browserid.no_account_matches')
|
37
|
+
redirect_to :action => :signup_as_browserid, :email => browserid_email
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def signup_as_browserid
|
42
|
+
raise ArgumentError, "email expected." if params[:email].blank? && !request.post?
|
43
|
+
|
44
|
+
# this loads @content_type
|
45
|
+
load_content_type
|
46
|
+
|
47
|
+
@user = User.new(:email => params[:email])
|
48
|
+
|
49
|
+
set_captcha_type
|
50
|
+
|
51
|
+
create_brain_buster if @captcha_type == 'question'
|
52
|
+
|
53
|
+
# after this is processing submitted form only
|
54
|
+
return unless request.post?
|
55
|
+
@user = User.new(params[:user].reject { |k, v| k == "captcha_type" })
|
56
|
+
|
57
|
+
@user.creating_with_browserid = true
|
58
|
+
|
59
|
+
case @captcha_type
|
60
|
+
when 'image'
|
61
|
+
if simple_captcha_valid?
|
62
|
+
@user.security_code = params[:user][:security_code]
|
63
|
+
end
|
64
|
+
|
65
|
+
if simple_captcha_confirm_valid?
|
66
|
+
@res = Captcha.find(session[:captcha_id])
|
67
|
+
@user.security_code_confirmation = @res.text
|
68
|
+
else
|
69
|
+
@user.security_code_confirmation = false
|
70
|
+
end
|
71
|
+
when 'question'
|
72
|
+
if validate_brain_buster
|
73
|
+
@user.security_code = true
|
74
|
+
@user.security_code_confirmation = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if agreed_terms?
|
79
|
+
@user.agree_to_terms = params[:user][:agree_to_terms]
|
80
|
+
end
|
81
|
+
|
82
|
+
@user.save!
|
83
|
+
|
84
|
+
@user.add_as_member_to_default_baskets
|
85
|
+
|
86
|
+
flash[:notice] = t('account_controller.signup_as_browserid.signed_up_login_with_browserid')
|
87
|
+
|
88
|
+
redirect_back_or_default({ :locale => params[:user][:locale],
|
89
|
+
:urlified_name => @site_basket.urlified_name,
|
90
|
+
:controller => 'account',
|
91
|
+
:action => 'index' })
|
92
|
+
rescue ActiveRecord::RecordInvalid
|
93
|
+
render :action => 'signup_as_browserid'
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
ApplicationController.class_eval do
|
2
|
+
before_filter :set_add_on_scripts_and_links
|
3
|
+
|
4
|
+
# set up our browserid javascript loading
|
5
|
+
def set_add_on_scripts_and_links
|
6
|
+
browserid_login_url = "/#{@site_basket.urlified_name}/account/login_via_browserid"
|
7
|
+
head_js = " <script src=\"https://browserid.org/include.js\" type=\"text/javascript\"></script>"
|
8
|
+
|
9
|
+
head_js += " <script type=\"text/javascript\">
|
10
|
+
function setUpBrowserIDForm() {
|
11
|
+
var form_html = '<form id=\"browserid_login_form\" action=\"#{browserid_login_url}\" style=\"display: none;\" method=\"post\">';
|
12
|
+
form_html += '<input type=\"hidden\" name=\"assertion\" />';
|
13
|
+
form_html += '<input style=\"display: none\" type=\"submit\" />';
|
14
|
+
form_html += '</form>';
|
15
|
+
|
16
|
+
jQuery('#body-outer-wrapper').append(form_html);
|
17
|
+
}
|
18
|
+
function browserid_login() {
|
19
|
+
navigator.id.get(gotAssertion);
|
20
|
+
}
|
21
|
+
function gotAssertion(assertion) {
|
22
|
+
if (assertion !== null) {
|
23
|
+
setUpBrowserIDForm();
|
24
|
+
|
25
|
+
jQuery('input[name=assertion]').val(assertion);
|
26
|
+
|
27
|
+
jQuery('#browserid_login_form').submit();
|
28
|
+
}
|
29
|
+
}
|
30
|
+
</script>"
|
31
|
+
|
32
|
+
# HACK to get content_for setting in controller
|
33
|
+
# we shouldn't use the internal representation (instance variable) of content_for data
|
34
|
+
# but we are, as we want to set this on every request
|
35
|
+
# WARNING: because of this use of internal data storage hack, this will break with Rails 3x
|
36
|
+
@content_for_add_on_scripts_and_links ||= String.new
|
37
|
+
@content_for_add_on_scripts_and_links += head_js unless @content_for_add_on_scripts_and_links.include?(head_js)
|
38
|
+
end
|
39
|
+
|
40
|
+
private :set_add_on_scripts_and_links
|
41
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
ApplicationHelper.module_eval do
|
2
|
+
def link_for_login_with_browserid
|
3
|
+
link_to(t('application_helper.link_for_login_with_browserid.login_with_browserid'),
|
4
|
+
'javascript:window.browserid_login()',
|
5
|
+
:id => '#browserid',
|
6
|
+
:title => "Sign-in with BrowserID link. ")
|
7
|
+
end
|
8
|
+
|
9
|
+
def link_to_login(phrase, url_for_options, html_options)
|
10
|
+
html = String.new
|
11
|
+
|
12
|
+
# don't make link active for login page
|
13
|
+
browserid_login_html = if params[:controller] == 'account' && params[:action] == 'login'
|
14
|
+
t('application_helper.link_to_login.login_with_browserid')
|
15
|
+
else
|
16
|
+
link_for_login_with_browserid
|
17
|
+
end
|
18
|
+
|
19
|
+
unless ::KeteBrowserid::REPLACE_EXISTING_LOGIN
|
20
|
+
html = link_to_unless_current phrase, url_for_options, html_options
|
21
|
+
html += '</li><li>'
|
22
|
+
end
|
23
|
+
|
24
|
+
html += browserid_login_html
|
25
|
+
html
|
26
|
+
end
|
27
|
+
|
28
|
+
def link_for_register_via_browserid
|
29
|
+
link_to(t('application_helper.link_for_register_via_browserid.register_via_browserid'),
|
30
|
+
'javascript:window.browserid_login()',
|
31
|
+
:id => '#browserid-register',
|
32
|
+
:title => "Signup with BrowserID link. ")
|
33
|
+
end
|
34
|
+
|
35
|
+
def link_to_register(phrase, url_for_options, html_options)
|
36
|
+
html = String.new
|
37
|
+
|
38
|
+
# don't make link active for signup page
|
39
|
+
browserid_register_html = if params[:controller] == 'account' && params[:action] == 'signup'
|
40
|
+
t('application_helper.link_to_register.register_via_browserid')
|
41
|
+
else
|
42
|
+
link_for_register_via_browserid
|
43
|
+
end
|
44
|
+
|
45
|
+
unless ::KeteBrowserid::REPLACE_EXISTING_REGISTER
|
46
|
+
html = link_to_unless_current phrase, url_for_options, html_options
|
47
|
+
html += '</li><li>'
|
48
|
+
end
|
49
|
+
|
50
|
+
html += browserid_register_html
|
51
|
+
html
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# if we are use browserid, email must be unique to the system
|
2
|
+
User.class_eval do
|
3
|
+
validates_uniqueness_of :email, :case_sensitive => false, :message => lambda { I18n.t('user_model.must_be_unique') }
|
4
|
+
|
5
|
+
# a way to check if emails are unique on this system
|
6
|
+
def self.has_non_unique_emails?
|
7
|
+
count(:select => 'distinct(email)') != count
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :creating_with_browserid
|
11
|
+
alias :creating_with_browserid? :creating_with_browserid
|
12
|
+
|
13
|
+
def password_required?
|
14
|
+
!creating_with_browserid? && (crypted_password.blank? || !password.blank?)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/rails/init.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
config.to_prepare do
|
2
|
+
# load our locales
|
3
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), '../config/locales/*.{rb,yml}')]
|
4
|
+
|
5
|
+
# precedence over a plugin or gem's (i.e. an engine's) app/views
|
6
|
+
# this is the way to go in most cases,
|
7
|
+
# but in our case we want to override the app's view.
|
8
|
+
# so we pop off our gem's app/views directory and put it at the front
|
9
|
+
engine_views_dir = File.join(directory, 'app/views')
|
10
|
+
# drop it from it's existing location if it exists
|
11
|
+
ActionController::Base.view_paths.delete engine_views_dir
|
12
|
+
# add it to the front of array
|
13
|
+
ActionController::Base.view_paths.unshift engine_views_dir
|
14
|
+
|
15
|
+
# override some controllers and helpers we need to alter for browserid support
|
16
|
+
exts = File.join(File.dirname(__FILE__), '../lib/kete_browserid/extensions/{controllers,helpers}/*')
|
17
|
+
# use Kernel.load here so that changes to the extensions are reloaded on each request in development
|
18
|
+
Dir[exts].each { |ext_path| Kernel.load(ext_path) }
|
19
|
+
|
20
|
+
# models we extend
|
21
|
+
Dir[File.join(File.dirname(__FILE__), '../lib/kete_browserid/extensions/models/*')].each do |ext_path|
|
22
|
+
key = File.basename(ext_path, '.rb').to_sym
|
23
|
+
Kete.add_code_to_extensions_for(key, Proc.new { Kernel.load(ext_path) })
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kete_browserid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Walter McGinnis
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-06-13 00:00:00 +12:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: system_timer
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: faraday
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: thoughtbot-shoulda
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
description: An add-on for Kete (http://kete.net.nz) that replaces normal login with a browserid based login.
|
64
|
+
email: walter@katipo.co.nz
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files:
|
70
|
+
- LICENSE
|
71
|
+
- README.rdoc
|
72
|
+
files:
|
73
|
+
- .document
|
74
|
+
- .gitignore
|
75
|
+
- LICENSE
|
76
|
+
- README.rdoc
|
77
|
+
- Rakefile
|
78
|
+
- VERSION
|
79
|
+
- app/views/account/_login_form.html.erb
|
80
|
+
- app/views/account/signup_as_browserid.html.erb
|
81
|
+
- config/locales/en.yml
|
82
|
+
- kete_browserid.gemspec
|
83
|
+
- lib/kete_browserid.rb
|
84
|
+
- lib/kete_browserid/extensions/controllers/account_controller.rb
|
85
|
+
- lib/kete_browserid/extensions/controllers/application_controller.rb
|
86
|
+
- lib/kete_browserid/extensions/helpers/application_helper.rb
|
87
|
+
- lib/kete_browserid/extensions/models/user.rb
|
88
|
+
- rails/init.rb
|
89
|
+
has_rdoc: true
|
90
|
+
homepage: http://github.com/kete/kete_browserid
|
91
|
+
licenses: []
|
92
|
+
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options:
|
95
|
+
- --charset=UTF-8
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.3.7
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: An add-on for Kete (http://kete.net.nz) that replaces normal login with a browserid based login.
|
123
|
+
test_files: []
|
124
|
+
|