Sha256: 9cbe46e463e67d7e7ceb824a0f06fc9a8f2b830c0258812661979b0fd1a8f675

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require 'mongoid'

module Vxod::Db
  module Mongoid
    class Identity
      include ::Mongoid::Document
      include ::Mongoid::Timestamps

      field :provider , type: String
      field :openid   , type: String

      belongs_to :user

      index({ provider: 1, social_id: 1 }, { unique: true })

      class << self
        def find_by_openid(provider, openid)
          Identity.where(provider: provider, openid: openid)[0]
        end
      end
    end

    class User
      include ::Mongoid::Document
      include ::Mongoid::Timestamps

      field :email        , type: String
      field :firstname    , type: String
      field :lastname     , type: String
      field :auth_key     , type: String
      
      has_many :identities, dependent: :destroy

      index({ auth_key: 1 }, { unique: true })

      def name
        "#{firstname} #{lastname}"
      end

      class << self
        def find_by_auth_key(auth_key)
          User.where(auth_key: auth_key)[0]
        end
      end
    end    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vxod-0.0.2 lib/vxod/db/mongoid.rb