Sha256: c052e5dc89a7081069dc9b5c967082be0aebb92e0b8c9906dbee16fc98c3fca3

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 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, :google_oauth2]

  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

4 entries across 4 versions & 1 rubygems

Version Path
tawork-0.0.50 app/models/user.rb
tawork-0.0.49 app/models/user.rb
tawork-0.0.48 app/models/user.rb
tawork-0.0.47 app/models/user.rb