module Toll::Models::Authenticable

Public Instance Methods

authenticate_with_token() click to toggle source

Method to authenticate the user It only updates the token

We are making sure the user is a valid record, that's why the `save` call

# File lib/toll/models/authenticable.rb, line 32
def authenticate_with_token
  generate_authentication_token!
  save
  self
end
Also aliased as: sign_out
sign_out()

Not really convinced about the sign_out method name

update_authentication_token!() click to toggle source

Updates the record but:

  • Validations are skipped.

  • Callbacks are skipped.

  • updated_at/updated_on are not updated.

# File lib/toll/models/authenticable.rb, line 22
def update_authentication_token!
  generate_authentication_token!
  update_column(Toll.authentication_token_attribute_name, self.send(Toll.authentication_token_attribute_name))
end
update_authentication_token_without_validations() click to toggle source

Updates the record authentication but:

  • Validation is skipped.

  • Callbacks are invoked.

  • updated_at/updated_on column is updated if that column is available.

  • Updates all the attributes that are dirty in this object.

# File lib/toll/models/authenticable.rb, line 12
def update_authentication_token_without_validations
  generate_authentication_token!
  update_attribute(Toll.authentication_token_attribute_name, self.send(Toll.authentication_token_attribute_name))
end

Private Instance Methods

ensure_authentication_token!() click to toggle source
# File lib/toll/models/authenticable.rb, line 49
def ensure_authentication_token!
  generate_authentication_token!
end
generate_authentication_token!() click to toggle source
# File lib/toll/models/authenticable.rb, line 43
def generate_authentication_token!
  begin
    self.send("#{Toll.authentication_token_attribute_name}=", Toll.token)
  end while self.class.exists?(Toll.authentication_token_attribute_name => self.send(Toll.authentication_token_attribute_name))
end