devise_token_auth 1.0.0 → 1.1.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.

Potentially problematic release.


This version of devise_token_auth might be problematic. Click here for more details.

Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +4 -2
  3. data/app/controllers/devise_token_auth/application_controller.rb +0 -1
  4. data/app/controllers/devise_token_auth/concerns/resource_finder.rb +11 -12
  5. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +39 -55
  6. data/app/controllers/devise_token_auth/confirmations_controller.rb +62 -20
  7. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +51 -26
  8. data/app/controllers/devise_token_auth/passwords_controller.rb +19 -23
  9. data/app/controllers/devise_token_auth/registrations_controller.rb +32 -40
  10. data/app/controllers/devise_token_auth/sessions_controller.rb +5 -5
  11. data/app/controllers/devise_token_auth/unlocks_controller.rb +4 -4
  12. data/app/models/devise_token_auth/concerns/active_record_support.rb +16 -0
  13. data/app/models/devise_token_auth/concerns/mongoid_support.rb +19 -0
  14. data/app/models/devise_token_auth/concerns/tokens_serialization.rb +19 -0
  15. data/app/models/devise_token_auth/concerns/user.rb +44 -67
  16. data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +2 -2
  17. data/app/validators/{email_validator.rb → devise_token_auth_email_validator.rb} +1 -1
  18. data/config/locales/en.yml +5 -0
  19. data/config/locales/he.yml +50 -0
  20. data/config/locales/ja.yml +1 -1
  21. data/lib/devise_token_auth/blacklist.rb +2 -0
  22. data/lib/devise_token_auth/engine.rb +2 -0
  23. data/lib/devise_token_auth/rails/routes.rb +1 -1
  24. data/lib/devise_token_auth/token_factory.rb +126 -0
  25. data/lib/devise_token_auth/version.rb +1 -1
  26. data/lib/devise_token_auth.rb +6 -3
  27. data/lib/generators/devise_token_auth/install_generator.rb +3 -87
  28. data/lib/generators/devise_token_auth/install_generator_helpers.rb +98 -0
  29. data/lib/generators/devise_token_auth/install_mongoid_generator.rb +46 -0
  30. data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +5 -0
  31. data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +0 -7
  32. data/lib/generators/devise_token_auth/templates/user_mongoid.rb.erb +56 -0
  33. data/test/controllers/custom/custom_confirmations_controller_test.rb +1 -1
  34. data/test/controllers/demo_user_controller_test.rb +2 -2
  35. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +79 -19
  36. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +2 -0
  37. data/test/controllers/devise_token_auth/passwords_controller_test.rb +115 -94
  38. data/test/controllers/devise_token_auth/registrations_controller_test.rb +31 -4
  39. data/test/controllers/devise_token_auth/sessions_controller_test.rb +0 -38
  40. data/test/controllers/devise_token_auth/token_validations_controller_test.rb +2 -1
  41. data/test/dummy/app/{models → active_record}/scoped_user.rb +2 -2
  42. data/test/dummy/app/{models → active_record}/unconfirmable_user.rb +1 -2
  43. data/test/dummy/app/{models → active_record}/unregisterable_user.rb +3 -3
  44. data/test/dummy/app/active_record/user.rb +6 -0
  45. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +3 -3
  46. data/test/dummy/app/controllers/overrides/passwords_controller.rb +3 -3
  47. data/test/dummy/app/controllers/overrides/registrations_controller.rb +1 -1
  48. data/test/dummy/app/controllers/overrides/sessions_controller.rb +2 -2
  49. data/test/dummy/app/models/{user.rb → concerns/favorite_color.rb} +7 -8
  50. data/test/dummy/app/mongoid/lockable_user.rb +38 -0
  51. data/test/dummy/app/mongoid/mang.rb +46 -0
  52. data/test/dummy/app/mongoid/only_email_user.rb +33 -0
  53. data/test/dummy/app/mongoid/scoped_user.rb +50 -0
  54. data/test/dummy/app/mongoid/unconfirmable_user.rb +44 -0
  55. data/test/dummy/app/mongoid/unregisterable_user.rb +47 -0
  56. data/test/dummy/app/mongoid/user.rb +49 -0
  57. data/test/dummy/config/application.rb +23 -1
  58. data/test/dummy/config/boot.rb +4 -0
  59. data/test/dummy/config/initializers/devise.rb +285 -0
  60. data/test/dummy/config/initializers/devise_token_auth.rb +35 -4
  61. data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +0 -7
  62. data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +0 -7
  63. data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +0 -7
  64. data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +0 -7
  65. data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +0 -7
  66. data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +0 -7
  67. data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +0 -7
  68. data/test/dummy/db/schema.rb +1 -28
  69. data/test/factories/users.rb +1 -1
  70. data/test/lib/devise_token_auth/blacklist_test.rb +11 -0
  71. data/test/lib/devise_token_auth/token_factory_test.rb +191 -0
  72. data/test/lib/generators/devise_token_auth/install_generator_test.rb +51 -31
  73. data/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb +51 -31
  74. data/test/models/concerns/mongoid_support_test.rb +31 -0
  75. data/test/models/concerns/tokens_serialization_test.rb +70 -0
  76. data/test/models/only_email_user_test.rb +0 -8
  77. data/test/models/user_test.rb +1 -33
  78. data/test/test_helper.rb +12 -2
  79. metadata +105 -25
  80. data/config/initializers/devise.rb +0 -198
  81. /data/test/dummy/app/{models → active_record}/lockable_user.rb +0 -0
  82. /data/test/dummy/app/{models → active_record}/mang.rb +0 -0
  83. /data/test/dummy/app/{models → active_record}/only_email_user.rb +0 -0
@@ -30,40 +30,37 @@ module DeviseTokenAuth
30
30
  # if whitelist is set, validate redirect_url against whitelist
31
31
  return render_create_error_redirect_url_not_allowed if blacklisted_redirect_url?
32
32
 
33
- begin
34
- # override email confirmation, must be sent manually from ctrl
35
- resource_class.set_callback('create', :after, :send_on_create_confirmation_instructions)
36
- resource_class.skip_callback('create', :after, :send_on_create_confirmation_instructions)
37
-
38
- if @resource.respond_to? :skip_confirmation_notification!
39
- # Fix duplicate e-mails by disabling Devise confirmation e-mail
40
- @resource.skip_confirmation_notification!
41
- end
33
+ # override email confirmation, must be sent manually from ctrl
34
+ resource_class.set_callback('create', :after, :send_on_create_confirmation_instructions)
35
+ resource_class.skip_callback('create', :after, :send_on_create_confirmation_instructions)
42
36
 
43
- if @resource.save
44
- yield @resource if block_given?
37
+ if @resource.respond_to? :skip_confirmation_notification!
38
+ # Fix duplicate e-mails by disabling Devise confirmation e-mail
39
+ @resource.skip_confirmation_notification!
40
+ end
45
41
 
46
- if @resource.confirmed?
47
- # email auth has been bypassed, authenticate user
48
- @client_id, @token = @resource.create_token
49
- @resource.save!
50
- update_auth_header
51
- else
52
- # user will require email authentication
53
- @resource.send_confirmation_instructions(
54
- client_config: params[:config_name],
55
- redirect_url: @redirect_url
56
- )
57
- end
58
-
59
- render_create_success
60
- else
61
- clean_up_passwords @resource
62
- render_create_error
42
+ if @resource.save
43
+ yield @resource if block_given?
44
+
45
+ unless @resource.confirmed?
46
+ # user will require email authentication
47
+ @resource.send_confirmation_instructions({
48
+ client_config: params[:config_name],
49
+ redirect_url: @redirect_url
50
+ })
51
+ end
52
+
53
+ if active_for_authentication?
54
+ # email auth has been bypassed, authenticate user
55
+ @token = @resource.create_token
56
+ @resource.save!
57
+ update_auth_header
63
58
  end
64
- rescue ActiveRecord::RecordNotUnique
59
+
60
+ render_create_success
61
+ else
65
62
  clean_up_passwords @resource
66
- render_create_error_email_already_exists
63
+ render_create_error
67
64
  end
68
65
  end
69
66
 
@@ -145,15 +142,6 @@ module DeviseTokenAuth
145
142
  }, status: 422
146
143
  end
147
144
 
148
- def render_create_error_email_already_exists
149
- response = {
150
- status: 'error',
151
- data: resource_data
152
- }
153
- message = I18n.t('devise_token_auth.registrations.email_already_exists', email: @resource.email)
154
- render_error(422, message, response)
155
- end
156
-
157
145
  def render_update_success
158
146
  render json: {
159
147
  status: 'success',
@@ -193,7 +181,7 @@ module DeviseTokenAuth
193
181
  elsif account_update_params.key?(:current_password)
194
182
  'update_with_password'
195
183
  else
196
- 'update_attributes'
184
+ 'update'
197
185
  end
198
186
  end
199
187
 
@@ -208,5 +196,9 @@ module DeviseTokenAuth
208
196
  def validate_post_data which, message
209
197
  render_error(:unprocessable_entity, message, status: 'error') if which.empty?
210
198
  end
199
+
200
+ def active_for_authentication?
201
+ !@resource.respond_to?(:active_for_authentication?) || @resource.active_for_authentication?
202
+ end
211
203
  end
212
204
  end
@@ -26,7 +26,7 @@ module DeviseTokenAuth
26
26
  if (@resource.respond_to?(:valid_for_authentication?) && !@resource.valid_for_authentication? { valid_password }) || !valid_password
27
27
  return render_create_error_bad_credentials
28
28
  end
29
- @client_id, @token = @resource.create_token
29
+ @token = @resource.create_token
30
30
  @resource.save
31
31
 
32
32
  sign_in(:user, @resource, store: false, bypass: false)
@@ -48,11 +48,11 @@ module DeviseTokenAuth
48
48
  def destroy
49
49
  # remove auth instance variables so that after_action does not run
50
50
  user = remove_instance_variable(:@resource) if @resource
51
- client_id = remove_instance_variable(:@client_id) if @client_id
52
- remove_instance_variable(:@token) if @token
51
+ client = @token.client if @token.client
52
+ @token.clear!
53
53
 
54
- if user && client_id && user.tokens[client_id]
55
- user.tokens.delete(client_id)
54
+ if user && client && user.tokens[client]
55
+ user.tokens.delete(client)
56
56
  user.save!
57
57
 
58
58
  yield user if block_given?
@@ -34,14 +34,14 @@ module DeviseTokenAuth
34
34
  def show
35
35
  @resource = resource_class.unlock_access_by_token(params[:unlock_token])
36
36
 
37
- if @resource && @resource.id
38
- client_id, token = @resource.create_token
37
+ if @resource.persisted?
38
+ token = @resource.create_token
39
39
  @resource.save!
40
40
  yield @resource if block_given?
41
41
 
42
42
  redirect_header_options = { unlock: true }
43
- redirect_headers = build_redirect_headers(token,
44
- client_id,
43
+ redirect_headers = build_redirect_headers(token.token,
44
+ token.client,
45
45
  redirect_header_options)
46
46
  redirect_to(@resource.build_auth_url(after_unlock_path_for(@resource),
47
47
  redirect_headers))
@@ -0,0 +1,16 @@
1
+ require_relative 'tokens_serialization'
2
+
3
+ module DeviseTokenAuth::Concerns::ActiveRecordSupport
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ serialize :tokens, DeviseTokenAuth::TokensSerialization
8
+ end
9
+
10
+ class_methods do
11
+ # It's abstract replacement .find_by
12
+ def dta_find_by(attrs = {})
13
+ find_by(attrs)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module DeviseTokenAuth::Concerns::MongoidSupport
2
+ extend ActiveSupport::Concern
3
+
4
+ def as_json(options = {})
5
+ options[:except] = (options[:except] || []) + [:_id]
6
+ hash = super(options)
7
+ hash['id'] = to_param
8
+ hash
9
+ end
10
+
11
+ class_methods do
12
+ # It's abstract replacement .find_by
13
+ def dta_find_by(attrs = {})
14
+ find_by(attrs)
15
+ rescue Mongoid::Errors::DocumentNotFound
16
+ nil
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module DeviseTokenAuth::TokensSerialization
2
+ # Serialization hash to json
3
+ def self.dump(object)
4
+ object.each_value(&:compact!) unless object.nil?
5
+ JSON.generate(object)
6
+ end
7
+
8
+ # Deserialization json to hash
9
+ def self.load(json)
10
+ case json
11
+ when String
12
+ JSON.parse(json)
13
+ when NilClass
14
+ {}
15
+ else
16
+ json
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bcrypt'
4
-
5
3
  module DeviseTokenAuth::Concerns::User
6
4
  extend ActiveSupport::Concern
7
5
 
@@ -9,7 +7,7 @@ module DeviseTokenAuth::Concerns::User
9
7
  @token_equality_cache ||= {}
10
8
 
11
9
  key = "#{token_hash}/#{token}"
12
- result = @token_equality_cache[key] ||= (::BCrypt::Password.new(token_hash) == token)
10
+ result = @token_equality_cache[key] ||= DeviseTokenAuth::TokenFactory.token_hash_is_token?(token_hash, token)
13
11
  @token_equality_cache = {} if @token_equality_cache.size > 10000
14
12
  result
15
13
  end
@@ -20,19 +18,21 @@ module DeviseTokenAuth::Concerns::User
20
18
  devise_modules.delete(:omniauthable)
21
19
  else
22
20
  devise :database_authenticatable, :registerable,
23
- :recoverable, :trackable, :validatable, :confirmable
21
+ :recoverable, :validatable, :confirmable
24
22
  end
25
23
 
26
- serialize :tokens, JSON unless tokens_has_json_column_type?
24
+ if const_defined?('ActiveRecord') && ancestors.include?(ActiveRecord::Base)
25
+ include DeviseTokenAuth::Concerns::ActiveRecordSupport
26
+ end
27
+
28
+ if const_defined?('Mongoid') && ancestors.include?(Mongoid::Document)
29
+ include DeviseTokenAuth::Concerns::MongoidSupport
30
+ end
27
31
 
28
32
  if DeviseTokenAuth.default_callbacks
29
33
  include DeviseTokenAuth::Concerns::UserOmniauthCallbacks
30
34
  end
31
35
 
32
- # can't set default on text fields in mysql, simulate here instead.
33
- after_save :set_empty_token_hash
34
- after_initialize :set_empty_token_hash
35
-
36
36
  # get rid of dead tokens
37
37
  before_save :destroy_expired_tokens
38
38
 
@@ -84,39 +84,25 @@ module DeviseTokenAuth::Concerns::User
84
84
  send_devise_notification(:unlock_instructions, raw, opts)
85
85
  raw
86
86
  end
87
- end
88
-
89
- def create_token(client_id: nil, token: nil, expiry: nil, **token_extras)
90
- client_id ||= SecureRandom.urlsafe_base64(nil, false)
91
- token ||= SecureRandom.urlsafe_base64(nil, false)
92
- expiry ||= (Time.zone.now + token_lifespan).to_i
93
87
 
94
- tokens[client_id] = {
95
- token: BCrypt::Password.create(token),
96
- expiry: expiry
97
- }.merge!(token_extras)
88
+ def create_token(client: nil, lifespan: nil, cost: nil, **token_extras)
89
+ token = DeviseTokenAuth::TokenFactory.create(client: client, lifespan: lifespan, cost: cost)
98
90
 
99
- clean_old_tokens
91
+ tokens[token.client] = {
92
+ token: token.token_hash,
93
+ expiry: token.expiry
94
+ }.merge!(token_extras)
100
95
 
101
- [client_id, token, expiry]
102
- end
96
+ clean_old_tokens
103
97
 
104
- module ClassMethods
105
- protected
106
-
107
- def tokens_has_json_column_type?
108
- database_exists? && table_exists? && columns_hash['tokens'] && columns_hash['tokens'].type.in?([:json, :jsonb])
109
- end
110
-
111
- def database_exists?
112
- ActiveRecord::Base.connection_pool.with_connection { |con| con.active? } rescue false
98
+ token
113
99
  end
114
100
  end
115
101
 
116
- def valid_token?(token, client_id = 'default')
117
- return false unless tokens[client_id]
118
- return true if token_is_current?(token, client_id)
119
- return true if token_can_be_reused?(token, client_id)
102
+ def valid_token?(token, client = 'default')
103
+ return false unless tokens[client]
104
+ return true if token_is_current?(token, client)
105
+ return true if token_can_be_reused?(token, client)
120
106
 
121
107
  # return false if none of the above conditions are met
122
108
  false
@@ -126,10 +112,10 @@ module DeviseTokenAuth::Concerns::User
126
112
  # can be passed on from the client
127
113
  def send_confirmation_notification?; false; end
128
114
 
129
- def token_is_current?(token, client_id)
115
+ def token_is_current?(token, client)
130
116
  # ghetto HashWithIndifferentAccess
131
- expiry = tokens[client_id]['expiry'] || tokens[client_id][:expiry]
132
- token_hash = tokens[client_id]['token'] || tokens[client_id][:token]
117
+ expiry = tokens[client]['expiry'] || tokens[client][:expiry]
118
+ token_hash = tokens[client]['token'] || tokens[client][:token]
133
119
 
134
120
  return true if (
135
121
  # ensure that expiry and token are set
@@ -144,53 +130,52 @@ module DeviseTokenAuth::Concerns::User
144
130
  end
145
131
 
146
132
  # allow batch requests to use the previous token
147
- def token_can_be_reused?(token, client_id)
133
+ def token_can_be_reused?(token, client)
148
134
  # ghetto HashWithIndifferentAccess
149
- updated_at = tokens[client_id]['updated_at'] || tokens[client_id][:updated_at]
150
- last_token = tokens[client_id]['last_token'] || tokens[client_id][:last_token]
135
+ updated_at = tokens[client]['updated_at'] || tokens[client][:updated_at]
136
+ last_token = tokens[client]['last_token'] || tokens[client][:last_token]
151
137
 
152
138
  return true if (
153
139
  # ensure that the last token and its creation time exist
154
140
  updated_at && last_token &&
155
141
 
156
142
  # ensure that previous token falls within the batch buffer throttle time of the last request
157
- Time.parse(updated_at) > Time.zone.now - DeviseTokenAuth.batch_request_buffer_throttle &&
143
+ updated_at.to_time > Time.zone.now - DeviseTokenAuth.batch_request_buffer_throttle &&
158
144
 
159
145
  # ensure that the token is valid
160
- ::BCrypt::Password.new(last_token) == token
146
+ DeviseTokenAuth::TokenFactory.valid_token_hash?(last_token)
161
147
  )
162
148
  end
163
149
 
164
150
  # update user's auth token (should happen on each request)
165
- def create_new_auth_token(client_id = nil)
151
+ def create_new_auth_token(client = nil)
166
152
  now = Time.zone.now
167
153
 
168
- client_id, token = create_token(
169
- client_id: client_id,
170
- expiry: (now + token_lifespan).to_i,
171
- last_token: tokens.fetch(client_id, {})['token'],
154
+ token = create_token(
155
+ client: client,
156
+ last_token: tokens.fetch(client, {})['token'],
172
157
  updated_at: now
173
158
  )
174
159
 
175
- update_auth_header(token, client_id)
160
+ update_auth_header(token.token, token.client)
176
161
  end
177
162
 
178
- def build_auth_header(token, client_id = 'default')
163
+ def build_auth_header(token, client = 'default')
179
164
  # client may use expiry to prevent validation request if expired
180
165
  # must be cast as string or headers will break
181
- expiry = tokens[client_id]['expiry'] || tokens[client_id][:expiry]
166
+ expiry = tokens[client]['expiry'] || tokens[client][:expiry]
182
167
 
183
168
  {
184
169
  DeviseTokenAuth.headers_names[:"access-token"] => token,
185
170
  DeviseTokenAuth.headers_names[:"token-type"] => 'Bearer',
186
- DeviseTokenAuth.headers_names[:"client"] => client_id,
171
+ DeviseTokenAuth.headers_names[:"client"] => client,
187
172
  DeviseTokenAuth.headers_names[:"expiry"] => expiry.to_s,
188
173
  DeviseTokenAuth.headers_names[:"uid"] => uid
189
174
  }
190
175
  end
191
176
 
192
- def update_auth_header(token, client_id = 'default')
193
- headers = build_auth_header(token, client_id)
177
+ def update_auth_header(token, client = 'default')
178
+ headers = build_auth_header(token, client)
194
179
  clean_old_tokens
195
180
  save!
196
181
 
@@ -204,9 +189,9 @@ module DeviseTokenAuth::Concerns::User
204
189
  DeviseTokenAuth::Url.generate(base_url, args)
205
190
  end
206
191
 
207
- def extend_batch_buffer(token, client_id)
208
- tokens[client_id]['updated_at'] = Time.zone.now
209
- update_auth_header(token, client_id)
192
+ def extend_batch_buffer(token, client)
193
+ tokens[client]['updated_at'] = Time.zone.now
194
+ update_auth_header(token, client)
210
195
  end
211
196
 
212
197
  def confirmed?
@@ -217,16 +202,8 @@ module DeviseTokenAuth::Concerns::User
217
202
  as_json(except: %i[tokens created_at updated_at])
218
203
  end
219
204
 
220
- def token_lifespan
221
- DeviseTokenAuth.token_lifespan
222
- end
223
-
224
205
  protected
225
206
 
226
- def set_empty_token_hash
227
- self.tokens ||= {} if has_attribute?(:tokens)
228
- end
229
-
230
207
  def destroy_expired_tokens
231
208
  if tokens
232
209
  tokens.delete_if do |cid, v|
@@ -250,8 +227,8 @@ module DeviseTokenAuth::Concerns::User
250
227
  return unless should_remove_tokens_after_password_reset?
251
228
 
252
229
  if tokens.present? && tokens.many?
253
- client_id, token_data = tokens.max_by { |cid, v| v[:expiry] || v['expiry'] }
254
- self.tokens = { client_id => token_data }
230
+ client, token_data = tokens.max_by { |cid, v| v[:expiry] || v['expiry'] }
231
+ self.tokens = { client => token_data }
255
232
  end
256
233
  end
257
234
 
@@ -5,7 +5,7 @@ module DeviseTokenAuth::Concerns::UserOmniauthCallbacks
5
5
 
6
6
  included do
7
7
  validates :email, presence: true,if: :email_provider?
8
- validates :email, email: true, allow_nil: true, allow_blank: true, if: :email_provider?
8
+ validates :email, :devise_token_auth_email => true, allow_nil: true, allow_blank: true, if: :email_provider?
9
9
  validates_presence_of :uid, unless: :email_provider?
10
10
 
11
11
  # only validate unique emails among email registration users
@@ -23,6 +23,6 @@ module DeviseTokenAuth::Concerns::UserOmniauthCallbacks
23
23
  end
24
24
 
25
25
  def sync_uid
26
- self.uid = email if provider == 'email'
26
+ self.uid = email if email_provider?
27
27
  end
28
28
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class EmailValidator < ActiveModel::EachValidator
3
+ class DeviseTokenAuthEmailValidator < ActiveModel::EachValidator
4
4
  def validate_each(record, attribute, value)
5
5
  unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
6
6
  record.errors[attribute] << email_invalid_message
@@ -27,6 +27,11 @@ en:
27
27
  missing_email: "You must provide an email address."
28
28
  sended: "An email has been sent to '%{email}' containing instructions for unlocking your account."
29
29
  user_not_found: "Unable to find user with email '%{email}'."
30
+ confirmations:
31
+ sended: "An email has been sent to '%{email}' containing instructions for confirming your account."
32
+ user_not_found: "Unable to find user with email '%{email}'."
33
+ missing_email: "You must provide an email address."
34
+
30
35
  errors:
31
36
  messages:
32
37
  validate_sign_up_params: "Please submit proper sign up data in request body."
@@ -0,0 +1,50 @@
1
+ he:
2
+ devise_token_auth:
3
+ sessions:
4
+ not_confirmed: "הודעת אישור נשלחה לחשבון שלך בכתובת '%{email}'. עליך לפעול לפי ההנחיות שבדוא\"ל לפני הפעלת החשבון שלך"
5
+ bad_credentials: "נתוני כניסה שגויים. בבקשה נסה שוב."
6
+ not_supported: "השתמש ב- POST / sign_in כדי להיכנס. GET אינו נתמך."
7
+ user_not_found: "המשתמש לא נמצא או לא היה מחובר."
8
+ token_validations:
9
+ invalid: "נתוני כניסה שגויים"
10
+ registrations:
11
+ missing_confirm_success_url: "חסר פרמטר 'confirm_success_url'."
12
+ redirect_url_not_allowed: "הפניה אל '%{redirect_url}' אינה מותרת."
13
+ email_already_exists: "כבר קיים חשבון עבור '%{email}'"
14
+ account_with_uid_destroyed: "חשבון עם UID '%{uid}' הושמד."
15
+ account_to_destroy_not_found: "לא ניתן לאתר חשבון להשמדה."
16
+ user_not_found: "המשתמש לא נמצא."
17
+ passwords:
18
+ missing_email: "עליך לספק כתובת דוא\"ל."
19
+ missing_redirect_url: "כתובת אתר להפניה מחדש חסרה."
20
+ not_allowed_redirect_url: "הפניה אל '%{redirect_url}' אינה מותרת."
21
+ sended: "אימייל נשלח ל '%{email}' המכיל הוראות לאיפוס הסיסמה שלך."
22
+ user_not_found: "לא ניתן למצוא משתמש עם הדוא\"ל '%{email}'."
23
+ password_not_required: "חשבון זה אינו דורש סיסמה. במקום זאת, השתמש בחשבון '%{provider}' שלך."
24
+ missing_passwords: "עליך למלא את השדות 'סיסמה' ו'אישור סיסמה'."
25
+ successfully_updated: "הסיסמה שלך עודכנה בהצלחה."
26
+ unlocks:
27
+ missing_email: "עליך לספק כתובת דוא\"ל."
28
+ sended: "הודעת אימייל נשלחה אל '%{email}' המכילה הוראות לביטול הנעילה של חשבונך."
29
+ user_not_found: "ניתן למצוא את המשתמש עם הדוא\"ל '%{email}'"
30
+ errors:
31
+ messages:
32
+ validate_sign_up_params: "שלח נתוני רישום תקינים בגוף הבקשה."
33
+ validate_account_update_params: "שלחו בבקשה נתוני עדכון חשבון תקינים בגוף הבקשה."
34
+ not_email: "אינו דוא\"ל"
35
+ devise:
36
+ mailer:
37
+ confirmation_instructions:
38
+ confirm_link_msg: "תוכל לאשר את כתובת הדוא\"ל של החשבון שלך באמצעות הקישור הבא:"
39
+ confirm_account_link: "אשר את החשבון שלי"
40
+ reset_password_instructions:
41
+ request_reset_link_msg: "מישהו ביקש קישור לשינוי הסיסמה שלך. תוכל לעשות זאת באמצעות הקישור הבא."
42
+ password_change_link: "שנה את הסיסמה שלי"
43
+ ignore_mail_msg: "אם לא ביקשת זאת, התעלם מדוא\"ל זה."
44
+ no_changes_msg: "הסיסמה שלך לא תשתנה עד שתגיע לקישור שלמעלה ותיצור סיסמה חדשה."
45
+ unlock_instructions:
46
+ account_lock_msg: "החשבון שלך ננעל עקב מספר מופרז של ניסיונות כניסה לא מוצלחים."
47
+ unlock_link_msg: "לחץ על הקישור למטה כדי לבטל את נעילת החשבון שלך:"
48
+ unlock_link: "בטל את הנעילה של החשבון שלי"
49
+ hello: "שלום"
50
+ welcome: "ברוך הבא"
@@ -34,7 +34,7 @@ ja:
34
34
  confirm_link_msg: "下記のリンクからアカウントを有効化できます:"
35
35
  confirm_account_link: "アカウントを有効化する"
36
36
  reset_password_instructions:
37
- request_reset_link_msg: "パスワード変更のリクエストが送信されました。下記のリンクからパスワードの変更をできます。"
37
+ request_reset_link_msg: "パスワード変更のリクエストが送信されました。下記のリンクからパスワードの変更ができます。"
38
38
  password_change_link: "パスワードを変更する"
39
39
  ignore_mail_msg: "もしこの内容に覚えがない場合は、このメールを無視してください。"
40
40
  no_changes_msg: "上記のリンクにアクセスして新しいパスワードを作成するまで、現在のパスワードは変更されません。"
@@ -0,0 +1,2 @@
1
+ # don't serialize tokens
2
+ Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION << :tokens
@@ -14,6 +14,7 @@ module DeviseTokenAuth
14
14
  mattr_accessor :change_headers_on_each_request,
15
15
  :max_number_of_devices,
16
16
  :token_lifespan,
17
+ :token_cost,
17
18
  :batch_request_buffer_throttle,
18
19
  :omniauth_prefix,
19
20
  :default_confirm_success_url,
@@ -29,6 +30,7 @@ module DeviseTokenAuth
29
30
  self.change_headers_on_each_request = true
30
31
  self.max_number_of_devices = 10
31
32
  self.token_lifespan = 2.weeks
33
+ self.token_cost = 10
32
34
  self.batch_request_buffer_throttle = 5.seconds
33
35
  self.omniauth_prefix = '/omniauth'
34
36
  self.default_confirm_success_url = nil
@@ -56,7 +56,7 @@ module ActionDispatch::Routing
56
56
 
57
57
  devise_scope mapping_name.to_sym do
58
58
  # path to verify token validity
59
- get "#{full_path}/validate_token", controller: token_validations_ctrl.to_s, action: 'validate_token'
59
+ get "#{full_path}/validate_token", controller: token_validations_ctrl.to_s, action: 'validate_token' if !opts[:skip].include?(:token_validations)
60
60
 
61
61
  # omniauth routes. only define if omniauth is installed and not skipped.
62
62
  if defined?(::OmniAuth) && !opts[:skip].include?(:omniauth_callbacks)