Module: Concerns::ModelActivation::ClassMethods

Includes:
Pillowfort::ModelFinder, Pillowfort::TokenGenerator
Defined in:
app/models/pillowfort/concerns/model_activation.rb

Instance Method Summary collapse

Methods included from Pillowfort::ModelFinder

#find_by_email_case_insensitive

Methods included from Pillowfort::TokenGenerator

#friendly_token, #secure_compare

Instance Method Details

#find_and_activate(email, token) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/pillowfort/concerns/model_activation.rb', line 66

def find_and_activate(email, token)
  return false if email.blank? || token.blank?

  transaction do
    if resource = find_by_email_case_insensitive(email)
      if resource.activation_token_expired?
        return false
      else
        if secure_compare(resource.activation_token, token)
          resource.activate!
          yield resource if block_given?
        end
      end
    end
  end
end