app/models/user.rb in spree_auth-0.40.4 vs app/models/user.rb in spree_auth-0.50.0

- old
+ new

@@ -12,10 +12,13 @@ before_validation :set_login # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :persistence_token + scope :admin, lambda { includes(:roles).where("roles.name" => "admin") } + scope :registered, where("users.email NOT LIKE ?", "%@example.net") + # has_role? simply needs to return true or false whether a user has a role or not. def has_role?(role_in_question) roles.any? { |role| role.name == role_in_question.to_s } end @@ -26,11 +29,11 @@ token = User.generate_token(:persistence_token) User.create(:email => "#{token}@example.net", :password => token, :password_confirmation => token, :persistence_token => token) end def self.admin_created? - Role.where(:name => "admin").includes(:users).count > 0 + User.admin.count > 0 end def anonymous? email =~ /@example.net$/ end @@ -67,8 +70,16 @@ def self.generate_token(column) loop do token = friendly_token break token unless find(:first, :conditions => { column => token }) end + end + + def self.current + Thread.current[:user] + end + + def self.current=(user) + Thread.current[:user] = user end end