Sha256: 13e59c0633c88107efd161bbb1cd64da5488fb59c99db087dfeb044abc956018

Contents?: true

Size: 1.42 KB

Versions: 29

Compression:

Stored size: 1.42 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:
  # :token_authenticatable, :encryptable, :confirmable, :lockable and :omniauthable
  devise :database_authenticatable, :registerable, :timeoutable,
         :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['info'].blank?
      self.email = omniauth['info']['email'] if email.blank?
      self.first_name = omniauth['info']['first_name'] if first_name.blank?
      self.last_name = omniauth['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

29 entries across 29 versions & 1 rubygems

Version Path
contour-1.1.0.rc2 test/dummy/app/models/user.rb
contour-1.1.0.rc test/dummy/app/models/user.rb
contour-1.0.5 test/dummy/app/models/user.rb
contour-1.1.0.pre2 test/dummy/app/models/user.rb
contour-1.1.0.pre test/dummy/app/models/user.rb
contour-1.0.4 test/dummy/app/models/user.rb
contour-1.0.3 test/dummy/app/models/user.rb
contour-1.0.2 test/dummy/app/models/user.rb
contour-1.0.1 test/dummy/app/models/user.rb
contour-1.0.0 test/dummy/app/models/user.rb
contour-1.0.0.rc2 test/dummy/app/models/user.rb
contour-1.0.0.rc test/dummy/app/models/user.rb
contour-1.0.0.beta12 test/dummy/app/models/user.rb
contour-1.0.0.beta11 test/dummy/app/models/user.rb
contour-1.0.0.beta10 test/dummy/app/models/user.rb
contour-1.0.0.beta9 test/dummy/app/models/user.rb
contour-1.0.0.beta8 test/dummy/app/models/user.rb
contour-1.0.0.beta7 test/dummy/app/models/user.rb
contour-1.0.0.beta6 test/dummy/app/models/user.rb
contour-1.0.0.beta5 test/dummy/app/models/user.rb