Sha256: d2708e069784beef6489f6ff8b376ff165ac879a536b5ff83f7f1ec12f19ca18

Contents?: true

Size: 1023 Bytes

Versions: 3

Compression:

Stored size: 1023 Bytes

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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tawork-0.0.11 app/models/user.rb
tawork-0.0.10 app/models/user.rb
tawork-0.0.9 app/models/user.rb