Sha256: 9084acb93d5d8190ea675b350e7950fc7132d4454e4374334747f0686b7ef4bb

Contents?: true

Size: 903 Bytes

Versions: 10

Compression:

Stored size: 903 Bytes

Contents

# Session manager that attempts to pull the user record from UCPath, and
# falls back to LDAP if needed

module UcbRailsUser
  module UserSessionManager

    class InUcPathAddToUsersTable < ActiveInUserTable
      def login(uid)
        self.uid = uid

        # try UCPath first
        user = safely_load_user_from_api do
          UcbRailsUser::UserUcPathService.create_or_update_user_from_ldap_uid(self.uid)
        end

        # if that doesn't work, try LDAP
        user ||= safely_load_user_from_api do
          UcbRailsUser::UserLdapService.create_or_update_user_from_entry(people_ou_entry)
        end

        user&.tap do |u|
          u&.touch(:last_login_at)
        end
      end

      private

      def safely_load_user_from_api(&block)
        begin
          user = block.call
        rescue StandardError
          user = nil
        end
        user
      end
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ucb_rails_user-7.0.0 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-6.2.2 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-6.2.0 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-6.1.1 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-6.1.0 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-6.0.0 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-5.0.0 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-4.1.2 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-4.1.1 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb
ucb_rails_user-4.1.0 app/models/ucb_rails_user/user_session_manager/in_uc_path_add_to_users_table.rb