Module: Devise::Models::Confirmable::ClassMethods

Defined in:
lib/devise/models/confirmable.rb

Instance Method Summary collapse

Instance Method Details

#confirm_by_token(confirmation_token) ⇒ Object

Find a user by its confirmation token and try to confirm it. If no user is found, returns a new user with an error. If the user is already confirmed, create an error for the user Options must have the confirmation_token



245
246
247
248
249
# File 'lib/devise/models/confirmable.rb', line 245

def confirm_by_token(confirmation_token)
  confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
  confirmable.confirm! if confirmable.persisted?
  confirmable
end

#confirmation_tokenObject

Generate a token checking if one does not already exist in the database.



252
253
254
# File 'lib/devise/models/confirmable.rb', line 252

def confirmation_token
  generate_token(:confirmation_token)
end

#find_by_unconfirmed_attribute_with_errors(attributes = {}) ⇒ Object

Find a record for confirmation by unconfirmed attribute field



257
258
259
260
261
262
# File 'lib/devise/models/confirmable.rb', line 257

def find_by_unconfirmed_attribute_with_errors(attributes = {})
  unconfirmed_required_attributes = confirmation_keys.map { |k| k == confirmable_attribute ? unconfirmed_attribute : k }
  unconfirmed_attributes = attributes.symbolize_keys
  unconfirmed_attributes[unconfirmed_attribute] = unconfirmed_attributes.delete(confirmable_attribute)
  find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)
end

#send_confirmation_instructions(attributes = {}) ⇒ Object

Attempt to find a user by its attributes. If a record is found, send new confirmation instructions to it. If not, try searching for a user by unconfirmed_attribute field. If no user is found, returns a new user with a not found error. Options must contain the confirmable_attribute



232
233
234
235
236
237
238
239
# File 'lib/devise/models/confirmable.rb', line 232

def send_confirmation_instructions(attributes={})
  confirmable = find_by_unconfirmed_attribute_with_errors(attributes) if reconfirmable
  unless confirmable.try(:persisted?)
    confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
  end
  confirmable.resend_confirmation_token if confirmable.persisted?
  confirmable
end