Sha256: b2bd2ad603a1af7d0dd4f9e66f663c3a99661a52db866153ea7b956c6dc986dd

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

module DataMapper
  module Is

    module Parse
      def is_parse(options = {})
        property :id, Property::ParseKey
        property :created_at, Property::ParseDate, field: "createdAt"
        property :updated_at, Property::ParseDate, field: "updatedAt"
      end

      def is_parse_user(options = {})
        is_parse(options)

        storage_names[:default] = "_User"

        property :username, Property::String
        property :password, Property::String
        property :email,    Property::String, format: :email_address

        class << self
          # Authenticate a user
          #
          # @param [String] username
          #   username
          #
          # @param [String] password
          #   password
          #
          # @return [Resource, nil]
          #   the user resource, or nil if authentication failed
          #
          # @api semipublic
          def authenticate(username, password)
            result = repository.adapter.sign_in(username, password)
            get(result["objectId"])
          rescue ::Parse::ParseError
            nil
          end

          def request_password_reset(email)
            repository.adapter.request_password_reset email
          end
        end
      end
    end

  end

  Model.append_extensions(Is::Parse)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dm-parse-0.3.11 lib/is/parse.rb
dm-parse-0.3.10 lib/is/parse.rb
dm-parse-0.3.9 lib/is/parse.rb
dm-parse-0.3.8 lib/is/parse.rb
dm-parse-0.3.7 lib/is/parse.rb
dm-parse-0.3.6 lib/is/parse.rb