vidpush/app/models/user.rb

29 lines
737 B
Ruby
Raw Normal View History

2014-04-08 19:27:38 +00:00
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
# before_save :ensure_authentication_token
2014-04-08 19:27:38 +00:00
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
2014-04-15 17:04:58 +00:00
before_save :ensure_authentication_token
def ensure_authentication_token
if authentication_token.blank?
self.authentication_token = generate_authentication_token
end
end
def generate_authentication_token
loop do
token = Devise.friendly_token
break token unless User.where(authentication_token: token).first
end
end
2014-05-14 18:01:19 +00:00
def is_admin?
Admin.exists?(email: self.email)
end
2014-04-08 19:27:38 +00:00
end