quo_vadis 1.0.0 → 1.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/Gemfile.lock +1 -1
- data/README.md +5 -1
- data/app/controllers/controller_mixin.rb +5 -2
- data/app/controllers/quo_vadis/sessions_controller.rb +13 -6
- data/config/initializers/quo_vadis.rb +13 -5
- data/lib/quo_vadis/version.rb +1 -1
- data/lib/quo_vadis.rb +15 -6
- data/quo_vadis.gemspec +2 -2
- data/test/dummy/app/views/layouts/sessions.html.erb +3 -0
- data/test/integration/config_test.rb +6 -0
- data/test/integration/locale_test.rb +78 -0
- data/test/test_helper.rb +6 -5
- metadata +11 -7
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -33,6 +33,8 @@ What it doesn't and won't do:
|
|
33
33
|
|
34
34
|
## Quick Start
|
35
35
|
|
36
|
+
If this takes you more than 5 minutes, you can have your money back ;)
|
37
|
+
|
36
38
|
Install and run the generator: add `gem 'quo_vadis'` to your Gemfile and run `rails generate quo_vadis:install`.
|
37
39
|
|
38
40
|
Edit and run the generated migration to add authentication columns: `rake db:migrate`. Note the migration (currently) assumes you already have a `User` model.
|
@@ -47,7 +49,7 @@ Note Quo Vadis validates the presence of the password, but it's up to you to add
|
|
47
49
|
|
48
50
|
Use `:authenticate` in a `before_filter` to protect your controllers' actions. For example:
|
49
51
|
|
50
|
-
class
|
52
|
+
class ArticlesController < ActionController::Base
|
51
53
|
before_filter :authenticate, :except => [:index, :show]
|
52
54
|
end
|
53
55
|
|
@@ -56,6 +58,8 @@ Write the sign-in view. Your sign-in form must:
|
|
56
58
|
* be in `app/views/sessions/new.html.:format`
|
57
59
|
* post the parameters `:username` and `:password` to `sign_in_url`
|
58
60
|
|
61
|
+
You have to write the view yourself because you'd inevitably want to change whatever markup I generated for you.
|
62
|
+
|
59
63
|
In your layout, use `current_user` to retrieve the signed-in user, and `sign_in_path` and `sign_out_path` as appropriate.
|
60
64
|
|
61
65
|
|
@@ -14,7 +14,10 @@ module ControllerMixin
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def authenticate
|
17
|
-
|
18
|
-
|
17
|
+
unless current_user
|
18
|
+
session[:quo_vadis_original_url] = request.fullpath
|
19
|
+
flash[:notice] = t('quo_vadis.flash.before_sign_in') unless t('quo_vadis.flash.before_sign_in').blank?
|
20
|
+
redirect_to sign_in_url
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class QuoVadis::SessionsController < ApplicationController
|
2
|
+
layout :quo_vadis_layout
|
2
3
|
|
3
4
|
# sign in
|
4
5
|
def new
|
@@ -9,20 +10,22 @@ class QuoVadis::SessionsController < ApplicationController
|
|
9
10
|
def create
|
10
11
|
if user = User.authenticate(params[:username], params[:password])
|
11
12
|
self.current_user = user
|
12
|
-
QuoVadis.signed_in_hook user,
|
13
|
-
|
13
|
+
QuoVadis.signed_in_hook user, self
|
14
|
+
flash[:notice] = t('quo_vadis.flash.after_sign_in') unless t('quo_vadis.flash.after_sign_in').blank?
|
15
|
+
redirect_to QuoVadis.signed_in_url(user, original_url)
|
14
16
|
else
|
15
|
-
QuoVadis.failed_sign_in_hook
|
16
|
-
flash.now[:alert] = t('quo_vadis.flash.failed_sign_in')
|
17
|
+
QuoVadis.failed_sign_in_hook self
|
18
|
+
flash.now[:alert] = t('quo_vadis.flash.failed_sign_in') unless t('quo_vadis.flash.failed_sign_in').blank?
|
17
19
|
render 'sessions/new'
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
# sign out
|
22
24
|
def destroy
|
23
|
-
QuoVadis.signed_out_hook current_user,
|
25
|
+
QuoVadis.signed_out_hook current_user, self
|
24
26
|
self.current_user = nil
|
25
|
-
|
27
|
+
flash[:notice] = t('quo_vadis.flash.sign_out') unless t('quo_vadis.flash.sign_out').blank?
|
28
|
+
redirect_to QuoVadis.signed_out_url
|
26
29
|
end
|
27
30
|
|
28
31
|
private
|
@@ -33,4 +36,8 @@ class QuoVadis::SessionsController < ApplicationController
|
|
33
36
|
url
|
34
37
|
end
|
35
38
|
|
39
|
+
def quo_vadis_layout
|
40
|
+
QuoVadis.layout
|
41
|
+
end
|
42
|
+
|
36
43
|
end
|
@@ -28,23 +28,31 @@ QuoVadis.configure do |config|
|
|
28
28
|
|
29
29
|
# Code to run when the user has signed in. E.g.:
|
30
30
|
#
|
31
|
-
# config.signed_in_hook = Proc.new do |user,
|
31
|
+
# config.signed_in_hook = Proc.new do |user, controller|
|
32
32
|
# user.increment! :sign_in_count # assuming this attribute exists
|
33
33
|
# end
|
34
34
|
config.signed_in_hook = nil
|
35
35
|
|
36
36
|
# Code to run when someone has tried but failed to sign in. E.g.:
|
37
37
|
#
|
38
|
-
# config.failed_sign_in_hook = Proc.new do |
|
39
|
-
# logger.info "Failed sign in from #{request.remote_ip}"
|
38
|
+
# config.failed_sign_in_hook = Proc.new do |controller|
|
39
|
+
# logger.info "Failed sign in from #{controller.request.remote_ip}"
|
40
40
|
# end
|
41
41
|
config.failed_sign_in_hook = nil
|
42
42
|
|
43
43
|
# Code to run just before the user has signed out. E.g.:
|
44
44
|
#
|
45
|
-
# config.signed_out_hook = Proc.new do |user,
|
46
|
-
# session.reset
|
45
|
+
# config.signed_out_hook = Proc.new do |user, controller|
|
46
|
+
# controller.session.reset
|
47
47
|
# end
|
48
48
|
config.signed_out_hook = nil
|
49
49
|
|
50
|
+
|
51
|
+
#
|
52
|
+
# Miscellaneous
|
53
|
+
#
|
54
|
+
|
55
|
+
# Layout for the sign-in view. Pass a string or a symbol.
|
56
|
+
config.layout = 'application'
|
57
|
+
|
50
58
|
end
|
data/lib/quo_vadis/version.rb
CHANGED
data/lib/quo_vadis.rb
CHANGED
@@ -36,27 +36,36 @@ module QuoVadis
|
|
36
36
|
mattr_accessor :signed_in_hook
|
37
37
|
@@signed_in_hook = nil
|
38
38
|
|
39
|
-
def self.signed_in_hook(user,
|
40
|
-
@@signed_in_hook.call(user,
|
39
|
+
def self.signed_in_hook(user, controller)
|
40
|
+
@@signed_in_hook.call(user, controller) if @@signed_in_hook
|
41
41
|
end
|
42
42
|
|
43
43
|
# Code to run when someone has tried but failed to sign in.
|
44
44
|
mattr_accessor :failed_sign_in_hook
|
45
45
|
@@failed_sign_in_hook = nil
|
46
46
|
|
47
|
-
def self.failed_sign_in_hook(
|
48
|
-
@@failed_sign_in_hook.call(
|
47
|
+
def self.failed_sign_in_hook(controller)
|
48
|
+
@@failed_sign_in_hook.call(controller) if @@failed_sign_in_hook
|
49
49
|
end
|
50
50
|
|
51
51
|
# Code to run just before the user has signed out.
|
52
52
|
mattr_accessor :signed_out_hook
|
53
53
|
@@signed_out_hook = nil
|
54
54
|
|
55
|
-
def self.signed_out_hook(user,
|
56
|
-
@@signed_out_hook.call(user,
|
55
|
+
def self.signed_out_hook(user, controller)
|
56
|
+
@@signed_out_hook.call(user, controller) if @@signed_out_hook
|
57
57
|
end
|
58
58
|
|
59
59
|
|
60
|
+
#
|
61
|
+
# Miscellaneous
|
62
|
+
#
|
63
|
+
|
64
|
+
# Layout for the sign-in view.
|
65
|
+
mattr_accessor :layout
|
66
|
+
@@layout = nil
|
67
|
+
|
68
|
+
|
60
69
|
# Configure from the initializer.
|
61
70
|
def self.configure
|
62
71
|
yield self
|
data/quo_vadis.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ['Andy Stewart']
|
10
10
|
s.email = ['boss@airbladesoftware.com']
|
11
|
-
s.homepage = ''
|
12
|
-
s.summary = 'Simple authentication for Rails 3.'
|
11
|
+
s.homepage = 'https://github.com/airblade/quo_vadis'
|
12
|
+
s.summary = 'Simple username/password authentication for Rails 3.'
|
13
13
|
s.description = s.summary
|
14
14
|
|
15
15
|
s.rubyforge_project = 'quo_vadis'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocaleTest < ActiveSupport::IntegrationCase
|
4
|
+
|
5
|
+
teardown do
|
6
|
+
Capybara.reset_sessions!
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'before_sign_in flash' do
|
10
|
+
visit new_article_path
|
11
|
+
within '.flash' do
|
12
|
+
assert page.has_content?('Please sign in first.')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'after_sign_in flash' do
|
17
|
+
user_factory 'Bob', 'bob', 'secret'
|
18
|
+
sign_in_as 'bob', 'secret'
|
19
|
+
within '.flash' do
|
20
|
+
assert page.has_content?('You have successfully signed in.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'failed_sign_in flash' do
|
25
|
+
sign_in_as 'bob', 'secret'
|
26
|
+
within '.flash' do
|
27
|
+
assert page.has_content?('Sorry, we did not recognise you.')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'sign_out flash' do
|
32
|
+
visit sign_out_path
|
33
|
+
within '.flash' do
|
34
|
+
assert page.has_content?('You have successfully signed out.')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'before_sign_in flash is optional' do
|
39
|
+
begin
|
40
|
+
I18n.backend.store_translations :en, {:quo_vadis => {:flash => {:before_sign_in => ''}}}
|
41
|
+
visit new_article_path
|
42
|
+
assert page.has_no_css?('div.flash')
|
43
|
+
ensure
|
44
|
+
I18n.reload!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'after_sign_in flash is optional' do
|
49
|
+
user_factory 'Bob', 'bob', 'secret'
|
50
|
+
begin
|
51
|
+
I18n.backend.store_translations :en, {:quo_vadis => {:flash => {:after_sign_in => ''}}}
|
52
|
+
sign_in_as 'bob', 'secret'
|
53
|
+
assert page.has_no_css?('div.flash')
|
54
|
+
ensure
|
55
|
+
I18n.reload!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'failed_sign_in flash is optional' do
|
60
|
+
begin
|
61
|
+
I18n.backend.store_translations :en, {:quo_vadis => {:flash => {:failed_sign_in => ''}}}
|
62
|
+
sign_in_as 'bob', 'secret'
|
63
|
+
assert page.has_no_css?('div.flash')
|
64
|
+
ensure
|
65
|
+
I18n.reload!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'sign_out flash is optional' do
|
70
|
+
begin
|
71
|
+
I18n.backend.store_translations :en, {:quo_vadis => {:flash => {:sign_out => ''}}}
|
72
|
+
visit sign_out_path
|
73
|
+
assert page.has_no_css?('div.flash')
|
74
|
+
ensure
|
75
|
+
I18n.reload!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -37,10 +37,11 @@ def user_factory(name, username, password)
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def reset_quo_vadis_configuration
|
40
|
-
QuoVadis.signed_in_url
|
40
|
+
QuoVadis.signed_in_url = :root
|
41
41
|
QuoVadis.override_original_url = false
|
42
|
-
QuoVadis.signed_out_url
|
43
|
-
QuoVadis.signed_in_hook
|
44
|
-
QuoVadis.failed_sign_in_hook
|
45
|
-
QuoVadis.signed_out_hook
|
42
|
+
QuoVadis.signed_out_url = :root
|
43
|
+
QuoVadis.signed_in_hook = nil
|
44
|
+
QuoVadis.failed_sign_in_hook = nil
|
45
|
+
QuoVadis.signed_out_hook = nil
|
46
|
+
QuoVadis.layout = 'application'
|
46
47
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quo_vadis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Stewart
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-26 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
version: "0"
|
94
94
|
type: :development
|
95
95
|
version_requirements: *id005
|
96
|
-
description: Simple authentication for Rails 3.
|
96
|
+
description: Simple username/password authentication for Rails 3.
|
97
97
|
email:
|
98
98
|
- boss@airbladesoftware.com
|
99
99
|
executables: []
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- test/dummy/app/views/articles/index.html.erb
|
131
131
|
- test/dummy/app/views/articles/new.html.erb
|
132
132
|
- test/dummy/app/views/layouts/application.html.erb
|
133
|
+
- test/dummy/app/views/layouts/sessions.html.erb
|
133
134
|
- test/dummy/app/views/sessions/new.html.erb
|
134
135
|
- test/dummy/config.ru
|
135
136
|
- test/dummy/config/application.rb
|
@@ -169,6 +170,7 @@ files:
|
|
169
170
|
- test/integration/authenticate_test.rb
|
170
171
|
- test/integration/config_test.rb
|
171
172
|
- test/integration/helper_test.rb
|
173
|
+
- test/integration/locale_test.rb
|
172
174
|
- test/integration/navigation_test.rb
|
173
175
|
- test/integration/sign_in_test.rb
|
174
176
|
- test/integration/sign_out_test.rb
|
@@ -176,7 +178,7 @@ files:
|
|
176
178
|
- test/support/integration_case.rb
|
177
179
|
- test/test_helper.rb
|
178
180
|
has_rdoc: true
|
179
|
-
homepage:
|
181
|
+
homepage: https://github.com/airblade/quo_vadis
|
180
182
|
licenses: []
|
181
183
|
|
182
184
|
post_install_message:
|
@@ -208,7 +210,7 @@ rubyforge_project: quo_vadis
|
|
208
210
|
rubygems_version: 1.3.7
|
209
211
|
signing_key:
|
210
212
|
specification_version: 3
|
211
|
-
summary: Simple authentication for Rails 3.
|
213
|
+
summary: Simple username/password authentication for Rails 3.
|
212
214
|
test_files:
|
213
215
|
- test/dummy/.gitignore
|
214
216
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -220,6 +222,7 @@ test_files:
|
|
220
222
|
- test/dummy/app/views/articles/index.html.erb
|
221
223
|
- test/dummy/app/views/articles/new.html.erb
|
222
224
|
- test/dummy/app/views/layouts/application.html.erb
|
225
|
+
- test/dummy/app/views/layouts/sessions.html.erb
|
223
226
|
- test/dummy/app/views/sessions/new.html.erb
|
224
227
|
- test/dummy/config.ru
|
225
228
|
- test/dummy/config/application.rb
|
@@ -259,6 +262,7 @@ test_files:
|
|
259
262
|
- test/integration/authenticate_test.rb
|
260
263
|
- test/integration/config_test.rb
|
261
264
|
- test/integration/helper_test.rb
|
265
|
+
- test/integration/locale_test.rb
|
262
266
|
- test/integration/navigation_test.rb
|
263
267
|
- test/integration/sign_in_test.rb
|
264
268
|
- test/integration/sign_out_test.rb
|