janus 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +3 -0
- data/.gitignore +4 -0
- data/.travis.yml +18 -0
- data/LICENSE +20 -0
- data/README.rdoc +4 -5
- data/Rakefile +22 -0
- data/VERSION +1 -0
- data/certs/ysbaddaden.pem +21 -0
- data/janus.gemspec +28 -0
- data/lib/generators/janus/resource_generator.rb +17 -1
- data/lib/generators/templates/janus.rb +9 -5
- data/lib/generators/templates/mailer.rb +3 -0
- data/lib/generators/templates/mailer/confirmation_instructions.html.erb +7 -0
- data/lib/generators/templates/mailer/confirmation_instructions.text.erb +7 -0
- data/lib/generators/templates/mailer/reset_password_instructions.html.erb +9 -0
- data/lib/generators/templates/mailer/reset_password_instructions.text.erb +7 -0
- data/lib/janus.rb +3 -0
- data/lib/janus/config.rb +9 -3
- data/lib/janus/controllers/confirmations_controller.rb +1 -1
- data/lib/janus/controllers/internal_helpers.rb +8 -1
- data/lib/janus/controllers/passwords_controller.rb +1 -1
- data/lib/janus/controllers/registrations_controller.rb +1 -1
- data/lib/janus/controllers/sessions_controller.rb +6 -5
- data/lib/janus/models/confirmable.rb +2 -0
- data/lib/janus/models/database_authenticatable.rb +4 -2
- data/lib/janus/models/rememberable.rb +2 -0
- data/lib/janus/models/remote_authenticatable.rb +2 -0
- data/lib/janus/models/remote_token.rb +6 -5
- data/lib/janus/models/token_authenticatable.rb +79 -0
- data/lib/janus/models/trackable.rb +2 -0
- data/lib/janus/strategies.rb +1 -1
- data/lib/janus/strategies/token_authenticatable.rb +22 -0
- data/lib/janus/version.rb +10 -0
- data/test/fixtures/admins.yml +5 -0
- data/test/fixtures/users.yml +10 -0
- data/test/functional/admins/sessions_controller_test.rb +13 -0
- data/test/functional/home_controller_test.rb +8 -0
- data/test/functional/janus/mailer_test.rb +14 -0
- data/test/functional/janus/manager_test.rb +94 -0
- data/test/functional/users/confirmations_controller_test.rb +68 -0
- data/test/functional/users/passwords_controller_test.rb +131 -0
- data/test/functional/users/registrations_controller_test.rb +112 -0
- data/test/functional/users/sessions_controller_test.rb +100 -0
- data/test/functional/users_controller_test.rb +29 -0
- data/test/generators/install_generator_test.rb +16 -0
- data/test/generators/resource_generator_test.rb +80 -0
- data/test/integration/users/rememberable_test.rb +32 -0
- data/test/integration/users/remote_test.rb +72 -0
- data/test/integration/users/sessions_test.rb +18 -0
- data/test/integration/users/token_authenticatable_test.rb +42 -0
- data/test/integration/users/trackable_test.rb +22 -0
- data/test/rails_app/.gitignore +4 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +11 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/blogs_controller.rb +6 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users/confirmations_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/passwords_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/registrations_controller.rb +17 -0
- data/test/rails_app/app/controllers/users/sessions_controller.rb +11 -0
- data/test/rails_app/app/controllers/users_controller.rb +9 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/mailers/user_mailer.rb +3 -0
- data/test/rails_app/app/models/admin.rb +3 -0
- data/test/rails_app/app/models/remote_token.rb +6 -0
- data/test/rails_app/app/models/user.rb +8 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +30 -0
- data/test/rails_app/app/views/blogs/show.html.erb +2 -0
- data/test/rails_app/app/views/home/index.html.erb +2 -0
- data/test/rails_app/app/views/layouts/application.html.erb +28 -0
- data/test/rails_app/app/views/user_mailer/confirmation_instructions.html.erb +7 -0
- data/test/rails_app/app/views/user_mailer/confirmation_instructions.text.erb +7 -0
- data/test/rails_app/app/views/user_mailer/reset_password_instructions.html.erb +9 -0
- data/test/rails_app/app/views/user_mailer/reset_password_instructions.text.erb +7 -0
- data/test/rails_app/app/views/users/confirmations/new.html.erb +16 -0
- data/test/rails_app/app/views/users/passwords/edit.html.erb +21 -0
- data/test/rails_app/app/views/users/passwords/new.html.erb +16 -0
- data/test/rails_app/app/views/users/registrations/edit.html.erb +31 -0
- data/test/rails_app/app/views/users/registrations/new.html.erb +26 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +30 -0
- data/test/rails_app/app/views/users/show.html.erb +2 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +43 -0
- data/test/rails_app/config/boot.rb +6 -0
- data/test/rails_app/config/database.yml +22 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +23 -0
- data/test/rails_app/config/environments/production.rb +50 -0
- data/test/rails_app/config/environments/test.rb +34 -0
- data/test/rails_app/config/initializers/janus.rb +25 -0
- data/test/rails_app/config/initializers/secret_token.rb +8 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/locales/janus.en.yml +65 -0
- data/test/rails_app/config/routes.rb +13 -0
- data/test/rails_app/db/migrate/20110323153820_create_users.rb +40 -0
- data/test/rails_app/db/migrate/20110331153546_create_remote_tokens.rb +15 -0
- data/test/rails_app/db/migrate/20130412104138_create_admins.rb +10 -0
- data/test/rails_app/db/schema.rb +58 -0
- data/test/rails_app/db/seeds.rb +7 -0
- data/test/rails_app/lib/tasks/.gitkeep +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/script/rails +6 -0
- data/test/test_helper.rb +121 -0
- data/test/unit/confirmable_test.rb +36 -0
- data/test/unit/janus_test.rb +27 -0
- data/test/unit/rememberable_test.rb +47 -0
- data/test/unit/remote_authenticatable_test.rb +37 -0
- data/test/unit/remote_token_test.rb +9 -0
- data/test/unit/reset_password_test.rb +45 -0
- data/test/unit/token_authenticatable_test.rb +41 -0
- data/test/unit/trackable_test.rb +21 -0
- data/test/unit/user_test.rb +68 -0
- metadata +303 -21
- 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,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,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,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,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,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,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 %>
|