Module: Authentasaurus::Models::Session::InstanceMethods
- Defined in:
- lib/authentasaurus/models/session.rb
Instance Method Summary collapse
-
#initialize(attributes = nil) ⇒ Object
Takes a hash of attributes keys and values just like ActiveRecord models.
-
#new_record? ⇒ Boolean
:nodoc:.
-
#save(*session_types) ⇒ Object
Authenticates the information saved in the attributes Returns true or false.
Instance Method Details
#initialize(attributes = nil) ⇒ Object
Takes a hash of attributes keys and values just like ActiveRecord models
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/authentasaurus/models/session.rb', line 33 def initialize(attributes = nil) self.errors = ActiveRecord::Errors.new(self) if attributes attributes.each do |key,value| send(key.to_s + '=', value) end else self.remember = false end end |
#new_record? ⇒ Boolean
:nodoc:
67 68 69 |
# File 'lib/authentasaurus/models/session.rb', line 67 def new_record? #:nodoc: true end |
#save(*session_types) ⇒ Object
Authenticates the information saved in the attributes Returns true or false
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/authentasaurus/models/session.rb', line 46 def save(*session_types) session_types = session_types.flatten if session_types.empty? session_types = [:user] end ret = true session_types.each do |type| @user = type.to_s.camelize.constantize.authenticate(self.username.downcase, self.password, self.remember == "1") if @user.nil? self.errors.add_to_base I18n.t(:invalid_login, :scope => [:authentasaurus, :messages, :sessions]) ret &= false else ret = true break end end ret end |