Sha256: 21c1cb0392df28919160a77afe7de4897d1b36a8a647cc9f1c8ce8823a2e20d7

Contents?: true

Size: 824 Bytes

Versions: 2

Compression:

Stored size: 824 Bytes

Contents

module DeviseIosRails
  module OAuth
    def self.included receiver
      receiver.extend ClassMethods
      receiver.validates_with OauthTokenValidator, unless: 'provider.blank?'
      receiver.validates :uid, uniqueness: { scope: :provider },
                               allow_nil: true, allow_blank: true
    end

    def email_required?
      super && password_required?
    end

    def password_required?
      super && provider.blank?
    end

    module ClassMethods
      def from_oauth attributes
        where(attributes.slice(:uid, :provider)).first_or_create do |user|
          user.oauth_email = attributes[:email]
          user.provider    = attributes[:provider]
          user.uid         = attributes[:uid]
          user.oauth_token = attributes[:oauth_token]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise-ios-rails-1.0.2 lib/devise-ios-rails/oauth.rb
devise-ios-rails-1.0.1 lib/devise-ios-rails/oauth.rb