janus 0.7.0 → 0.8.0

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.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +3 -0
  4. data/.gitignore +4 -0
  5. data/.travis.yml +18 -0
  6. data/LICENSE +20 -0
  7. data/README.rdoc +4 -5
  8. data/Rakefile +22 -0
  9. data/VERSION +1 -0
  10. data/certs/ysbaddaden.pem +21 -0
  11. data/janus.gemspec +28 -0
  12. data/lib/generators/janus/resource_generator.rb +17 -1
  13. data/lib/generators/templates/janus.rb +9 -5
  14. data/lib/generators/templates/mailer.rb +3 -0
  15. data/lib/generators/templates/mailer/confirmation_instructions.html.erb +7 -0
  16. data/lib/generators/templates/mailer/confirmation_instructions.text.erb +7 -0
  17. data/lib/generators/templates/mailer/reset_password_instructions.html.erb +9 -0
  18. data/lib/generators/templates/mailer/reset_password_instructions.text.erb +7 -0
  19. data/lib/janus.rb +3 -0
  20. data/lib/janus/config.rb +9 -3
  21. data/lib/janus/controllers/confirmations_controller.rb +1 -1
  22. data/lib/janus/controllers/internal_helpers.rb +8 -1
  23. data/lib/janus/controllers/passwords_controller.rb +1 -1
  24. data/lib/janus/controllers/registrations_controller.rb +1 -1
  25. data/lib/janus/controllers/sessions_controller.rb +6 -5
  26. data/lib/janus/models/confirmable.rb +2 -0
  27. data/lib/janus/models/database_authenticatable.rb +4 -2
  28. data/lib/janus/models/rememberable.rb +2 -0
  29. data/lib/janus/models/remote_authenticatable.rb +2 -0
  30. data/lib/janus/models/remote_token.rb +6 -5
  31. data/lib/janus/models/token_authenticatable.rb +79 -0
  32. data/lib/janus/models/trackable.rb +2 -0
  33. data/lib/janus/strategies.rb +1 -1
  34. data/lib/janus/strategies/token_authenticatable.rb +22 -0
  35. data/lib/janus/version.rb +10 -0
  36. data/test/fixtures/admins.yml +5 -0
  37. data/test/fixtures/users.yml +10 -0
  38. data/test/functional/admins/sessions_controller_test.rb +13 -0
  39. data/test/functional/home_controller_test.rb +8 -0
  40. data/test/functional/janus/mailer_test.rb +14 -0
  41. data/test/functional/janus/manager_test.rb +94 -0
  42. data/test/functional/users/confirmations_controller_test.rb +68 -0
  43. data/test/functional/users/passwords_controller_test.rb +131 -0
  44. data/test/functional/users/registrations_controller_test.rb +112 -0
  45. data/test/functional/users/sessions_controller_test.rb +100 -0
  46. data/test/functional/users_controller_test.rb +29 -0
  47. data/test/generators/install_generator_test.rb +16 -0
  48. data/test/generators/resource_generator_test.rb +80 -0
  49. data/test/integration/users/rememberable_test.rb +32 -0
  50. data/test/integration/users/remote_test.rb +72 -0
  51. data/test/integration/users/sessions_test.rb +18 -0
  52. data/test/integration/users/token_authenticatable_test.rb +42 -0
  53. data/test/integration/users/trackable_test.rb +22 -0
  54. data/test/rails_app/.gitignore +4 -0
  55. data/test/rails_app/Rakefile +7 -0
  56. data/test/rails_app/app/controllers/admins/sessions_controller.rb +11 -0
  57. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  58. data/test/rails_app/app/controllers/blogs_controller.rb +6 -0
  59. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  60. data/test/rails_app/app/controllers/users/confirmations_controller.rb +3 -0
  61. data/test/rails_app/app/controllers/users/passwords_controller.rb +3 -0
  62. data/test/rails_app/app/controllers/users/registrations_controller.rb +17 -0
  63. data/test/rails_app/app/controllers/users/sessions_controller.rb +11 -0
  64. data/test/rails_app/app/controllers/users_controller.rb +9 -0
  65. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  66. data/test/rails_app/app/mailers/user_mailer.rb +3 -0
  67. data/test/rails_app/app/models/admin.rb +3 -0
  68. data/test/rails_app/app/models/remote_token.rb +6 -0
  69. data/test/rails_app/app/models/user.rb +8 -0
  70. data/test/rails_app/app/views/admins/sessions/new.html.erb +30 -0
  71. data/test/rails_app/app/views/blogs/show.html.erb +2 -0
  72. data/test/rails_app/app/views/home/index.html.erb +2 -0
  73. data/test/rails_app/app/views/layouts/application.html.erb +28 -0
  74. data/test/rails_app/app/views/user_mailer/confirmation_instructions.html.erb +7 -0
  75. data/test/rails_app/app/views/user_mailer/confirmation_instructions.text.erb +7 -0
  76. data/test/rails_app/app/views/user_mailer/reset_password_instructions.html.erb +9 -0
  77. data/test/rails_app/app/views/user_mailer/reset_password_instructions.text.erb +7 -0
  78. data/test/rails_app/app/views/users/confirmations/new.html.erb +16 -0
  79. data/test/rails_app/app/views/users/passwords/edit.html.erb +21 -0
  80. data/test/rails_app/app/views/users/passwords/new.html.erb +16 -0
  81. data/test/rails_app/app/views/users/registrations/edit.html.erb +31 -0
  82. data/test/rails_app/app/views/users/registrations/new.html.erb +26 -0
  83. data/test/rails_app/app/views/users/sessions/new.html.erb +30 -0
  84. data/test/rails_app/app/views/users/show.html.erb +2 -0
  85. data/test/rails_app/config.ru +4 -0
  86. data/test/rails_app/config/application.rb +43 -0
  87. data/test/rails_app/config/boot.rb +6 -0
  88. data/test/rails_app/config/database.yml +22 -0
  89. data/test/rails_app/config/environment.rb +5 -0
  90. data/test/rails_app/config/environments/development.rb +23 -0
  91. data/test/rails_app/config/environments/production.rb +50 -0
  92. data/test/rails_app/config/environments/test.rb +34 -0
  93. data/test/rails_app/config/initializers/janus.rb +25 -0
  94. data/test/rails_app/config/initializers/secret_token.rb +8 -0
  95. data/test/rails_app/config/initializers/session_store.rb +8 -0
  96. data/test/rails_app/config/locales/janus.en.yml +65 -0
  97. data/test/rails_app/config/routes.rb +13 -0
  98. data/test/rails_app/db/migrate/20110323153820_create_users.rb +40 -0
  99. data/test/rails_app/db/migrate/20110331153546_create_remote_tokens.rb +15 -0
  100. data/test/rails_app/db/migrate/20130412104138_create_admins.rb +10 -0
  101. data/test/rails_app/db/schema.rb +58 -0
  102. data/test/rails_app/db/seeds.rb +7 -0
  103. data/test/rails_app/lib/tasks/.gitkeep +0 -0
  104. data/test/rails_app/public/404.html +26 -0
  105. data/test/rails_app/public/422.html +26 -0
  106. data/test/rails_app/public/500.html +26 -0
  107. data/test/rails_app/script/rails +6 -0
  108. data/test/test_helper.rb +121 -0
  109. data/test/unit/confirmable_test.rb +36 -0
  110. data/test/unit/janus_test.rb +27 -0
  111. data/test/unit/rememberable_test.rb +47 -0
  112. data/test/unit/remote_authenticatable_test.rb +37 -0
  113. data/test/unit/remote_token_test.rb +9 -0
  114. data/test/unit/reset_password_test.rb +45 -0
  115. data/test/unit/token_authenticatable_test.rb +41 -0
  116. data/test/unit/trackable_test.rb +21 -0
  117. data/test/unit/user_test.rb +68 -0
  118. metadata +303 -21
  119. metadata.gz.sig +0 -0
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class Users::SessionsTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ test "sign in and out" do
7
+ visit new_user_session_path
8
+ fill_in 'user_email', :with => users(:julien).email
9
+ fill_in 'user_password', :with => 'secret'
10
+ find('input[name=commit]').click
11
+
12
+ assert_equal user_path, page.current_path
13
+ find('h1').has_content?('Welcome ' + users(:julien).email)
14
+
15
+ page.driver.submit :delete, destroy_user_session_path, {}
16
+ assert_equal root_path, page.current_path
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class Users::TokenAuthenticatableTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ setup do
7
+ @user = users(:julien)
8
+ @user.reset_authentication_token!
9
+ end
10
+
11
+ test "should sign user in from token" do
12
+ visit root_url(:auth_token => @user.authentication_token)
13
+ assert_authenticated
14
+ end
15
+
16
+ test "should not sign user with invalid token" do
17
+ visit root_url(:auth_token => 'unknown token')
18
+ assert_not_authenticated
19
+ end
20
+
21
+ test "should reuse token" do
22
+ Janus::Config.stub(:reusable_authentication_token, true) do
23
+ token = @user.authentication_token
24
+ visit root_url(:auth_token => token)
25
+ sign_out :user
26
+
27
+ visit root_url(:auth_token => token)
28
+ assert_authenticated
29
+ end
30
+ end
31
+
32
+ test "shouldn't reuse token" do
33
+ Janus::Config.stub(:reusable_authentication_token, false) do
34
+ token = @user.authentication_token
35
+ visit root_url(:auth_token => token)
36
+ sign_out :user
37
+
38
+ visit root_url(:auth_token => token)
39
+ assert_not_authenticated
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class Users::TrackableTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ test "should track user" do
7
+ current_sign_in_at = users(:julien).reload.current_sign_in_at
8
+ sign_in users(:julien)
9
+ assert_not_equal current_sign_in_at, users(:julien).reload.current_sign_in_at
10
+ end
11
+
12
+ test "remote authentication should not track user" do
13
+ sign_in users(:julien)
14
+
15
+ current_sign_in_at = users(:julien).reload.current_sign_in_at
16
+
17
+ visit root_url(:host => 'test.host')
18
+ click_link 'sign_in'
19
+
20
+ assert_equal current_sign_in_at, users(:julien).reload.current_sign_in_at
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ RailsApp::Application.load_tasks
@@ -0,0 +1,11 @@
1
+ class Admins::SessionsController < Janus::SessionsController
2
+ respond_to :html
3
+
4
+ def after_sign_in_url(admin)
5
+ root_url
6
+ end
7
+
8
+ # def valid_remote_host?(host)
9
+ # ['www.example.com', 'test.host'].include?(host)
10
+ # end
11
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ helper_method :main_site_host
5
+
6
+ def main_site_host
7
+ 'www.example.com'
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class BlogsController < ApplicationController
2
+ respond_to :html
3
+
4
+ def show
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class Users::ConfirmationsController < Janus::ConfirmationsController
2
+ respond_to :html
3
+ end
@@ -0,0 +1,3 @@
1
+ class Users::PasswordsController < Janus::PasswordsController
2
+ respond_to :html
3
+ end
@@ -0,0 +1,17 @@
1
+ class Users::RegistrationsController < Janus::RegistrationsController
2
+ respond_to :html
3
+
4
+ def after_sign_up_url(user)
5
+ user_url
6
+ end
7
+
8
+ def user_params
9
+ if params.respond_to?(:permit)
10
+ # Rails 4 (or Rails 3 + strong_parameters)
11
+ params.require(:user).permit(:email, :current_password, :password, :password_confirmation)
12
+ else
13
+ # Rails 3
14
+ params[:user].slice(:email, :current_password, :password, :password_confirmation)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class Users::SessionsController < Janus::SessionsController
2
+ respond_to :html
3
+
4
+ def after_sign_in_url(user)
5
+ user_url
6
+ end
7
+
8
+ def valid_remote_host?(host)
9
+ ['www.example.com', 'test.host'].include?(host)
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :authenticate_user!
3
+
4
+ respond_to :html, :xml
5
+
6
+ def show
7
+ respond_with(current_user)
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class UserMailer < Janus::Mailer
2
+ default from: 'me@example.com'
3
+ end
@@ -0,0 +1,3 @@
1
+ class Admin < ActiveRecord::Base
2
+ include Janus::Models::DatabaseAuthenticatable
3
+ end
@@ -0,0 +1,6 @@
1
+ class RemoteToken < ActiveRecord::Base
2
+ include Janus::Models::RemoteToken
3
+
4
+ belongs_to :user
5
+ validates_presence_of :user
6
+ end
@@ -0,0 +1,8 @@
1
+ class User < ActiveRecord::Base
2
+ include Janus::Models::DatabaseAuthenticatable
3
+ include Janus::Models::Confirmable
4
+ include Janus::Models::Rememberable
5
+ include Janus::Models::RemoteAuthenticatable
6
+ include Janus::Models::TokenAuthenticatable
7
+ include Janus::Models::Trackable
8
+ end
@@ -0,0 +1,30 @@
1
+ <h1><%= t 'janus.sessions.new.sign_in' %></h1>
2
+
3
+ <%= form_for @admin, :url => admin_session_path, :method => :post do |f| %>
4
+ <%= hidden_field_tag :return_to, params[:return_to] if params[:return_to] %>
5
+
6
+ <%= janus_error_messages %>
7
+
8
+ <% Admin.authentication_keys.each do |key| %>
9
+ <div class="field">
10
+ <%= f.label key %>
11
+ <%= f.text_field key %>
12
+ </div>
13
+ <% end %>
14
+
15
+ <div class="field">
16
+ <%= f.label :password %>
17
+ <%= f.password_field :password %>
18
+ </div>
19
+
20
+ <% if @admin.respond_to?(:remember_me!) %>
21
+ <div class="field">
22
+ <%= check_box_tag :remember_me, '1' %>
23
+ <%= label_tag :remember_me, Admin.human_attribute_name(:remember_me) %>
24
+ </div>
25
+ <% end %>
26
+
27
+ <div class="actions">
28
+ <%= f.submit t('janus.sessions.new.sign_in_btn') %>
29
+ </div>
30
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <h1>Blog</h1>
2
+
@@ -0,0 +1,2 @@
1
+ <h1>Home</h1>
2
+
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Janus</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <header>
12
+ <p>Janus</p>
13
+
14
+ <p class="user">
15
+ <% if user_signed_in? %>
16
+ <%= link_to current_user.email, user_url(:host => main_site_host), :id => 'my_page' %>
17
+ <% else %>
18
+ <%= link_to 'Sign in',
19
+ new_user_session_url(:host => main_site_host, :return_to => request.url),
20
+ :id => 'sign_in' %>
21
+ <% end %>
22
+ </p>
23
+ </header>
24
+
25
+ <%= yield %>
26
+
27
+ </body>
28
+ </html>
@@ -0,0 +1,7 @@
1
+ <p><%= t('janus.mailer.hello') %><p>
2
+
3
+ <p><%= t('janus.mailer.confirmation_instructions.confirm') %></p>
4
+
5
+ <p><%= link_to t('janus.mailer.confirmation_instructions.confirm_my_account'),
6
+ user_confirmation_url(@user.class.confirmation_key => @user.confirmation_token) %></p>
7
+
@@ -0,0 +1,7 @@
1
+ <%= t('janus.mailer.hello') %>
2
+
3
+ <%= t('janus.mailer.confirmation_instructions.confirm') %>
4
+
5
+ <%= link_to t('janus.mailer.confirmation_instructions.confirm_my_account'),
6
+ user_confirmation_url(@user.class.confirmation_key => @user.confirmation_token) %>
7
+
@@ -0,0 +1,9 @@
1
+ <p><%= t('janus.mailer.hello') %><p>
2
+
3
+ <p><%= t('janus.mailer.reset_password_instructions.infos') %></p>
4
+
5
+ <p><%= link_to t('janus.mailer.reset_password_instructions.change_password_link'),
6
+ edit_user_password_url(:token => @user.reset_password_token) %></p>
7
+
8
+ <p><%= t('janus.mailer.reset_password_instructions.please_ignore_your_password_wont_change') %></p>
9
+
@@ -0,0 +1,7 @@
1
+ <%= t('janus.mailer.hello') %>
2
+
3
+ <%= t('janus.mailer.reset_password_instructions.infos') %>
4
+ <%= edit_user_password_url(:token => @user.reset_password_token) %>
5
+
6
+ <%= t('janus.mailer.reset_password_instructions.please_ignore_your_password_wont_change') %>
7
+
@@ -0,0 +1,16 @@
1
+ <h1><%= t 'janus.confirmations.new.resend_confirmation_instructions' %></h1>
2
+
3
+ <%= form_for resource, :url => confirmation_path(janus_scope), :method => :post do |f| %>
4
+ <%= janus_error_messages %>
5
+
6
+ <% resource.class.authentication_keys.each do |key| %>
7
+ <div class="field">
8
+ <%= f.label key %>
9
+ <%= f.text_field key %>
10
+ </div>
11
+ <% end %>
12
+
13
+ <div class="actions">
14
+ <%= f.submit t('janus.confirmations.new.send_instructions_btn') %>
15
+ </div>
16
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <h1><%= t 'janus.passwords.edit.change_password' %></h1>
2
+
3
+ <%= form_for resource, :url => password_path(janus_scope), :method => :put do |f| %>
4
+ <%= janus_error_messages %>
5
+
6
+ <%= f.hidden_field :reset_password_token %>
7
+
8
+ <div class="field">
9
+ <%= f.label :password %>
10
+ <%= f.password_field :password %>
11
+ </div>
12
+
13
+ <div class="field">
14
+ <%= f.label :password_confirmation %>
15
+ <%= f.password_field :password_confirmation %>
16
+ </div>
17
+
18
+ <div class="actions">
19
+ <%= f.submit t('janus.passwords.edit.change_password_btn') %>
20
+ </div>
21
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <h1><%= t 'janus.passwords.new.forgot_password' %></h1>
2
+
3
+ <%= form_for resource, :url => password_path(janus_scope), :method => :post do |f| %>
4
+ <%= janus_error_messages %>
5
+
6
+ <% resource_class.authentication_keys.each do |key| %>
7
+ <div class="field">
8
+ <%= f.label key %>
9
+ <%= f.text_field key %>
10
+ </div>
11
+ <% end %>
12
+
13
+ <div class="actions">
14
+ <%= f.submit t('janus.passwords.new.send_instructions_btn') %>
15
+ </div>
16
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <h1><%= t 'janus.registrations.edit.my_account' %></h1>
2
+
3
+ <%= form_for resource, :url => registration_path(janus_scope), :method => :put do |f| %>
4
+ <%= janus_error_messages %>
5
+
6
+ <% resource_class.authentication_keys.each do |key| %>
7
+ <div class="field">
8
+ <%= f.label key %>
9
+ <%= f.text_field key %>
10
+ </div>
11
+ <% end %>
12
+
13
+ <div class="field">
14
+ <%= f.label :current_password %>
15
+ <%= f.password_field :current_password %>
16
+ </div>
17
+
18
+ <div class="field">
19
+ <%= f.label :password %>
20
+ <%= f.password_field :password %>
21
+ </div>
22
+
23
+ <div class="field">
24
+ <%= f.label :password_confirmation %>
25
+ <%= f.password_field :password_confirmation %>
26
+ </div>
27
+
28
+ <div class="actions">
29
+ <%= f.submit t('janus.registrations.edit.save_changes_btn') %>
30
+ </div>
31
+ <% end %>
@@ -0,0 +1,26 @@
1
+ <h1><%= t 'janus.registrations.new.sign_up' %></h1>
2
+
3
+ <%= form_for resource, :url => registration_path(janus_scope) do |f| %>
4
+ <%= janus_error_messages %>
5
+
6
+ <% resource_class.authentication_keys.each do |key| %>
7
+ <div class="field">
8
+ <%= f.label key %>
9
+ <%= f.text_field key %>
10
+ </div>
11
+ <% end %>
12
+
13
+ <div class="field">
14
+ <%= f.label :password %>
15
+ <%= f.password_field :password %>
16
+ </div>
17
+
18
+ <div class="field">
19
+ <%= f.label :password_confirmation %>
20
+ <%= f.password_field :password_confirmation %>
21
+ </div>
22
+
23
+ <div class="actions">
24
+ <%= f.submit t('janus.registrations.new.sign_up_btn') %>
25
+ </div>
26
+ <% end %>