Sha256: 1063e583c9f4093179d568224bad89203b761f71458a416de4ca5079c55f4eea

Contents?: true

Size: 1.29 KB

Versions: 9

Compression:

Stored size: 1.29 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, unique: true
        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

9 entries across 9 versions & 1 rubygems

Version Path
dm-parse-0.3.20 lib/is/parse.rb
dm-parse-0.3.19 lib/is/parse.rb
dm-parse-0.3.18 lib/is/parse.rb
dm-parse-0.3.17 lib/is/parse.rb
dm-parse-0.3.16 lib/is/parse.rb
dm-parse-0.3.15 lib/is/parse.rb
dm-parse-0.3.14 lib/is/parse.rb
dm-parse-0.3.13 lib/is/parse.rb
dm-parse-0.3.12 lib/is/parse.rb