Sha256: 9a67347e5eb8c30f663147a40ace2395a5bf095b2827d5deb57cbaba9d92d859

Contents?: true

Size: 1.32 KB

Versions: 17

Compression:

Stored size: 1.32 KB

Contents

module AuthLh
  module Authentication
    def self.included(base)
      base.extend(ClassMethods)
    end

    def auth_user
      if @auth_user.nil?
        @auth_user = self.class.find_external(login)
      end

      @auth_user
    end

    def auth_user=(val)
      @auth_user = val
    end

    module ClassMethods
      def all_external
        AuthLh.get_users
      end

      def find_external(login)
        all_external.find { |x| x.login == login.to_s }
      end

      def find_current_user(session_token, remote_ip, return_url=nil)
        response = AuthLh.get_current_user(session_token, remote_ip, return_url)

        logged_user = response.user
        @destination_url = response.destination_url

        if logged_user
          user = find_or_create_by(login: logged_user.login)
          user.auth_user = logged_user
          user
        else
          nil
        end
      end

      def login_url(return_url=nil)
        if @destination_url.present?
          @destination_url
        else
          AuthLh.login_url(return_url)
        end
      end

      def logout_url(return_url=nil)
        AuthLh.logout_url(return_url)
      end

      def change_password_url(return_url=nil)
        AuthLh.change_password_url(return_url)
      end

      def my_apps_url
        AuthLh.my_apps_url
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
auth-lh-0.11.2 lib/auth_lh/authentication.rb
auth-lh-0.11.1 lib/auth_lh/authentication.rb
auth-lh-0.11.0 lib/auth_lh/authentication.rb
auth-lh-0.10.3 lib/auth_lh/authentication.rb
auth-lh-0.10.2 lib/auth_lh/authentication.rb
auth-lh-0.10.1 lib/auth_lh/authentication.rb
auth-lh-0.10.0 lib/auth_lh/authentication.rb
auth-lh-0.9.0 lib/auth_lh/authentication.rb
auth-lh-0.8.2 lib/auth_lh/authentication.rb
auth-lh-0.8.1 lib/auth_lh/authentication.rb
auth-lh-0.8.0 lib/auth_lh/authentication.rb
auth-lh-0.7.0 lib/auth_lh/authentication.rb
auth-lh-0.6.1 lib/auth_lh/authentication.rb
auth-lh-0.6.0 lib/auth_lh/authentication.rb
auth-lh-0.5.0 lib/auth_lh/authentication.rb
auth-lh-0.4.2 lib/auth_lh/authentication.rb
auth-lh-0.4.1 lib/auth_lh/authentication.rb