Sha256: 8bea61f7831791095033819f45f000fc2b4f759410096b5f37d2044b0558d550

Contents?: true

Size: 1.19 KB

Versions: 1

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[OneSignalUser::Configuration.devise_class.downcase.to_sym] = OneSignalUser::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

1 entries across 1 versions & 1 rubygems

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