28 lines
627 B
Ruby
28 lines
627 B
Ruby
class User
|
|
include SimplyStored::Couch
|
|
|
|
property :name
|
|
property :active_list_id
|
|
property :admin, type: :boolean, default: false
|
|
|
|
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :token_authenticatable # , :registerable
|
|
|
|
has_and_belongs_to_many :lists, storing_keys: false
|
|
has_many :orders
|
|
|
|
validates_uniqueness_of :email
|
|
before_save :ensure_authentication_token
|
|
|
|
view :by_authentication_token, key: :authentication_token
|
|
view :by_email, key: :email
|
|
|
|
def list_is_closed!
|
|
self.active_list_id = nil
|
|
save
|
|
end
|
|
|
|
def has_active_list?
|
|
active_list_id.present?
|
|
end
|
|
end
|