lib/models/user.rb in logman-0.0.2 vs lib/models/user.rb in logman-0.1.0.alpha

- old
+ new

@@ -1,30 +1,37 @@ -module Logman +class Logman class User - include MongoMapper::Document + include Mongoid::Document + include ActiveModel::SecurePassword + store_in collection: 'logman_users' - set_collection_name 'logman_users' + attr_accessible :email, :password, :name, :admin - attr_accessible :email, :name, :admin, :password + validates_presence_of :email, :name + validates_presence_of :password, :on=> :create + validates_uniqueness_of :email + validates_format_of :email, with: /.+\@.+\..+/ - has_secure_password :validations=>false, :validations=>false + field :email, type: String + field :password_digest, type: String + field :name, type: String + field :admin, type: Boolean - key :email, String, :required=>true, :unique=>true, :format=> /.+\@.+\..+/ - key :password_digest, String #, :required=>true - key :name, String, :required=>true - key :admin, Boolean + has_secure_password # buckets that user have access def buckets - return Bucket.where if self.admin + return Bucket.all if self.admin Bucket.where(:user_ids=> self.id) end + def serializable_hash(options={}) + options[:methods] ||= [:id] options[:except] ||= [:password_digest] super(options) end \ No newline at end of file