class User include SimplyStored::Couch property :name property :active_list_id property :admin, type: :boolean, default: false #FACEBOOK property :provider property :uid property :oauth_token property :oauth_expires_at property :auth_data devise :database_authenticatable, :recoverable, :rememberable, :trackable, :token_authenticatable, :omniauthable, :omniauth_providers => [:facebook] # , :registerable property :authentication_token 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 view :by_facebook, key: [:provider, :uid] def self.find_for_facebook_oauth(auth_data, user) user = database.view(self.by_facebook(key: [auth_data.provider, auth_data.uid], limit: 1)).first user || create( provider: auth_data.provider, uid: auth_data.uid, name: auth_data.info.nickname, email: auth_data.info.email, password: Devise.friendly_token[0,20], oauth_token: user.oauth_token = auth.credentials.token, oauth_expires_at: Time.at(auth_data.credentials.expires_at), auth_data: auth_data ) end def self.from_omniauth(auth) binding.pry end def list_is_closed! self.active_list_id = nil save end def has_active_list? active_list_id.present? end end