Sha256: 013c4562b1693e5fde8984bca2b816bedc5170d8adbb9fc79c99deb1f2d9f7ce

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

module OneSignalUser

    extend ActiveSupport::Concern

    included do
        before_action :set_onesignal_user
        helper_method :current_onesignal
    end

    def current_onesignal
        current_onesignal = {}
        current_onesignal[:id] = cookies[:oneSignalUserId]
        current_onesignal[:permission] = cookies[:oneSignalUserPermission]
        current_onesignal[DeviseOneSignal::Configuration.devise_class.downcase.to_sym] = DeviseOneSignal::Configuration.devise_class.constantize&.find_by(onesignal_id: current_onesignal[:id]) if cookies.has_key?(:oneSignalUserId)
        current_onesignal.each do |key, value|
            current_onesignal.delete(key) if value == nil
        end
        current_onesignal
    end

    private

    def set_onesignal_user
        if current_user
            onesignal_user_id = cookies[:oneSignalUserId]
            if onesignal_user_id.nil?
                current_user.update_attributes onesignal_id: nil, onesignal_permission: nil
            else
                current_user.update_attributes onesignal_id: onesignal_user_id, onesignal_permission: cookies[:oneSignalUserPermission]
            end
        end
    end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise-onesignal-1.2.1 app/controllers/concerns/one_signal_user.rb
devise-onesignal-1.1.1 app/controllers/concerns/one_signal_user.rb