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