easy_auth 0.0.1.alpha.1 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -3
- data/app/mailers/password_reset_mailer.rb +1 -1
- data/app/mixins/easy_auth/controllers/sessions.rb +5 -1
- data/app/mixins/easy_auth/helpers.rb +10 -0
- data/app/mixins/easy_auth/models/identity.rb +19 -1
- data/app/views/password_reset/edit.html.erb +11 -5
- data/app/views/password_reset/new.html.erb +7 -3
- data/app/views/sessions/new.html.erb +15 -5
- data/db/migrate/20120227014023_create_identities.rb +2 -1
- data/lib/easy_auth/version.rb +1 -1
- data/lib/easy_auth.rb +1 -0
- metadata +30 -27
data/Rakefile
CHANGED
@@ -5,7 +5,10 @@ module EasyAuth::Controllers::Sessions
|
|
5
5
|
|
6
6
|
def create
|
7
7
|
if identity = EasyAuth.identity_model.authenticate(params[:identity])
|
8
|
-
session[:session_token]
|
8
|
+
session[:session_token] = identity.generate_session_token!
|
9
|
+
if identity.remember
|
10
|
+
cookies[:remember_token] = { :value => identity.generate_remember_token!, :expires => identity.remember_time.from_now }
|
11
|
+
end
|
9
12
|
after_successful_sign_in(identity)
|
10
13
|
else
|
11
14
|
@identity = EasyAuth.identity_model.new(params[:identity])
|
@@ -15,6 +18,7 @@ module EasyAuth::Controllers::Sessions
|
|
15
18
|
|
16
19
|
def destroy
|
17
20
|
session.delete(:session_token)
|
21
|
+
cookies.delete(:remember_token)
|
18
22
|
after_sign_out
|
19
23
|
end
|
20
24
|
|
@@ -14,6 +14,16 @@ module EasyAuth
|
|
14
14
|
@current_account = nil
|
15
15
|
session.delete(:session_token)
|
16
16
|
end
|
17
|
+
elsif cookies[:remember_token]
|
18
|
+
begin
|
19
|
+
@current_account ||= EasyAuth.identity_model.find_by_remember_token(cookies[:remember_token]).account
|
20
|
+
rescue
|
21
|
+
@current_acount = nil
|
22
|
+
cookies.delete(:remember_token)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
session.delete(:session_token)
|
26
|
+
cookies.delete(:remember_token)
|
17
27
|
end
|
18
28
|
|
19
29
|
@current_account
|
@@ -3,12 +3,13 @@ module EasyAuth::Models::Identity
|
|
3
3
|
base.class_eval do
|
4
4
|
belongs_to :account, :polymorphic => true
|
5
5
|
has_secure_password
|
6
|
-
attr_accessible :username, :password, :password_confirmation
|
6
|
+
attr_accessible :username, :password, :password_confirmation, :remember
|
7
7
|
|
8
8
|
def self.authenticate(attributes = nil)
|
9
9
|
return nil if attributes.nil?
|
10
10
|
|
11
11
|
if identity = where(arel_table[:username].matches(attributes[:username].try(&:strip))).first.try(:authenticate, attributes[:password])
|
12
|
+
identity.remember = attributes[:remember]
|
12
13
|
identity
|
13
14
|
else
|
14
15
|
nil
|
@@ -17,6 +18,14 @@ module EasyAuth::Models::Identity
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def remember
|
22
|
+
@remember
|
23
|
+
end
|
24
|
+
|
25
|
+
def remember=(value)
|
26
|
+
@remember = ::ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
|
27
|
+
end
|
28
|
+
|
20
29
|
def password_reset
|
21
30
|
update_attribute(:reset_token, URI.escape(_generate_token(:reset).gsub(/[\.|\\\/]/,'')))
|
22
31
|
PasswordResetMailer.reset(self.id).deliver
|
@@ -27,6 +36,15 @@ module EasyAuth::Models::Identity
|
|
27
36
|
self.session_token
|
28
37
|
end
|
29
38
|
|
39
|
+
def generate_remember_token!
|
40
|
+
self.update_attribute(:remember_token, _generate_token(:remember))
|
41
|
+
self.remember_token
|
42
|
+
end
|
43
|
+
|
44
|
+
def remember_time
|
45
|
+
1.year
|
46
|
+
end
|
47
|
+
|
30
48
|
private
|
31
49
|
|
32
50
|
def _generate_token(type)
|
@@ -1,7 +1,13 @@
|
|
1
1
|
<%= form_for @identity, :url => main_app.edit_password_path(params[:reset_token]) do |f| %>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
<p>
|
3
|
+
<%= f.label :password %>
|
4
|
+
<%= f.text_field :password %>
|
5
|
+
</p>
|
6
|
+
<p>
|
7
|
+
<%= f.label :password_confirmation %>
|
8
|
+
<%= f.text_field :password_confirmation %>
|
9
|
+
</p>
|
10
|
+
<p>
|
11
|
+
<%= f.submit 'Submit' %>
|
12
|
+
</p>
|
7
13
|
<% end %>
|
@@ -1,5 +1,9 @@
|
|
1
1
|
<%= form_for @identity, :url => main_app.password_reset_path do |f| %>
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
<p>
|
3
|
+
<%= f.label :username %>
|
4
|
+
<%= f.text_field :username %>
|
5
|
+
</p>
|
6
|
+
<p>
|
7
|
+
<%= f.submit 'Submit' %>
|
8
|
+
</p>
|
5
9
|
<% end %>
|
@@ -1,7 +1,17 @@
|
|
1
1
|
<%= form_for @identity, :url => main_app.sign_in_path do |f| %>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
<p>
|
3
|
+
<%= f.label :username %>
|
4
|
+
<%= f.text_field :username %>
|
5
|
+
</p>
|
6
|
+
<p>
|
7
|
+
<%= f.label :password %>
|
8
|
+
<%= f.password_field :password %>
|
9
|
+
</p>
|
10
|
+
<p>
|
11
|
+
<%= f.label :remember, "Remember for #{@identity.remember_time.inspect}" %>
|
12
|
+
<%= f.check_box :remember %>
|
13
|
+
</p>
|
14
|
+
<p>
|
15
|
+
<%= f.submit 'Submit' %>
|
16
|
+
</p>
|
7
17
|
<% end %>
|
@@ -7,10 +7,11 @@ class CreateIdentities < ActiveRecord::Migration
|
|
7
7
|
t.integer :account_id
|
8
8
|
t.string :reset_token
|
9
9
|
t.string :session_token
|
10
|
+
t.string :remember_token
|
10
11
|
t.timestamps
|
11
12
|
end
|
12
13
|
|
13
|
-
[:username, :reset_token, :session_token].each do |column|
|
14
|
+
[:username, :reset_token, :remember_token, :session_token].each do |column|
|
14
15
|
add_index :identities, column
|
15
16
|
end
|
16
17
|
end
|
data/lib/easy_auth/version.rb
CHANGED
data/lib/easy_auth.rb
CHANGED
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Cardarella
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70365829440860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70365829440860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bcrypt-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &70365829440220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70365829440220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70365829439460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70365829439460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec-rails
|
49
|
-
requirement: &
|
49
|
+
requirement: &70365829438880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70365829438880
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: capybara
|
60
|
-
requirement: &
|
60
|
+
requirement: &70365829438360 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70365829438360
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: capybara-email
|
71
|
-
requirement: &
|
71
|
+
requirement: &70365829437580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70365829437580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: valid_attribute
|
82
|
-
requirement: &
|
82
|
+
requirement: &70365829437000 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70365829437000
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: factory_girl_rails
|
93
|
-
requirement: &
|
93
|
+
requirement: &70365850682120 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70365850682120
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: bourne
|
104
|
-
requirement: &
|
104
|
+
requirement: &70365850681360 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70365850681360
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: debugger
|
115
|
-
requirement: &
|
115
|
+
requirement: &70365850680700 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70365850680700
|
124
124
|
description: EasyAuth
|
125
125
|
email:
|
126
126
|
- brian@dockyard.com
|
@@ -172,16 +172,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
segments:
|
174
174
|
- 0
|
175
|
-
hash: -
|
175
|
+
hash: -3835469776783802043
|
176
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
177
|
none: false
|
178
178
|
requirements:
|
179
|
-
- - ! '
|
179
|
+
- - ! '>='
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
181
|
+
version: '0'
|
182
|
+
segments:
|
183
|
+
- 0
|
184
|
+
hash: -3835469776783802043
|
182
185
|
requirements: []
|
183
186
|
rubyforge_project:
|
184
|
-
rubygems_version: 1.8.
|
187
|
+
rubygems_version: 1.8.11
|
185
188
|
signing_key:
|
186
189
|
specification_version: 3
|
187
190
|
summary: EasyAuth
|