Sha256: 69100319db060146093c396836b2dba9ab68c48e05722dc5f9c5f798aca5a6ec

Contents?: true

Size: 1.12 KB

Versions: 24

Compression:

Stored size: 1.12 KB

Contents

class User < ActiveRecord::Base
  # include Tire::Model::Search
  # include Tire::Model::Callbacks

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  devise :omniauthable, omniauth_providers: [:google_apps]

  has_many :tickets, foreign_key: 'creator_id'
  has_many :projects, foreign_key: 'creator_id', class_name: "Project"

  validates :name, presence: true

  def self.find_for_open_id(access_token, signed_in_resource = nil)
    data = access_token.info
    name = data["name"] 

    if name.blank?
      name = data["first_name"] + " " + data["last_name"]
    end

    if user = User.where(email: data["email"]).first
      user
    else
      User.create!(
        name: name,
        email: data["email"], 
        password: Devise.friendly_token[0,20]
      )
    end
  end

  def display_name
    name || username || email
  end

  def starred?(starrable)
    starred = Starred.where(user: self, starrable: starrable).first
    starred.present?
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
tawork-0.0.25 app/models/user.rb
tawork-0.0.24 app/models/user.rb
tawork-0.0.23 app/models/user.rb
tawork-0.0.22 app/models/user.rb