authenticate 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +6 -23
- data/app/controllers/authenticate/users_controller.rb +4 -1
- data/app/views/users/new.html.erb +10 -0
- data/config/routes.rb +2 -1
- data/lib/authenticate/configuration.rb +15 -2
- data/lib/authenticate/model/db_password.rb +10 -2
- data/lib/authenticate/modules.rb +2 -2
- data/lib/authenticate/version.rb +1 -1
- data/lib/generators/authenticate/helpers.rb +62 -0
- data/lib/generators/authenticate/install/install_generator.rb +41 -19
- data/lib/generators/authenticate/install/templates/authenticate.rb +2 -0
- data/lib/generators/authenticate/install/templates/db/migrate/add_authenticate_brute_force_to_users.rb +2 -2
- data/lib/generators/authenticate/install/templates/db/migrate/add_authenticate_password_reset_to_users.rb +3 -2
- data/lib/generators/authenticate/install/templates/db/migrate/add_authenticate_timeoutable_to_users.rb +1 -1
- data/lib/generators/authenticate/install/templates/db/migrate/add_authenticate_to_users.rb +2 -2
- data/lib/generators/authenticate/install/templates/db/migrate/create_users.rb +1 -2
- data/lib/generators/authenticate/routes/routes_generator.rb +5 -1
- data/lib/generators/authenticate/routes/templates/routes.rb +1 -1
- data/spec/model/db_password_spec.rb +58 -21
- data/spec/model/email_spec.rb +1 -1
- data/spec/model/password_reset_spec.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c160442936452dc9147dbe4fd4d917c1aa278b50
|
4
|
+
data.tar.gz: 358c081a740043a8db0e95b62f8ce8e3512ffbf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 392b0d52f226921b405e65bff052ac0e7f20eb2ed84c4047a44ddff2e544db0173734957425e51604137143ebb53573ba49077518eccc4543dcea7200b7d0166
|
7
|
+
data.tar.gz: 4e7833c91bf197290bdba2d81536adc920cc6c7e06ef710b3f7f095038d9c0709600e7be4d3f6ddd92738750e89c52b027b459bf2c044fccfabc3044c0fc726d
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# Authenticate Changelog
|
2
2
|
|
3
|
+
## [0.2.2] - February 9, 2016
|
3
4
|
|
4
|
-
|
5
|
+
Password length range requirements added, defaults to 8..128.
|
6
|
+
Generators and app now respect model class more completely, including in routes.
|
7
|
+
|
8
|
+
[0.2.2]: https://github.com/tomichj/authenticate/compare/v0.2.1...v0.2.2
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## [0.2.1] - February 9, 2016
|
5
13
|
|
6
14
|
Fixed potential password_reset nil pointer.
|
7
15
|
Continued adding I18n support.
|
@@ -10,6 +18,7 @@ Minor documentation improvments.
|
|
10
18
|
[0.2.1]: https://github.com/tomichj/authenticate/compare/v0.2.0...v0.2.1
|
11
19
|
|
12
20
|
|
21
|
+
|
13
22
|
## [0.2.0] - February 2, 2016
|
14
23
|
|
15
24
|
Added app/ including controllers, views, routes, mailers.
|
@@ -17,6 +26,7 @@ Added app/ including controllers, views, routes, mailers.
|
|
17
26
|
[0.2.0]: https://github.com/tomichj/authenticate/compare/v0.1.0...v0.2.0
|
18
27
|
|
19
28
|
|
29
|
+
|
20
30
|
## 0.1.0 - January 23, 2016
|
21
31
|
|
22
32
|
Initial Release, barely functioning
|
data/README.md
CHANGED
@@ -63,7 +63,7 @@ rails generate authenticate:install
|
|
63
63
|
|
64
64
|
The generator does the following:
|
65
65
|
|
66
|
-
* Insert `include Authenticate::User` into your `User` model.
|
66
|
+
* Insert `include Authenticate::User` into your `User` model. If you don't have a User model, one is created.
|
67
67
|
* Insert `include Authenticate::Controller` into your `ApplicationController`
|
68
68
|
* Add an initializer at `config/intializers/authenticate.rb`.
|
69
69
|
* Create migrations to either create a users table or add additional columns to :user. A primary migration is added,
|
@@ -93,10 +93,11 @@ Authenticate.configure do |config|
|
|
93
93
|
config.cookie_http_only = false
|
94
94
|
config.mailer_sender = 'reply@example.com'
|
95
95
|
config.crypto_provider = Bcrypt
|
96
|
-
config.timeout_in = nil
|
96
|
+
config.timeout_in = nil
|
97
97
|
config.max_session_lifetime = nil # 8.hours
|
98
|
-
config.max_consecutive_bad_logins_allowed = nil
|
98
|
+
config.max_consecutive_bad_logins_allowed = nil
|
99
99
|
config.bad_login_lockout_period = nil # 5.minutes
|
100
|
+
config.password_length = 8..128
|
100
101
|
config.authentication_strategy = :email
|
101
102
|
config.redirect_url = '/'
|
102
103
|
config.allow_sign_up = true
|
@@ -270,27 +271,9 @@ $ rails generate authenticate:views
|
|
270
271
|
|
271
272
|
### Layout
|
272
273
|
|
273
|
-
Authenticate uses your application's default layout. If you would like to change the layout
|
274
|
+
Authenticate uses your application's default layout. If you would like to change the layout Authenticate uses when
|
274
275
|
rendering views, you can either deploy copies of the controllers and customize them, or you can specify
|
275
|
-
the layout in an initializer. This
|
276
|
-
because it's executed once in production and before each request in development.
|
277
|
-
|
278
|
-
You can specify the layout per-controller:
|
279
|
-
|
280
|
-
```ruby
|
281
|
-
config.to_prepare do
|
282
|
-
Authenticate::PasswordsController.layout 'my_passwords_layout'
|
283
|
-
Authenticate::SessionsController.layout 'my_sessions_layout'
|
284
|
-
Authenticate::UsersController.layout 'my_users_layout'
|
285
|
-
end
|
286
|
-
```
|
287
|
-
|
288
|
-
|
289
|
-
### Layout
|
290
|
-
|
291
|
-
Authenticate uses your application's default layout. If you would like to change the layout clearance uses when
|
292
|
-
rendering views, you can either deploy copies of the controllers and customize them, or you can specify
|
293
|
-
the layout in an initializer. This needs to be done in a to_prepare callback in `config/application.rb`
|
276
|
+
the layout in an initializer. This should be done in a to_prepare callback in `config/application.rb`
|
294
277
|
because it's executed once in production and before each request in development.
|
295
278
|
|
296
279
|
You can specify the layout per-controller:
|
@@ -14,6 +14,8 @@ class Authenticate::UsersController < Authenticate::AuthenticateController
|
|
14
14
|
login @user
|
15
15
|
redirect_back_or url_after_create
|
16
16
|
else
|
17
|
+
logger.info "@user: " + @user.inspect
|
18
|
+
logger.info "ERRORS?: " + @user.errors.inspect
|
17
19
|
render template: 'users/new'
|
18
20
|
end
|
19
21
|
end
|
@@ -41,6 +43,7 @@ class Authenticate::UsersController < Authenticate::AuthenticateController
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def user_params
|
44
|
-
|
46
|
+
key = Authenticate.configuration.user_model_param_key.to_sym
|
47
|
+
params[key] || Hash.new
|
45
48
|
end
|
46
49
|
end
|
@@ -3,6 +3,16 @@
|
|
3
3
|
|
4
4
|
<%= form_for @user do |form| %>
|
5
5
|
|
6
|
+
<% if @user.errors.any? %>
|
7
|
+
<ul>
|
8
|
+
<% @user.errors.full_messages.each do |msg| %>
|
9
|
+
<li><%= msg %></li>
|
10
|
+
<% end %>
|
11
|
+
</ul>
|
12
|
+
<br>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
|
6
16
|
<div class="field">
|
7
17
|
<%= form.label :email %>
|
8
18
|
<%= form.text_field :email, type: 'email' %>
|
data/config/routes.rb
CHANGED
@@ -4,7 +4,8 @@ if Authenticate.configuration.routes_enabled?
|
|
4
4
|
resources :passwords, controller: 'authenticate/passwords', only: [:new, :create]
|
5
5
|
|
6
6
|
user_actions = Authenticate.configuration.allow_sign_up? ? [:new, :create] : []
|
7
|
-
|
7
|
+
user_model = Authenticate.configuration.user_model_route_key
|
8
|
+
resource user_model, controller: 'authenticate/users', only: user_actions do
|
8
9
|
resources :passwords, controller: 'authenticate/passwords', only: [:edit, :update]
|
9
10
|
end
|
10
11
|
|
@@ -99,6 +99,10 @@ module Authenticate
|
|
99
99
|
# @return [ActiveSupport::CoreExtensions::Numeric::Time]
|
100
100
|
attr_accessor :bad_login_lockout_period
|
101
101
|
|
102
|
+
# Range requirement for password length. Defaults to `8..128`.
|
103
|
+
# @return [Range]
|
104
|
+
attr_accessor :password_length
|
105
|
+
|
102
106
|
# Strategy for authentication.
|
103
107
|
#
|
104
108
|
# Available strategies:
|
@@ -133,7 +137,6 @@ module Authenticate
|
|
133
137
|
# @return [Boolean]
|
134
138
|
attr_accessor :allow_sign_up
|
135
139
|
|
136
|
-
|
137
140
|
# Enable or disable Authenticate's built-in routes. Defaults to 'true',
|
138
141
|
# enabling Authenticate's built-in routes. Disable by setting to 'false'.
|
139
142
|
# If you disable the routes, your application is responsible for all routes.
|
@@ -176,12 +179,23 @@ module Authenticate
|
|
176
179
|
@modules = []
|
177
180
|
@user_model = '::User'
|
178
181
|
@authentication_strategy = :email
|
182
|
+
@password_length = 8..128
|
179
183
|
end
|
180
184
|
|
181
185
|
def user_model_class
|
182
186
|
@user_model_class ||= user_model.constantize
|
183
187
|
end
|
184
188
|
|
189
|
+
def user_model_route_key
|
190
|
+
return :users if @user_model == '::User' # avoid nil in generator
|
191
|
+
Authenticate.configuration.user_model_class.model_name.route_key
|
192
|
+
end
|
193
|
+
|
194
|
+
def user_model_param_key
|
195
|
+
return :user if @user_model == '::User' # avoid nil in generator
|
196
|
+
Authenticate.configuration.user_model_class.model_name.param_key
|
197
|
+
end
|
198
|
+
|
185
199
|
# The name of foreign key parameter for the configured user model.
|
186
200
|
# This is derived from the `model_name` of the `user_model` setting.
|
187
201
|
# In the default configuration, this is `user_id`.
|
@@ -214,7 +228,6 @@ module Authenticate
|
|
214
228
|
modules
|
215
229
|
end
|
216
230
|
|
217
|
-
|
218
231
|
end # end of Configuration class
|
219
232
|
|
220
233
|
|
@@ -35,7 +35,10 @@ module Authenticate
|
|
35
35
|
include crypto_provider
|
36
36
|
attr_reader :password
|
37
37
|
attr_accessor :password_changing
|
38
|
-
validates :password,
|
38
|
+
validates :password,
|
39
|
+
presence: true,
|
40
|
+
length:{ in: password_length },
|
41
|
+
unless: :skip_password_validation?
|
39
42
|
end
|
40
43
|
|
41
44
|
|
@@ -60,12 +63,17 @@ module Authenticate
|
|
60
63
|
def crypto_provider
|
61
64
|
Authenticate.configuration.crypto_provider || Authenticate::Crypto::BCrypt
|
62
65
|
end
|
66
|
+
|
67
|
+
def password_length
|
68
|
+
Authenticate.configuration.password_length
|
69
|
+
end
|
63
70
|
end
|
64
71
|
|
65
72
|
|
66
73
|
# If we already have an encrypted password and it's not changing, skip the validation.
|
67
74
|
def skip_password_validation?
|
68
|
-
encrypted_password.present? && !password_changing
|
75
|
+
# encrypted_password.present? && !password_changing
|
76
|
+
false
|
69
77
|
end
|
70
78
|
|
71
79
|
end
|
data/lib/authenticate/modules.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Authenticate
|
2
2
|
module Modules
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
include Authenticate::Debug
|
5
4
|
|
6
5
|
# Module to help Authenticate's user model load Authenticate modules.
|
7
6
|
#
|
@@ -59,7 +58,8 @@ module Authenticate
|
|
59
58
|
end
|
60
59
|
|
61
60
|
if failed_attributes.any?
|
62
|
-
fail MissingAttribute.new(failed_attributes)
|
61
|
+
# fail MissingAttribute.new(failed_attributes)
|
62
|
+
Rails.logger.warn "The following attribute(s) is (are) missing on your user model: #{failed_attributes.join(", ")}"
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
data/lib/authenticate/version.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Authenticate
|
2
|
+
module Generators
|
3
|
+
module Helpers
|
4
|
+
private
|
5
|
+
|
6
|
+
# Either return the model passed in a classified form or return the default "User".
|
7
|
+
def model_class_name
|
8
|
+
options[:model] ? options[:model].classify : 'User'
|
9
|
+
end
|
10
|
+
|
11
|
+
def model_path
|
12
|
+
@model_path ||= File.join('app', 'models', "#{file_path}.rb")
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_path
|
16
|
+
model_name.underscore
|
17
|
+
end
|
18
|
+
|
19
|
+
def namespace
|
20
|
+
Rails::Generators.namespace if Rails::Generators.respond_to?(:namespace)
|
21
|
+
end
|
22
|
+
|
23
|
+
def namespaced?
|
24
|
+
!!namespace
|
25
|
+
end
|
26
|
+
|
27
|
+
def model_name
|
28
|
+
if namespaced?
|
29
|
+
[namespace.to_s] + [model_class_name]
|
30
|
+
else
|
31
|
+
[model_class_name]
|
32
|
+
end.join('::')
|
33
|
+
end
|
34
|
+
|
35
|
+
def table_name
|
36
|
+
@table_name ||= begin
|
37
|
+
base = plural_name
|
38
|
+
(class_path + [base]).join('_')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def class_path
|
43
|
+
@class_path
|
44
|
+
end
|
45
|
+
|
46
|
+
def singular_name
|
47
|
+
@file_name
|
48
|
+
end
|
49
|
+
|
50
|
+
def plural_name
|
51
|
+
singular_name.pluralize
|
52
|
+
end
|
53
|
+
|
54
|
+
def assign_names!(name) #:nodoc:
|
55
|
+
@class_path = name.include?('/') ? name.split('/') : name.split('::')
|
56
|
+
@class_path.map!(&:underscore)
|
57
|
+
@file_name = @class_path.pop
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,31 +1,33 @@
|
|
1
1
|
require 'rails/generators/base'
|
2
2
|
require 'rails/generators/active_record'
|
3
|
+
require 'generators/authenticate/helpers'
|
3
4
|
|
4
5
|
module Authenticate
|
5
6
|
module Generators
|
6
7
|
class InstallGenerator < Rails::Generators::Base
|
7
8
|
include Rails::Generators::Migration
|
9
|
+
include Authenticate::Generators::Helpers
|
10
|
+
|
8
11
|
source_root File.expand_path('../templates', __FILE__)
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
class_option :model, optional: true, type: :string, banner: 'model',
|
14
|
+
desc: "Specify the model class name if you will use anything other than 'User'"
|
15
|
+
|
16
|
+
def initialize(*)
|
17
|
+
super
|
18
|
+
assign_names!(model_class_name)
|
12
19
|
end
|
13
20
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
)
|
21
|
+
def verify
|
22
|
+
if options[:model] && !File.exists?(model_path)
|
23
|
+
puts "Exiting: the model class you specified, #{options[:model]}, is not found."
|
24
|
+
exit 1
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
def create_or_inject_into_user_model
|
23
|
-
if File.exist?
|
24
|
-
|
25
|
-
'app/models/user.rb',
|
26
|
-
' include Authenticate::User\n\n',
|
27
|
-
after: 'class User < ActiveRecord::Base\n'
|
28
|
-
)
|
29
|
+
if File.exist? model_path
|
30
|
+
inject_into_class(model_path, model_class_name, " include Authenticate::User\n\n")
|
29
31
|
else
|
30
32
|
copy_file 'user.rb', 'app/models/user.rb'
|
31
33
|
end
|
@@ -45,6 +47,26 @@ module Authenticate
|
|
45
47
|
copy_migration 'add_authenticate_password_reset_to_users.rb'
|
46
48
|
end
|
47
49
|
|
50
|
+
def inject_into_application_controller
|
51
|
+
inject_into_class(
|
52
|
+
'app/controllers/application_controller.rb',
|
53
|
+
ApplicationController,
|
54
|
+
" include Authenticate::Controller\n\n"
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_initializer
|
59
|
+
copy_file 'authenticate.rb', 'config/initializers/authenticate.rb'
|
60
|
+
if options[:model]
|
61
|
+
inject_into_file(
|
62
|
+
'config/initializers/authenticate.rb',
|
63
|
+
" config.user_model = '#{options[:model]}' \n",
|
64
|
+
after: "Authenticate.configure do |config|\n",
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
48
70
|
private
|
49
71
|
|
50
72
|
def create_new_users_migration
|
@@ -96,8 +118,8 @@ module Authenticate
|
|
96
118
|
|
97
119
|
def new_indexes
|
98
120
|
@new_indexes ||= {
|
99
|
-
index_users_on_email:
|
100
|
-
index_users_on_session_token:
|
121
|
+
index_users_on_email: "add_index :#{table_name}, :email",
|
122
|
+
index_users_on_session_token: "add_index :#{table_name}, :session_token"
|
101
123
|
}.reject { |index| existing_users_indexes.include?(index.to_s) }
|
102
124
|
end
|
103
125
|
|
@@ -116,17 +138,17 @@ module Authenticate
|
|
116
138
|
end
|
117
139
|
|
118
140
|
def users_table_exists?
|
119
|
-
ActiveRecord::Base.connection.table_exists?(
|
141
|
+
ActiveRecord::Base.connection.table_exists?(table_name)
|
120
142
|
end
|
121
143
|
|
122
144
|
def existing_users_columns
|
123
145
|
return [] unless users_table_exists?
|
124
|
-
ActiveRecord::Base.connection.columns(
|
146
|
+
ActiveRecord::Base.connection.columns(table_name).map(&:name)
|
125
147
|
end
|
126
148
|
|
127
149
|
def existing_users_indexes
|
128
150
|
return [] unless users_table_exists?
|
129
|
-
ActiveRecord::Base.connection.indexes(
|
151
|
+
ActiveRecord::Base.connection.indexes(table_name).map(&:name)
|
130
152
|
end
|
131
153
|
|
132
154
|
# for generating a timestamp when using `create_migration`
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class AddAuthenticateBruteForceToUsers < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
add_column
|
4
|
-
add_column
|
3
|
+
add_column :<%= table_name %>, :failed_logins_count, :integer, default: 0
|
4
|
+
add_column :<%= table_name %>, :lock_expires_at, :datetime, default: nil
|
5
5
|
end
|
6
6
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class AddAuthenticatePasswordResetToUsers < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
add_column
|
4
|
-
add_column
|
3
|
+
add_column :<%= table_name %>, :password_reset_token, :string, default: nil
|
4
|
+
add_column :<%= table_name %>, :password_reset_sent_at, :datetime, default: nil
|
5
|
+
add_index :<%= table_name %>, :password_reset_token
|
5
6
|
end
|
6
7
|
end
|
7
8
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class AddAuthenticateToUsers < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
change_table
|
3
|
+
change_table :<%= table_name %> do |t|
|
4
4
|
<% config[:new_columns].values.each do |column| -%>
|
5
5
|
<%= column %>
|
6
6
|
<% end -%>
|
@@ -12,7 +12,7 @@ class AddAuthenticateToUsers < ActiveRecord::Migration
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.down
|
15
|
-
change_table
|
15
|
+
change_table :<%= table_name %> do |t|
|
16
16
|
<% if config[:new_columns].any? -%>
|
17
17
|
t.remove <%= new_columns.keys.map { |column| ":#{column}" }.join(", ") %>
|
18
18
|
<% end -%>
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'rails/generators/base'
|
2
|
+
require 'generators/authenticate/helpers'
|
2
3
|
|
3
4
|
module Authenticate
|
4
5
|
module Generators
|
5
6
|
class RoutesGenerator < Rails::Generators::Base
|
7
|
+
include Authenticate::Generators::Helpers
|
8
|
+
|
6
9
|
source_root File.expand_path('../templates', __FILE__)
|
7
10
|
|
8
11
|
def add_authenticate_routes
|
@@ -20,7 +23,8 @@ module Authenticate
|
|
20
23
|
private
|
21
24
|
|
22
25
|
def authenticate_routes
|
23
|
-
|
26
|
+
@user_model = Authenticate.configuration.user_model_route_key
|
27
|
+
ERB.new(File.read(routes_file_path)).result(binding)
|
24
28
|
end
|
25
29
|
|
26
30
|
def routes_file_path
|
@@ -1,7 +1,7 @@
|
|
1
1
|
resource :session, controller: 'authenticate/sessions', only: [:create, :new, :destroy]
|
2
2
|
resources :passwords, controller: 'authenticate/passwords', only: [:new, :create]
|
3
3
|
|
4
|
-
resource
|
4
|
+
resource :<%= @user_model %>, controller: 'authenticate/users', only: [:new, :create] do
|
5
5
|
resources :passwords, controller: 'authenticate/passwords', only: [:edit, :update]
|
6
6
|
end
|
7
7
|
|
@@ -3,31 +3,68 @@ require 'authenticate/model/db_password'
|
|
3
3
|
|
4
4
|
|
5
5
|
describe Authenticate::Model::DbPassword do
|
6
|
+
describe 'Passwords' do
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
user.save
|
10
|
-
expect(user.errors.count).to be(1)
|
11
|
-
expect(user.errors.messages[:password]).to eq(["can't be blank"])
|
12
|
-
end
|
8
|
+
context '#password_match?' do
|
9
|
+
subject { create(:user, password: 'password') }
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
11
|
+
it 'matches a password' do
|
12
|
+
expect(subject.password_match? 'password').to be_truthy
|
13
|
+
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
15
|
+
it 'fails to match a bad password' do
|
16
|
+
expect(subject.password_match? 'bad password').to be_falsey
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
user.save!
|
19
|
+
it 'saves passwords' do
|
20
|
+
subject.password = 'new_password'
|
21
|
+
subject.save!
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
user = User.find(subject.id)
|
24
|
+
expect(user.password_match? 'new_password').to be_truthy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'Validations' do
|
29
|
+
before(:all) {
|
30
|
+
Authenticate.configure do |config|
|
31
|
+
config.password_length = 8..128
|
32
|
+
end
|
33
|
+
}
|
34
|
+
|
35
|
+
context 'on a new user' do
|
36
|
+
it 'should not be valid without a password' do
|
37
|
+
user = build(:user, :without_password)
|
38
|
+
expect(user).to_not be_valid
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should be not be valid with a short password' do
|
42
|
+
user = build(:user, password: 'short')
|
43
|
+
expect(user).to_not be_valid
|
44
|
+
end
|
32
45
|
|
46
|
+
it 'is valid with a long password' do
|
47
|
+
user = build(:user, password: 'thisisalongpassword')
|
48
|
+
expect(user).to be_valid
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'on an existing user' do
|
53
|
+
subject { create(:user, password: 'password') }
|
54
|
+
|
55
|
+
it { is_expected.to be_valid }
|
56
|
+
|
57
|
+
it 'should not be valid with an empty password' do
|
58
|
+
subject.password = ''
|
59
|
+
expect(subject).to_not be_valid
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should be valid with a new (valid) password' do
|
63
|
+
subject.password = 'new password'
|
64
|
+
expect(subject).to be_valid
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
33
70
|
end
|
data/spec/model/email_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe Authenticate::Model::Email do
|
|
14
14
|
|
15
15
|
it 'extracts credentials from params' do
|
16
16
|
params = {session:{email:'foo', password:'bar'}}
|
17
|
-
expect(User.credentials(params)).to match_array(
|
17
|
+
expect(User.credentials(params)).to match_array(%w(foo bar))
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'authenticates from credentials' do
|
@@ -55,17 +55,17 @@ describe Authenticate::Model::PasswordReset do
|
|
55
55
|
}
|
56
56
|
|
57
57
|
it 'allows password update within time limit' do
|
58
|
-
expect(subject.update_password '
|
58
|
+
expect(subject.update_password 'password2').to be_truthy
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'clears password reset token' do
|
62
|
-
subject.update_password '
|
62
|
+
subject.update_password 'password2'
|
63
63
|
expect(subject.password_reset_token).to be_nil
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'generates a new session token' do
|
67
67
|
token = subject.session_token
|
68
|
-
subject.update_password '
|
68
|
+
subject.update_password 'password2'
|
69
69
|
expect(subject.session_token).to_not eq(token)
|
70
70
|
end
|
71
71
|
|
@@ -73,7 +73,7 @@ describe Authenticate::Model::PasswordReset do
|
|
73
73
|
|
74
74
|
it 'stops password update after time limit' do
|
75
75
|
subject.password_reset_sent_at = 6.minutes.ago
|
76
|
-
expect(subject.update_password '
|
76
|
+
expect(subject.update_password 'password2').to be_falsey
|
77
77
|
end
|
78
78
|
|
79
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authenticate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Tomich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/authenticate/version.rb
|
186
186
|
- lib/generators/authenticate/controllers/USAGE
|
187
187
|
- lib/generators/authenticate/controllers/controllers_generator.rb
|
188
|
+
- lib/generators/authenticate/helpers.rb
|
188
189
|
- lib/generators/authenticate/install/USAGE
|
189
190
|
- lib/generators/authenticate/install/install_generator.rb
|
190
191
|
- lib/generators/authenticate/install/templates/authenticate.rb
|