Sha256: ba25d9abd606812ac9edc0f28bec7b79abefee0e0d7a5592adc1525bc74655d0

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

# rails g model Authentication user_id:integer provider:string uid:string
# rails g migration CreateUsers first_name:string last_name:string

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :encryptable, :confirmable, :lockable and :omniauthable
  devise :database_authenticatable, :registerable, :timeoutable, :token_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name

  # Named Scopes
  scope :current, :conditions => { :deleted => false }
  
  # Model Relationships
  has_many :authentications
  
  def name
    first_name + ' ' + last_name
  end
  
  def reverse_name
    last_name + ', ' + first_name
  end

  # Overriding Devise built-in active? method
  def active_for_authentication?
    super # and self.status == 'active' and not self.deleted?
  end
  
  def apply_omniauth(omniauth)
    unless omniauth['user_info'].blank?
      self.email = omniauth['user_info']['email'] if email.blank?
      self.first_name = omniauth['user_info']['first_name'] if first_name.blank?
      self.last_name = omniauth['user_info']['last_name'] if last_name.blank?
    end
    authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
  end

  def password_required?
    (authentications.empty? || !password.blank?) && super
  end
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contour-0.8.3 test/dummy/app/models/user.rb
contour-0.8.2 test/dummy/app/models/user.rb
contour-0.8.1 test/dummy/app/models/user.rb
contour-0.8.0 test/dummy/app/models/user.rb
contour-0.7.2 test/dummy/app/models/user.rb
contour-0.7.1 test/dummy/app/models/user.rb
contour-0.7.0 test/dummy/app/models/user.rb