2009-05-22 16:14:07 +02:00
|
|
|
class User < ActiveRecord::Base
|
2012-07-24 23:26:16 +02:00
|
|
|
devise :database_authenticatable, :registerable, :confirmable, :token_authenticatable,
|
|
|
|
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :lockable
|
|
|
|
|
|
|
|
attr_accessible :id, :name, :second_name, :surname, :email, :password, :password_confirmation, :remember_me, :userpic
|
|
|
|
|
2012-07-26 22:26:23 +02:00
|
|
|
ajaxful_rater
|
|
|
|
|
2012-07-24 23:26:16 +02:00
|
|
|
mount_uploader :userpic, UserpicUploader
|
|
|
|
|
|
|
|
has_and_belongs_to_many :roles
|
|
|
|
|
|
|
|
def small_url
|
|
|
|
userpic.url(:small)
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :avatar, :small_url
|
|
|
|
|
|
|
|
def thumb_url
|
|
|
|
userpic.url(:thumb)
|
|
|
|
end
|
|
|
|
|
|
|
|
def original_url
|
|
|
|
userpic.url(:original)
|
|
|
|
end
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
# This hack is needed to access the current user in models.
|
|
|
|
#See http://rails-bestpractices.com/posts/47-fetch-current-user-in-models
|
|
|
|
def self.current
|
|
|
|
Thread.current[:user]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.current=(user)
|
|
|
|
Thread.current[:user] = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.admin_created?
|
|
|
|
User.admin.count > 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_role?(role_in_question)
|
|
|
|
roles.any? { |role| role.name == role_in_question.to_s }
|
|
|
|
end
|
2009-05-22 16:14:07 +02:00
|
|
|
end
|