quo_vadis 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/app/controllers/controller_mixin.rb +38 -6
- data/app/controllers/quo_vadis/sessions_controller.rb +0 -32
- data/lib/quo_vadis/version.rb +1 -1
- data/test/dummy/app/controllers/users_controller.rb +17 -0
- data/test/dummy/app/views/users/new.html.erb +14 -0
- data/test/dummy/config/routes.rb +1 -0
- data/test/integration/sign_up_test.rb +21 -0
- metadata +24 -19
- data/Gemfile.lock +0 -113
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,8 @@ module ControllerMixin
|
|
3
3
|
base.helper_method :current_user
|
4
4
|
end
|
5
5
|
|
6
|
+
protected
|
7
|
+
|
6
8
|
def handle_unverified_request
|
7
9
|
super
|
8
10
|
cookies.delete :remember_me
|
@@ -10,14 +12,9 @@ module ControllerMixin
|
|
10
12
|
|
11
13
|
private
|
12
14
|
|
13
|
-
# Returns true if the sign-in process is blocked to the user, false otherwise.
|
14
|
-
def blocked?
|
15
|
-
QuoVadis.blocked?(self)
|
16
|
-
end
|
17
|
-
|
18
15
|
# Remembers the authenticated <tt>user</tt> (in this session and future sessions).
|
19
16
|
#
|
20
|
-
# If you want to sign in a <tt>user</tt
|
17
|
+
# If you want to sign in a <tt>user</tt> you have just created, call <tt>sign_in</tt>
|
21
18
|
# instead.
|
22
19
|
def current_user=(user)
|
23
20
|
remember_user_in_session user
|
@@ -39,6 +36,24 @@ module ControllerMixin
|
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
39
|
+
# Signs in a user, i.e. remembers them in the session, runs the sign-in hook,
|
40
|
+
# and redirects appropriately.
|
41
|
+
#
|
42
|
+
# This method should be called when you have just authenticated a <tt>user</tt>
|
43
|
+
# and you need to sign them in. For example, if a new user has just signed up,
|
44
|
+
# you should call this method to sign them in.
|
45
|
+
def sign_in(user)
|
46
|
+
prevent_session_fixation
|
47
|
+
self.current_user = user
|
48
|
+
QuoVadis.signed_in_hook user, self
|
49
|
+
redirect_to QuoVadis.signed_in_url(user, original_url)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns true if the sign-in process is blocked to the user, false otherwise.
|
53
|
+
def blocked?
|
54
|
+
QuoVadis.blocked?(self)
|
55
|
+
end
|
56
|
+
|
42
57
|
def remember_user_in_session(user) # :nodoc:
|
43
58
|
session[:current_user_id] = user ? user.id : nil
|
44
59
|
end
|
@@ -66,4 +81,21 @@ module ControllerMixin
|
|
66
81
|
def find_user_by_session # :nodoc:
|
67
82
|
User.find(session[:current_user_id]) if session[:current_user_id]
|
68
83
|
end
|
84
|
+
|
85
|
+
# Returns the URL if any which the user tried to visit before being forced to authenticate.
|
86
|
+
def original_url
|
87
|
+
url = session[:quo_vadis_original_url]
|
88
|
+
session[:quo_vadis_original_url] = nil
|
89
|
+
url
|
90
|
+
end
|
91
|
+
|
92
|
+
def prevent_session_fixation # :nodoc:
|
93
|
+
original_flash = flash.inject({}) { |hsh, (k,v)| hsh[k] = v; hsh }
|
94
|
+
original_url = session[:quo_vadis_original_url]
|
95
|
+
|
96
|
+
reset_session
|
97
|
+
|
98
|
+
original_flash.each { |k,v| flash[k] = v }
|
99
|
+
session[:quo_vadis_original_url] = original_url
|
100
|
+
end
|
69
101
|
end
|
@@ -77,30 +77,8 @@ class QuoVadis::SessionsController < ApplicationController
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
protected
|
81
|
-
|
82
|
-
# Signs in a user, i.e. remembers them in the session, runs the sign-in hook,
|
83
|
-
# and redirects appropriately.
|
84
|
-
#
|
85
|
-
# This method should be called when you have just authenticated <tt>user</tt>
|
86
|
-
# and you need to sign them in. For example, if a new user has just signed up,
|
87
|
-
# you should call this method to sign them in.
|
88
|
-
def sign_in(user)
|
89
|
-
prevent_session_fixation
|
90
|
-
self.current_user = user
|
91
|
-
QuoVadis.signed_in_hook user, self
|
92
|
-
redirect_to QuoVadis.signed_in_url(user, original_url)
|
93
|
-
end
|
94
|
-
|
95
80
|
private
|
96
81
|
|
97
|
-
# Returns the URL if any which the user tried to visit before being forced to authenticate.
|
98
|
-
def original_url
|
99
|
-
url = session[:quo_vadis_original_url]
|
100
|
-
session[:quo_vadis_original_url] = nil
|
101
|
-
url
|
102
|
-
end
|
103
|
-
|
104
82
|
def invalid_token # :nodoc:
|
105
83
|
flash[:alert] = t('quo_vadis.flash.forgotten.invalid_token') unless t('quo_vadis.flash.forgotten.invalid_token').blank?
|
106
84
|
redirect_to forgotten_sign_in_url
|
@@ -110,14 +88,4 @@ class QuoVadis::SessionsController < ApplicationController
|
|
110
88
|
QuoVadis.layout
|
111
89
|
end
|
112
90
|
|
113
|
-
def prevent_session_fixation # :nodoc:
|
114
|
-
original_flash = flash.inject({}) { |hsh, (k,v)| hsh[k] = v; hsh }
|
115
|
-
original_url = session[:quo_vadis_original_url]
|
116
|
-
|
117
|
-
reset_session
|
118
|
-
|
119
|
-
original_flash.each { |k,v| flash[k] = v }
|
120
|
-
session[:quo_vadis_original_url] = original_url
|
121
|
-
end
|
122
|
-
|
123
91
|
end
|
data/lib/quo_vadis/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class UsersController < ActionController::Base
|
2
|
+
|
3
|
+
def new
|
4
|
+
@user = User.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
@user = User.new params[:user]
|
9
|
+
if @user.save
|
10
|
+
flash[:notice] = 'You have signed up!'
|
11
|
+
sign_in @user # <-- Quo Vadis sign-in hook
|
12
|
+
else
|
13
|
+
render 'new'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<h1>Sign up</h1>
|
2
|
+
|
3
|
+
<%= form_for @user do |f| %>
|
4
|
+
<%= f.label :name %>
|
5
|
+
<%= f.text_field :name %>
|
6
|
+
|
7
|
+
<%= f.label :username %>
|
8
|
+
<%= f.text_field :username %>
|
9
|
+
|
10
|
+
<%= f.label :password %>
|
11
|
+
<%= f.password_field :password %>
|
12
|
+
|
13
|
+
<%= f.submit 'Sign up' %>
|
14
|
+
<% end %>
|
data/test/dummy/config/routes.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SignUpTest < ActiveSupport::IntegrationCase
|
4
|
+
|
5
|
+
test 'sign in of a just-signed-up user' do
|
6
|
+
visit new_user_path
|
7
|
+
fill_in 'user_name', :with => 'Robert'
|
8
|
+
fill_in 'user_username', :with => 'bob'
|
9
|
+
fill_in 'user_password', :with => 'secret'
|
10
|
+
click_button 'Sign up'
|
11
|
+
|
12
|
+
assert_equal root_path, current_path
|
13
|
+
|
14
|
+
within '.flash.notice' do
|
15
|
+
assert page.has_content?('You have signed up!')
|
16
|
+
end
|
17
|
+
|
18
|
+
assert page.has_content?('You are signed in as Robert')
|
19
|
+
end
|
20
|
+
|
21
|
+
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Stewart
|
@@ -15,10 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-03 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
22
23
|
prerelease: false
|
23
24
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
@@ -30,10 +31,10 @@ dependencies:
|
|
30
31
|
- 3
|
31
32
|
- 0
|
32
33
|
version: "3.0"
|
33
|
-
requirement: *id001
|
34
|
-
name: rails
|
35
34
|
type: :runtime
|
35
|
+
requirement: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
+
name: bcrypt-ruby
|
37
38
|
prerelease: false
|
38
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
@@ -46,10 +47,10 @@ dependencies:
|
|
46
47
|
- 1
|
47
48
|
- 4
|
48
49
|
version: 2.1.4
|
49
|
-
requirement: *id002
|
50
|
-
name: bcrypt-ruby
|
51
50
|
type: :runtime
|
51
|
+
requirement: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
|
+
name: rails
|
53
54
|
prerelease: false
|
54
55
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
56
|
none: false
|
@@ -62,10 +63,10 @@ dependencies:
|
|
62
63
|
- 0
|
63
64
|
- 4
|
64
65
|
version: 3.0.4
|
65
|
-
requirement: *id003
|
66
|
-
name: rails
|
67
66
|
type: :development
|
67
|
+
requirement: *id003
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
|
+
name: sqlite3-ruby
|
69
70
|
prerelease: false
|
70
71
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
72
|
none: false
|
@@ -76,10 +77,10 @@ dependencies:
|
|
76
77
|
segments:
|
77
78
|
- 0
|
78
79
|
version: "0"
|
79
|
-
requirement: *id004
|
80
|
-
name: sqlite3-ruby
|
81
80
|
type: :development
|
81
|
+
requirement: *id004
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
+
name: capybara
|
83
84
|
prerelease: false
|
84
85
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
85
86
|
none: false
|
@@ -92,10 +93,10 @@ dependencies:
|
|
92
93
|
- 4
|
93
94
|
- 0
|
94
95
|
version: 0.4.0
|
95
|
-
requirement: *id005
|
96
|
-
name: capybara
|
97
96
|
type: :development
|
97
|
+
requirement: *id005
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
+
name: launchy
|
99
100
|
prerelease: false
|
100
101
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
101
102
|
none: false
|
@@ -106,9 +107,8 @@ dependencies:
|
|
106
107
|
segments:
|
107
108
|
- 0
|
108
109
|
version: "0"
|
109
|
-
requirement: *id006
|
110
|
-
name: launchy
|
111
110
|
type: :development
|
111
|
+
requirement: *id006
|
112
112
|
description: Simple username/password authentication for Rails 3.
|
113
113
|
email:
|
114
114
|
- boss@airbladesoftware.com
|
@@ -122,7 +122,6 @@ files:
|
|
122
122
|
- .gitignore
|
123
123
|
- CHANGELOG.md
|
124
124
|
- Gemfile
|
125
|
-
- Gemfile.lock
|
126
125
|
- README.md
|
127
126
|
- Rakefile
|
128
127
|
- app/controllers/controller_mixin.rb
|
@@ -142,6 +141,7 @@ files:
|
|
142
141
|
- test/dummy/Rakefile
|
143
142
|
- test/dummy/app/controllers/application_controller.rb
|
144
143
|
- test/dummy/app/controllers/articles_controller.rb
|
144
|
+
- test/dummy/app/controllers/users_controller.rb
|
145
145
|
- test/dummy/app/helpers/application_helper.rb
|
146
146
|
- test/dummy/app/helpers/articles_helper.rb
|
147
147
|
- test/dummy/app/models/article.rb
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- test/dummy/app/views/sessions/edit.html.erb
|
155
155
|
- test/dummy/app/views/sessions/forgotten.html.erb
|
156
156
|
- test/dummy/app/views/sessions/new.html.erb
|
157
|
+
- test/dummy/app/views/users/new.html.erb
|
157
158
|
- test/dummy/config.ru
|
158
159
|
- test/dummy/config/application.rb
|
159
160
|
- test/dummy/config/boot.rb
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- test/integration/navigation_test.rb
|
204
205
|
- test/integration/sign_in_test.rb
|
205
206
|
- test/integration/sign_out_test.rb
|
207
|
+
- test/integration/sign_up_test.rb
|
206
208
|
- test/quo_vadis_test.rb
|
207
209
|
- test/support/integration_case.rb
|
208
210
|
- test/test_helper.rb
|
@@ -237,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
239
|
requirements: []
|
238
240
|
|
239
241
|
rubyforge_project: quo_vadis
|
240
|
-
rubygems_version: 1.
|
242
|
+
rubygems_version: 1.6.2
|
241
243
|
signing_key:
|
242
244
|
specification_version: 3
|
243
245
|
summary: Simple username/password authentication for Rails 3.
|
@@ -246,6 +248,7 @@ test_files:
|
|
246
248
|
- test/dummy/Rakefile
|
247
249
|
- test/dummy/app/controllers/application_controller.rb
|
248
250
|
- test/dummy/app/controllers/articles_controller.rb
|
251
|
+
- test/dummy/app/controllers/users_controller.rb
|
249
252
|
- test/dummy/app/helpers/application_helper.rb
|
250
253
|
- test/dummy/app/helpers/articles_helper.rb
|
251
254
|
- test/dummy/app/models/article.rb
|
@@ -258,6 +261,7 @@ test_files:
|
|
258
261
|
- test/dummy/app/views/sessions/edit.html.erb
|
259
262
|
- test/dummy/app/views/sessions/forgotten.html.erb
|
260
263
|
- test/dummy/app/views/sessions/new.html.erb
|
264
|
+
- test/dummy/app/views/users/new.html.erb
|
261
265
|
- test/dummy/config.ru
|
262
266
|
- test/dummy/config/application.rb
|
263
267
|
- test/dummy/config/boot.rb
|
@@ -307,6 +311,7 @@ test_files:
|
|
307
311
|
- test/integration/navigation_test.rb
|
308
312
|
- test/integration/sign_in_test.rb
|
309
313
|
- test/integration/sign_out_test.rb
|
314
|
+
- test/integration/sign_up_test.rb
|
310
315
|
- test/quo_vadis_test.rb
|
311
316
|
- test/support/integration_case.rb
|
312
317
|
- test/test_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
quo_vadis (1.0.5)
|
5
|
-
bcrypt-ruby (~> 2.1.4)
|
6
|
-
rails (~> 3.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
abstract (1.0.0)
|
12
|
-
actionmailer (3.0.4)
|
13
|
-
actionpack (= 3.0.4)
|
14
|
-
mail (~> 2.2.15)
|
15
|
-
actionpack (3.0.4)
|
16
|
-
activemodel (= 3.0.4)
|
17
|
-
activesupport (= 3.0.4)
|
18
|
-
builder (~> 2.1.2)
|
19
|
-
erubis (~> 2.6.6)
|
20
|
-
i18n (~> 0.4)
|
21
|
-
rack (~> 1.2.1)
|
22
|
-
rack-mount (~> 0.6.13)
|
23
|
-
rack-test (~> 0.5.7)
|
24
|
-
tzinfo (~> 0.3.23)
|
25
|
-
activemodel (3.0.4)
|
26
|
-
activesupport (= 3.0.4)
|
27
|
-
builder (~> 2.1.2)
|
28
|
-
i18n (~> 0.4)
|
29
|
-
activerecord (3.0.4)
|
30
|
-
activemodel (= 3.0.4)
|
31
|
-
activesupport (= 3.0.4)
|
32
|
-
arel (~> 2.0.2)
|
33
|
-
tzinfo (~> 0.3.23)
|
34
|
-
activeresource (3.0.4)
|
35
|
-
activemodel (= 3.0.4)
|
36
|
-
activesupport (= 3.0.4)
|
37
|
-
activesupport (3.0.4)
|
38
|
-
arel (2.0.8)
|
39
|
-
bcrypt-ruby (2.1.4)
|
40
|
-
builder (2.1.2)
|
41
|
-
capybara (0.4.1.2)
|
42
|
-
celerity (>= 0.7.9)
|
43
|
-
culerity (>= 0.2.4)
|
44
|
-
mime-types (>= 1.16)
|
45
|
-
nokogiri (>= 1.3.3)
|
46
|
-
rack (>= 1.0.0)
|
47
|
-
rack-test (>= 0.5.4)
|
48
|
-
selenium-webdriver (>= 0.0.27)
|
49
|
-
xpath (~> 0.1.3)
|
50
|
-
celerity (0.8.8)
|
51
|
-
childprocess (0.1.7)
|
52
|
-
ffi (~> 0.6.3)
|
53
|
-
configuration (1.2.0)
|
54
|
-
culerity (0.2.15)
|
55
|
-
erubis (2.6.6)
|
56
|
-
abstract (>= 1.0.0)
|
57
|
-
ffi (0.6.3)
|
58
|
-
rake (>= 0.8.7)
|
59
|
-
i18n (0.5.0)
|
60
|
-
json_pure (1.5.1)
|
61
|
-
launchy (0.3.7)
|
62
|
-
configuration (>= 0.0.5)
|
63
|
-
rake (>= 0.8.1)
|
64
|
-
mail (2.2.15)
|
65
|
-
activesupport (>= 2.3.6)
|
66
|
-
i18n (>= 0.4.0)
|
67
|
-
mime-types (~> 1.16)
|
68
|
-
treetop (~> 1.4.8)
|
69
|
-
mime-types (1.16)
|
70
|
-
nokogiri (1.4.4)
|
71
|
-
polyglot (0.3.1)
|
72
|
-
rack (1.2.1)
|
73
|
-
rack-mount (0.6.13)
|
74
|
-
rack (>= 1.0.0)
|
75
|
-
rack-test (0.5.7)
|
76
|
-
rack (>= 1.0)
|
77
|
-
rails (3.0.4)
|
78
|
-
actionmailer (= 3.0.4)
|
79
|
-
actionpack (= 3.0.4)
|
80
|
-
activerecord (= 3.0.4)
|
81
|
-
activeresource (= 3.0.4)
|
82
|
-
activesupport (= 3.0.4)
|
83
|
-
bundler (~> 1.0)
|
84
|
-
railties (= 3.0.4)
|
85
|
-
railties (3.0.4)
|
86
|
-
actionpack (= 3.0.4)
|
87
|
-
activesupport (= 3.0.4)
|
88
|
-
rake (>= 0.8.7)
|
89
|
-
thor (~> 0.14.4)
|
90
|
-
rake (0.8.7)
|
91
|
-
rubyzip (0.9.4)
|
92
|
-
selenium-webdriver (0.1.3)
|
93
|
-
childprocess (~> 0.1.5)
|
94
|
-
ffi (~> 0.6.3)
|
95
|
-
json_pure
|
96
|
-
rubyzip
|
97
|
-
sqlite3-ruby (1.2.5)
|
98
|
-
thor (0.14.6)
|
99
|
-
treetop (1.4.9)
|
100
|
-
polyglot (>= 0.3.1)
|
101
|
-
tzinfo (0.3.24)
|
102
|
-
xpath (0.1.3)
|
103
|
-
nokogiri (~> 1.3)
|
104
|
-
|
105
|
-
PLATFORMS
|
106
|
-
ruby
|
107
|
-
|
108
|
-
DEPENDENCIES
|
109
|
-
capybara (>= 0.4.0)
|
110
|
-
launchy
|
111
|
-
quo_vadis!
|
112
|
-
rails (>= 3.0.4)
|
113
|
-
sqlite3-ruby
|