Module: Devise::Models::SmsActivable::ClassMethods

Defined in:
lib/models/sms_activable.rb

Instance Method Summary collapse

Instance Method Details

#confirm_by_sms_token(sms_confirmation_token) ⇒ Object

Find a user by it’s sms 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 sms_confirmation_token



155
156
157
158
159
# File 'lib/models/sms_activable.rb', line 155

def confirm_by_sms_token(sms_confirmation_token)
  sms_confirmable = find_or_initialize_with_error_by(:sms_confirmation_token, sms_confirmation_token)
  sms_confirmable.confirm_sms! if sms_confirmable.persisted?
  sms_confirmable
end

#generate_small_token(column) ⇒ Object

Generates a small token that can be used conveniently on SMS’s. The token is 5 chars long and uppercased.



164
165
166
167
168
169
# File 'lib/models/sms_activable.rb', line 164

def generate_small_token(column)
  loop do
    token = Devise.friendly_token[0,5].upcase
    break token unless to_adapter.find_first({ column => token })
  end
end

#send_sms_token(attributes = {}) ⇒ Object

Attempt to find a user by it’s email. If a record is found, send a new sms token instructions to it. If not user is found, returns a new user with an email not found error. Options must contain the user email



145
146
147
148
149
# File 'lib/models/sms_activable.rb', line 145

def send_sms_token(attributes={})
  sms_confirmable = find_or_initialize_with_errors(sms_confirmation_keys, attributes, :not_found)
  sms_confirmable.resend_sms_token if sms_confirmable.persisted?
  sms_confirmable
end

#sms_confirmation_tokenObject

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



172
173
174
# File 'lib/models/sms_activable.rb', line 172

def sms_confirmation_token
  generate_small_token(:sms_confirmation_token)
end