Sha256: 454b2e39e6014e092fb6bb171d6e478c8638c8be62919ff33082d4152bd6a35d

Contents?: true

Size: 1.29 KB

Versions: 43

Compression:

Stored size: 1.29 KB

Contents

require 'devise'

module Ddr::Auth
  module User
    extend ActiveSupport::Concern

    included do
      delegate :can, :can?, :cannot, :cannot?, to: :ability

      validates_uniqueness_of :username, case_sensitive: false
      validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/

      devise :database_authenticatable, :omniauthable, omniauth_providers: [:shibboleth]

      class_attribute :user_key_attribute
      self.user_key_attribute = Devise.authentication_keys.first
    end

    module ClassMethods
      def find_by_user_key(key)
        send("find_by_#{user_key_attribute}", key)
      end

      def from_omniauth(auth)
        user = find_by_user_key(auth.uid) ||
               new(user_key_attribute => auth.uid, :password => Devise.friendly_token)
        user.update!(email: auth.info.email,
                     display_name: auth.info.name,
                     first_name: auth.info.first_name,
                     last_name: auth.info.last_name,
                     nickname: auth.info.nickname)
        user
      end
    end

    # Copied from Hydra::User
    def user_key
      send(user_key_attribute)
    end

    def to_s
      user_key
    end

    def agent
      user_key
    end

    def ability
      @ability ||= AbilityFactory.call(self)
    end

  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
ddr-core-1.6.1 lib/ddr/auth/user.rb
ddr-core-1.6.0 lib/ddr/auth/user.rb
ddr-core-1.5.5 lib/ddr/auth/user.rb
ddr-core-1.5.4 lib/ddr/auth/user.rb
ddr-core-1.5.2 lib/ddr/auth/user.rb
ddr-core-1.5.3 lib/ddr/auth/user.rb
ddr-core-1.5.1 lib/ddr/auth/user.rb
ddr-core-1.4.4 lib/ddr/auth/user.rb
ddr-core-1.4.3 lib/ddr/auth/user.rb
ddr-core-1.4.2 lib/ddr/auth/user.rb
ddr-core-1.4.0 lib/ddr/auth/user.rb
ddr-core-1.3.0 lib/ddr/auth/user.rb
ddr-core-1.2.0 lib/ddr/auth/user.rb
ddr-core-1.2.0.rc3 lib/ddr/auth/user.rb
ddr-core-1.2.0.rc2 lib/ddr/auth/user.rb
ddr-core-1.2.0.rc1 lib/ddr/auth/user.rb
ddr-core-1.1.2 lib/ddr/auth/user.rb
ddr-core-1.1.1 lib/ddr/auth/user.rb
ddr-core-1.1.0 lib/ddr/auth/user.rb
ddr-core-1.0.0 lib/ddr/auth/user.rb