Module: Negroni::Models::Lockable::ClassMethods
- Defined in:
- lib/negroni/models/lockable.rb
Overview
Class Methods for Lockable
Instance Method Summary collapse
-
#lock_strategy_enabled?(strategy) ⇒ Boolean
If the strategy is enabled.
-
#send_unlock_instructions(attributes = {}) ⇒ Object
Attempt to find a user by its unlock keys.
-
#unlock_access_by_token(token) ⇒ Object
Find a user by its unlock token and try to unlock it.
-
#unlock_strategy_enabled?(strategy) ⇒ Boolean
Checks if a given unlock strategy is enabled.
Instance Method Details
#lock_strategy_enabled?(strategy) ⇒ Boolean
Returns if the strategy is enabled.
200 201 202 |
# File 'lib/negroni/models/lockable.rb', line 200 def lock_strategy_enabled?(strategy) lock_strategy == strategy end |
#send_unlock_instructions(attributes = {}) ⇒ Object
Attempt to find a user by its unlock keys. If a record is found, send new unlock instructions to it. If not user is found, returns a new user with an email not found error. Options must contain the user’s unlock keys Checks if a given lock strategy is enabled.
175 176 177 178 179 180 181 |
# File 'lib/negroni/models/lockable.rb', line 175 def send_unlock_instructions(attributes = {}) lockable = find_or_initialize_with_errors( unlock_keys, attributes, :not_found ) lockable.resend_unlock_instructions if lockable.persisted? lockable end |
#unlock_access_by_token(token) ⇒ Object
Find a user by its unlock token and try to unlock it. If no user is found, returns a new user with an error. If the user is not locked, creates an error for the user Options must have the unlock_token
187 188 189 190 191 192 193 194 195 |
# File 'lib/negroni/models/lockable.rb', line 187 def unlock_access_by_token(token) orig = token token = Negroni.token_generator.digest(self, :unlock_token, token) lockable = find_or_initialize_with_error_by(:unlock_token, token) lockable.unlock_access! if lockable.persisted? lockable.unlock_token = orig lockable end |
#unlock_strategy_enabled?(strategy) ⇒ Boolean
Checks if a given unlock strategy is enabled.
209 210 211 212 |
# File 'lib/negroni/models/lockable.rb', line 209 def unlock_strategy_enabled?(strategy) unlock_strategy == strategy || (unlock_strategy == :both && BOTH_STRATEGIES.include?(strategy)) end |