Module: Devise::Models::DateRestrictable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise_date_restrictable/active_record.rb
Overview
DateRestrictable provides the ability to restrict a user’s access by date. This can be used to limit logging in either before- or after a certain date, or outside of a given date range.
Where dates are given they are inclusive, that is:
-
if
valid_from
is specified, the user may log in after 00:00:00 on that date -
if
valid_until
is specified, the user may log in until 23:59:59 on that date
This module also provides basic validation to ensure that, where both valid_from
and valid_until
are specified, this is done in a sensible chronological order.
Class Method Summary collapse
-
.required_fields(klass) ⇒ Object
Returns an array of fields required by this module.
Instance Method Summary collapse
-
#access_locked? ⇒ Boolean
Hook into lockable: verifies whether the user is locked for any reason.
-
#active_for_authentication? ⇒ Boolean
Hook into authenticatable: verifies whether the user is available for authentication.
-
#date_restricted? ⇒ Boolean
Returns whether or not the user is currently restricted by date.
-
#inactive_message ⇒ Object
Returns an appropriate message should the user be locked out by this module.
Class Method Details
.required_fields(klass) ⇒ Object
Returns an array of fields required by this module.
34 35 36 37 38 |
# File 'lib/devise_date_restrictable/active_record.rb', line 34 def self.required_fields( klass ) %i{ valid_from, valid_until } end |
Instance Method Details
#access_locked? ⇒ Boolean
Hook into lockable: verifies whether the user is locked for any reason.
41 42 43 44 45 |
# File 'lib/devise_date_restrictable/active_record.rb', line 41 def access_locked? super && date_restricted? end |
#active_for_authentication? ⇒ Boolean
Hook into authenticatable: verifies whether the user is available for authentication.
48 49 50 51 52 |
# File 'lib/devise_date_restrictable/active_record.rb', line 48 def active_for_authentication? super && !date_restricted? end |
#date_restricted? ⇒ Boolean
Returns whether or not the user is currently restricted by date.
25 26 27 28 29 30 31 |
# File 'lib/devise_date_restrictable/active_record.rb', line 25 def date_restricted? now = Date.today !((valid_from.nil? or now >= valid_from) and (valid_until.nil? or now <= valid_until)) end |
#inactive_message ⇒ Object
Returns an appropriate message should the user be locked out by this module.
55 56 57 58 59 |
# File 'lib/devise_date_restrictable/active_record.rb', line 55 def date_restricted? ? :account_date_restricted : super end |